18/06/2011, 12:14
|
| | Fecha de Ingreso: junio-2011
Mensajes: 23
Antigüedad: 13 años, 5 meses Puntos: 0 | |
Respuesta: problema boton as3 y reproductor mp3 xml Y aquí el código en el frame 3 parte1
stop();
var snd:Sound = new Sound();
var channel:SoundChannel;
var context:SoundLoaderContext = new SoundLoaderContext(5000, true);
snd.load(songURL, context);
channel = snd.play(pausePosition); // Start playing
// Set "isPalying" to true now that song is playing
isPlaying = true;
// Make play button show the pause symbol on it
playBtn.gotoAndStop(2);
// Playlist item click listener
list.addEventListener(Event.CHANGE, itemClick);
// Playlist item click function
function itemClick (event:Event):void {
channel.stop(); // stop play
pausePosition = 0;
status_txt.text = event.target.selectedItem.label + ".mp3";
trackToPlay = event.target.selectedItem.songString;
gotoAndPlay(2);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Stop Button Function
function stopPlayer (event:MouseEvent):void {
channel.stop();
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Play & Pause Function //////////////////////////////////////////////////////
function playPause(event:MouseEvent):void {
if (isPlaying == true) {
pausePosition = channel.position;
channel.stop();
playBtn.gotoAndStop(1);
isPlaying = false;
} else {
channel = snd.play(pausePosition);
playBtn.gotoAndStop(2);
isPlaying = true;
}
}
////////////////////////////////////////////////////////////////////////////////////
// Play Next Button Function //////////////////////////////////////////////////////
function playNext(event:MouseEvent):void {
newTrack();
}
////////////////////////////////////////////////////////////////////////////////////
// Play Previous Button Function //////////////////////////////////////////////////////
function previousSound(event:MouseEvent):void {
// set some variables here
var prevNum:uint = list.selectedItem.songNum - 2;
var selectPrevSong = new Array (prevNum,prevNum); // array for cell select
var indexMinus1:uint = i -1; // This takes the index and subtracts 1 from it in order to select the correct song
var lastSongInList = new Array (indexMinus1,indexMinus1); // array for cell select of very last song in list
if (list.selectedItem.songNum == 1) {
if (snd.bytesLoaded != snd.bytesTotal) {
channel.stop();
snd.close();
list.selectedIndices = lastSongInList; // This selects very last song in the list component
list.scrollToIndex(indexMinus1); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
} else {
channel.stop();
list.selectedIndices = lastSongInList; // This selects very last song in the list component
list.scrollToIndex(indexMinus1); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
}
} else {
if (snd.bytesLoaded != snd.bytesTotal) {
channel.stop();
snd.close();
list.selectedIndices = selectPrevSong; // This selects previous song in the list component
list.scrollToIndex(prevNum); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
} else {
channel.stop();
list.selectedIndices = selectPrevSong; // This selects previous song in the list component
list.scrollToIndex(prevNum); // auto scroll to it
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2);
}
}
pausePosition = 0;
}
// Button Listeners ///////////////////////////////////////////////////////////////////////
stop_btn.addEventListener(MouseEvent.CLICK, stopPlayer);
playBtn.addEventListener(MouseEvent.CLICK, playPause);
previousBtn.addEventListener(MouseEvent.CLICK, previousSound);
nextBtn.addEventListener(MouseEvent.CLICK, playNext);
// Place track amount and current track # into our text field
songCount_txt.text = "Ahora sonando " + list.selectedItem.songNum + " of " + i;
// Event Listener for sound complete when any song finishes
channel.addEventListener(Event.SOUND_COMPLETE, onCompletePlayback);
// Function inSoundComplete
function onCompletePlayback (event:Event):void {
newTrack();
}
// New track play function
function newTrack():void {
if (list.selectedItem.songNum == i) { // if songNum == total track amount
channel.stop(); // stop the player
var selectFirst = new Array (0,0); // array for cell select
list.selectedIndices = selectFirst; // This selects song 1
list.scrollToIndex(0);
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2); // Make the switch and play
} else {
channel.stop(); // stop the player
var sn:uint = list.selectedItem.songNum; // var that has value of current list songNum
var selectNext = new Array (sn,sn); // array for cell select
list.selectedIndices = selectNext; // This selects next song in the list component
list.scrollToIndex(sn);
trackToPlay = list.selectedItem.songString; // Define New track to play
status_txt.text = list.selectedItem.label + ".mp3"; // update the song status text
gotoAndPlay(2); // Make the switch and play
}
// Always set pausePosition back to 0 here
pausePosition = 0;
} /// Close newTrack function
//////////////////////////////////////////////////////////////////////////////////// |