reproductor mp3 en flash (play - pause - stop)
Hoy viene la segunda parte para crear un reproductor en flash completo. Ahora añadiremos al codigo anterior las opciones de pause y stop. En el siguiente capítulo añadiremos funciones para controlar el sonido.
Este es el codigo:
- function cargar_mp3(mp3) {
- //creamos una instancia de sonido
- cancion = new Sound();
- //cargamos el mp3 y ponemos la variable de inStreaming en true
- cancion.loadSound(mp3, true);
- //Iniciamos onEnterFrame para visualizar la precarga del archivo mp3
- this.onEnterFrame = function() {
- BytesLoaded = cancion.getBytesLoaded();
- BytesTotal = cancion.getBytesTotal();
- porcentaje = Math.floor(BytesLoaded/BytesTotal*100);
- if (!isNaN(porcentaje)) {
- estado.text = porcentaje+”% cargado.”;
- }
- };
- //en cuanto el mp3 este totalmente cargamos eliminamos onEnterFrame
- cancion.onLoad = function() {
- delete onEnterFrame;
- estado.text = “carga completa”;
- };
- //llamamos a la funcion para cargar el mp3
- cargar_mp3(”http://www.forosdeflash.com/blog/wp-content/cancion.mp3
- b_pause.onRelease = function() {
- ultimaPosicion = Math.round(cancion.position/1000);
- cancion.stop();
- };
- b_stop.onRelease = function() {
- ultimaPosicion = 0;
- cancion.stop();
- };
- b_play.onRelease = function() {
- if (ultimaPosicion == 0) {
- cancion.start();
- } else {
- cancion.start(ultimaPosicion);
- }
- };
Ejemplo:
This movie requires Flash Player 8
30 comments February 5th, 2007