ActionScript - Autoplay y Loop MP3

 
Vista:

Autoplay y Loop MP3

Publicado por ss007 (1 intervención) el 02/06/2009 01:22:01
Hola! Tengo un componente de flash para reproducir mp3, pero necesito que haga autoplay (pide presionar play cuando carga) y que cuando termine una cancion siga con la otra y asi sucesivamente hasta que cuando llegue a la ultima vuelva a la primera.

La verdad se muy poco sobre AS, quizas esté haciendo algo mal...

Les dejo el codigo:

AudioXml = new XML();
AudioXml.ignoreWhite = true;
AudioXml.onLoad = LoadXmlFile;
AudioXml.load(playListPath);
function LoadXmlFile(success) {
if (success) {
aPath = new Array();
asongTitle = new Array();
aAudio = new Array();
aAudio = this.firstChild.childNodes;
AudioTotal = aAudio.length;
for (i=0; i<AudioTotal; i++) {
if (aAudio[i].nodeName == "AudioProps") {
aPath.push(aAudio[i].attributes.path);
asongTitle.push(aAudio[i].attributes.songTitle);
}
}
AudioPath = aPath[0];
tAuthor = asongTitle[0];
AudioActual = 1;
tCount = AudioActual+" Of "+AudioTotal;
tText = "Reproductor";
} else {
tText = "No se puede cargar sonidos";
}
}
Ff.onPress = function() {
if (AudioActual<AudioTotal) {
AudioActual += 1;
AudioPath = aPath[AudioActual-1];
tAuthor = asongTitle[AudioActual-1];
MySound.stop();
Mystatus = "Presione Play";
}
};
Rw.onPress = function() {
if (AudioActual>1) {
AudioActual -= 1;
AudioPath = aPath[AudioActual-1];
tAuthor = aSongTitle[AudioActual-1];
MySound.stop();
Mystatus = "Press Play";
}
};
PlayBtn.onPress = function() {
if (FlagPausa == true) {
MySound.start(SoundPausePos, 0);
FlagPausa = false;
SoundPausePos = undefined;
} else {
MySound = new Sound();
volume = 100;
MySound.setVolume(volume);
MySound.loadSound(AudioPath, StreamFlag);
FlagPausa = false;
_parent.onEnterFrame = function() {
TB = MySound.getBytesTotal();
BL = MySound.getBytesLoaded();
if (BL != TB) {
TheText2.text = Math.round((BL/TB)*100)+"% Cargando";
} else {
TheText2.text = "Tema Cargado";
delete _parent.onEnterFrame;
MySound.start();
}
};
}
};
StopBtn.onPress = function() {
MySound.stop();
Mystatus = "Precione Play";
};
PauseBtn.onPress = function() {
SoundPausePos = MySound.position/1000;
MySound.stop();
FlagPausa = true;
};
volUp.onPress = function() {
if (volume == 100) {
volume = 100;
} else {
volume += 10;
MySound.setVolume(volume);
}
};
volDown.onPress = function() {
if (volume == 0) {
volume = 0;
} else {
volume -= 10;
MySound.setVolume(volume);
}
};
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de Alejandro

Reproducción automática en bucle de una lista de reproducción de MP3

Publicado por Alejandro (369 intervenciones) el 24/06/2023 00:52:27
Para lograr la reproducción automática en bucle de una lista de reproducción de MP3 en ActionScript, puedes realizar los siguientes cambios en tu código:

1. Asegúrate de tener el siguiente código al principio de tu archivo ActionScript para importar la clase necesaria:
1
import flash.media.SoundChannel;

2. Agrega la siguiente línea de código antes de la declaración de variables para crear una variable adicional:
1
var soundChannel:SoundChannel = new SoundChannel();

3. Reemplaza la función `PlayBtn.onPress` con el siguiente código:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
PlayBtn.onPress = function() {
    if (FlagPausa == true) {
        MySound.start(SoundPausePos, 0);
        FlagPausa = false;
        SoundPausePos = undefined;
    } else {
        MySound = new Sound();
        volume = 100;
        MySound.setVolume(volume);
        MySound.loadSound(AudioPath, StreamFlag);
        FlagPausa = false;
        _parent.onEnterFrame = function() {
            TB = MySound.getBytesTotal();
            BL = MySound.getBytesLoaded();
            if (BL != TB) {
                TheText2.text = Math.round((BL/TB)*100)+"% Cargando";
            } else {
                TheText2.text = "Tema Cargado";
                delete _parent.onEnterFrame;
                soundChannel = MySound.play();
                soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
            }
        };
    }
};
 
function onSoundComplete(event:Event):void {
    AudioActual += 1;
    if (AudioActual > AudioTotal) {
        AudioActual = 1;
    }
    AudioPath = aPath[AudioActual - 1];
    tAuthor = asongTitle[AudioActual - 1];
    MySound = new Sound();
    MySound.setVolume(volume);
    MySound.loadSound(AudioPath, StreamFlag);
    _parent.onEnterFrame = function() {
        TB = MySound.getBytesTotal();
        BL = MySound.getBytesLoaded();
        if (BL != TB) {
            TheText2.text = Math.round((BL/TB)*100)+"% Cargando";
        } else {
            TheText2.text = "Tema Cargado";
            delete _parent.onEnterFrame;
            soundChannel = MySound.play();
            soundChannel.addEventListener(Event.SOUND_COMPLETE, onSoundComplete);
        }
    };
}

Con estos cambios, la reproducción de la lista de reproducción de MP3 comenzará automáticamente cuando se cargue la primera canción. Después de que una canción termine, se reproducirá automáticamente la siguiente canción en orden y así sucesivamente hasta que llegue a la última canción. Cuando se alcance la última canción, la reproducción volverá a la primera canción en un bucle continuo.

Espero que esto resuelva tu problema.
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar