stoppare un player mp3

Di: nessaxel | 26/09/2020 18:09:10
salve a tutti. ho messo un player mp3 che carica una playlist in xml.
il problema è che parte in automatico e non ho ben capito come fare a far si che al caricamento del sito sia spenta e si attivi solo premendo "play"
questo è il codice:
var getMusic:URLRequest;
var music:Sound = new Sound();
var soundChannel:SoundChannel;
var currentSound:Sound = music;
var pos:Number;
var currentIndex:Number = 0;
var songPlaying:Boolean = false;
var xml:XML;
var songlist:XMLList;
/*--------Simple preloader----------------------------------------*/
function loadProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
if(percentLoaded > 20){
trace("loading");
} else{
}
}
function completeHandler(event):void {
trace("DONE");
}
/*-------------------Load in Our XML ------------------------*/
/*----------------------------------------------------------*/
var loader:URLLoader = new URLLoader(); //create a new URLLoader Object
loader.addEventListener(Event.COMPLETE, whenLoaded); //add an event listener to that object
loader.load(new URLRequest("songs.xm")); //Requests our xml file that contains our song data
function whenLoaded(e:Event):void //WhenLoaded function(see line 50) runs when line 50 is complete
{
xml = new XML(e.target.data);
songlist = xml.song; //accesses our song tag in our xml file
getMusic = new URLRequest(songlist[0].url);//get music from songlist
music.load(getMusic);//load music
soundChannel = music.play();//plays the music
songTXT.text = songlist[0].title; //gets song name from xml
soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);//runs the next song function when a song completes
}
/*--------ads some mouse events to our buttons----------------------------------------*/
next_btn.addEventListener(MouseEvent.CLICK, nextSong);
prev_btn.addEventListener(MouseEvent.CLICK, prevSong);
pause_btn.addEventListener(MouseEvent.CLICK,pauseSong);
/*--------Skips Songs----------------------------------------*/
/*-most of below the vars is explained above---------*/
function nextSong(e:Event):void
{
if (currentIndex < (songlist.length() - 1))
{
currentIndex++;
}
else
{
currentIndex = 0;
}
var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var nextTitle:Sound = new Sound(nextReq);
soundChannel.stop();
songTXT.text = songlist[currentIndex].title;
soundChannel = nextTitle.play();
songPlaying = true;
currentSound = nextTitle;
soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);
}
/*--------Previous song and acceses the information in the xml File--------------------------*/
/*--------most of below the vars is explained above-------------------------*/
function prevSong(e:Event):void
{
if (currentIndex > 0)
{
currentIndex--;
}
else
{
currentIndex = songlist.length() - 1;
}
var nextReq:URLRequest = new URLRequest(songlist[currentIndex].url);
var prevTitle:Sound = new Sound(nextReq);
soundChannel.stop();
songTXT.text = songlist[currentIndex].title;
soundChannel = prevTitle.play();
songPlaying = true;
currentSound = prevTitle;
soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);
}
function pauseSong(e:Event):void
{
pos = soundChannel.position; //pause song at current position
soundChannel.stop(); //stop sound
songPlaying = false; // songPlaying is now equal to false
play_btn.addEventListener(MouseEvent.CLICK,playSong);
}
function playSong(e:Event):void
{
if(songPlaying == false) //if songplaying is equal to false run function below
{
soundChannel = currentSound.play(pos); //play from current position(used if it was paused)
soundChannel.addEventListener(Event.SOUND_COMPLETE, nextSong);//run nextSong function if current song is complete
songPlaying = true; //songPlaying is now true
play_btn.removeEventListener(MouseEvent.CLICK,playSong);
}
}

Risposte


Nessuna risposta trovata!