How to play next song

I am trying to build a simple player inside my swf file. The code is a bit messy but it seems to work.
I´m using a soundChannel for Playback..
I´m trying to figure out how to have the player play the next song once the previous one has reached its end.
Do I add some sort of EventListener to the soundChannel?
Thanks for helping
import fl.transitions.*;
import fl.transitions.easing.*;
prevBt.buttonMode=true;
playBt.buttonMode=true;
stopBt.buttonMode=true;
nextBt.buttonMode=true;
pauseBt.buttonMode=true;
pauseBt.visible=false;
var xmlLoader:URLLoader= new URLLoader;
var temasURL:URLRequest= new URLRequest ("temas.xml");
xmlLoader.addEventListener(Event.COMPLETE, xmlLoaded)
xmlLoader.load(temasURL);
var temasXML:XML = new XML();
temasXML.ignoreWhitespace=true;
function xmlLoaded(e:Event):void{
      temasXML =XML(xmlLoader.data);
      var temaNum:Number=0;
      var tema:String = temasXML.tema[temaNum].mp3;
      var musica:Sound = new Sound(new URLRequest("audio/"+ tema))
      var sc:SoundChannel;
      var isPlaying:Boolean = false;
      var pos:Number=0;
      stopBt.addEventListener(MouseEvent.CLICK, parar_musica);
      function parar_musica(e:MouseEvent):void{
            sc.stop();
            isPlaying=false;
            playBt.visible=true;
            pos=0;
      playBt.addEventListener(MouseEvent.CLICK, tocar_musica);
      function tocar_musica(e:MouseEvent):void{
            pauseBt.visible=true;
            playBt.visible=false;
            if(!isPlaying){
                 sc= musica.play(pos);
                 isPlaying=true;
                 playerTx.text=temasXML.tema[temaNum].legenda;
     pauseBt.addEventListener(MouseEvent.CLICK, pausa_musica);
     function pausa_musica(e:MouseEvent):void{
           if (isPlaying){
               pauseBt.visible=false;
               playBt.visible=true;
               pos=sc.position;
               sc.stop();
               isPlaying=false;
     nextBt.addEventListener(MouseEvent.CLICK,seguinte);
     function seguinte(e:MouseEvent):void{
            sc.stop();
            temaNum +=1;
            musica= new Sound(new URLRequest("audio/"+ (temasXML.tema[temaNum].mp3)))
            sc= musica.play();
            pauseBt.visible=true;
            playBt.visible=false;
            isPlaying=true;
            playerTx.text=temasXML.tema[temaNum].legenda;
     prevBt.addEventListener(MouseEvent.CLICK,anterior);
     function anterior(e:MouseEvent):void{
            sc.stop();
            temaNum -=1;
            musica= new Sound(new URLRequest("audio/"+ (temasXML.tema[temaNum].mp3)))
            sc= musica.play();
            pauseBt.visible=true;
            playBt.visible=false;
            isPlaying=true;
            playerTx.text=temasXML.tema[temaNum].legenda;

if I declare:
     var musica:Sound;
then add the EL:
      musica.addEventListener(Event.COMPLETE, song_ended)
      function song_ended(e:Event):void{
            trace("finished");
            pauseBt.visible=false;
            playBt.visible=true;
            isPlaying=false;
and finally load the sound into the variable:
      musica= new Sound(new URLRequest("audio/"+ (temasXML.tema[temaNum].mp3)))
I get this error message:
     TypeError: Error #1009: Der Zugriff auf eine Eigenschaft oder eine Methode eines null-Objektverweises ist nicht möglich.
      at index1_fla::player_33/xmlLoaded()
      at flash.events::EventDispatcher/dispatchEventFunction()
      at flash.events::EventDispatcher/dispatchEvent()
      at flash.net::URLLoader/onComplete()
     (sorry about the untranslated text, I bought this laptop in Germany)
which leads me to think that the COMPLETE event in the Sound Class is related to the loading of the sound rather then the playing of the sound (correct me if I´m wrong).
On the other hand,
       var musica:Sound = new Sound(new URLRequest("audio/"+ (temasXML.tema[temaNum].mp3)))
      musica.addEventListener(Event.COMPLETE, song_ended)
      function song_ended(e:Event):void{
            trace("finished");
            pauseBt.visible=false;
            playBt.visible=true;
            isPlaying=false;
doesn´t work either. As a matter of fact, after I´ve written:
     var musica:Sound = new Sound(new URLRequest("audio/"+ (temasXML.tema[temaNum].mp3)))
it´s as if I can no longer add an Ev Listener (it´s not there on the list of options anymore)

Similar Messages

  • Nano 6G: When I play next song, an extremely loud sound will play for 0.3 sec.

    I am extremely annoyned to the fact that when I play music on my iPod Nano 6G (The small one with touch feature), I will play next song by double clicking sleep button then suddenly an an EXTREMELY LOUD DEADLY SOUND will play as if the iPod wants to kill my eardrums. This happens in 1:500 ratio I guess. Did anyone experience this before? I tried playing the song with iTunes, Media Player and other players then I click NEXT to try if it happens but not.

    Oh sorry - just answered my own question - somehow the songs were marked "Skip on shuffle" (went to "Get Info" for all songs, under Options....not sure how they got marked that way, but the issue seems to be resolved on both Mac and iPhone....

  • HT1349 When listening to songs on my itunes acct (without ipod attached), I can only play one song at a time. It doesn't automatically play next song on list. It happens with all playlists. It only started happening when I downloaded the latest itunes upd

    When listening to songs on my itunes acct (without ipod attached), I can only play one song at a time. It doesn't automatically play next song on list. It happens with all playlists. It only started happening when I downloaded the latest itunes update.

    Are all songs checked in your playlist?

  • Itunes stops working after say half hour of use and will not play next song, the only way to get it working again is to close and reopen, then it works fine till next time, but the problem keeps returning

    itunes stops working after say half hour of use and will not play next song, I have to close and reopen, it works fine till next time, it keeps happening on a regular basis, HP pavilion laptop, g6 series,
    Window 7 64 bit

    Hello davewood26,
    The following article provides steps that can help get iTunes stabilized.
    iTunes for Windows Vista, Windows 7, or Windows 8: Fix unexpected quits or launch issues
    http://support.apple.com/kb/TS1717
    Cheers,
    Allen

  • Play next song feature

    Listening on PC using itunes, is there a play next song feature where you can select the next song to be played?

    Not really. Best you can do is make a playlist and play from that.
    Patrick

  • Ipod nano songs repeating 3x before playing next song

    ipod nano keeps repeating songs 3x before playing next song. all from playlists any ideas plse

    So you have a playlist with song x,y and z. You are saying that the nano plays x,x,x,y,y,y,z,z,z?
    i

  • How to play one song at a time?

    I have never had this problem with any of my previous iPod's however I just got a new 32GB Touch after Christmas and I can not figure out how to do this. When I go into my music section and select my artist then album and then a specific song off that album I would like it to stop playing after the song I picked. After the song is done playing that I selected it starts playing the next track. I would prefer it if that only happened if I selected the "Play Album/All" option. I have never had this problem with my other iPods. Hopefully someone knows what I am doing wrong.
    Message was edited by: VonDaurie

    If you don't find a app to do this, there is always:
    a- Use the On The Go playlist and just put one song in it, or
    b- Tag all the music on the iPod as "Skip When Shuffling" and play a song in shuffle mode. When the song completes, the iPod will stop playing.
    I realize that (b) is not a very good solution, but if you don't normally use shuffle mode it might work for you.

  • Try to play next song or the song ends and the music stops. Whats wrong with it?

    Every time I hit "next" to play the next song, the current song playing will stop and wont play the next song. This also happens when the songs ends. When the song ends it won't start the next song. How do I fix this?
    Also the shuffle won't shuffle any one my songs.
    HELP!!!!!!

    Have you tried restarting or resetting your iPod?
    Restart: Press On/Off button until the Slide to Power Off slider appears, select Slide to Power Off and, after the iPod shuts down, then press the On/Off button until the Apple logo appears.
    Reset: Press the Home and On/Off buttons at the same time and hold them until the Apple logo appears (about 10 seconds). Ignore the "Slide to power off"
    If these don't work try removing all music via iTunes and reinstall all the music from your iTunes library.

  • Newbie can't figure out how to play one song only.

    So I just got up and running with my new iPod 80GB Video. I ripped 3 CDS of tunes to mp3's with iTunes and loaded them into the iPod and it plays but I can't figure out how to just play a single song, it always continues to the next song alphabetically. I've looked in the online manuals and couldn't find where you set "single" instead of "play all". I'm in Songs menu, not Artists or Albums. Please help.

    The iPod isn't designed to work like this, and I think the only workaround is to create a playlist with one song in it.

  • How to Play One Song Without Repeat?

    I am a new Ipod user, with an 80 GB video version. (I don't think it's one of the latest new models, but the second to last generation. Is that "fifth generation"?)I updated it with the latest firmware, just a few days ago.
    I have used other MP3 players before though. In most respects I find the Ipod superior to the other MP3 players I have used. However, there is one setting, that I have made before on other MP3 players, for instance my old Creative Muvo 4GB (a few years old), which I cannot figure out how to set on my Ipod.
    How does one set the Ipod to play one song, without going on to the next one, and without repeating that one? The default (of course) is to play all the songs in the album or playlist, going on to the next one, when the current song is finished. Looking in Settings, I find one can set "Repeat" to repeat the whole playlist or album when one comes to the end of it, or set it to repeat the same song.
    But---what if one wants to play one song, and then have the Ipod stop (or at least pause), and not automatically go on to the next song, or repeat the same song? Is it possible to set that? I cannot see how. If there is a way to do that, please let me know.
    Some might ask--why would one want to do that? True, for normal use, the default setting is the best one, going on to the next song, as when one listens to a CD. But, there are cases where one might want the Ipod to play one song and stop. I'll explain my reason for wanting to make that setting--I am an elementary school music teacher. In my concerts with the children this upcoming week, I will put the musical accompaniments for my choirs on the Ipod, and play them from it. When the choir is performing a song, at the end of the song, I don't want the Ipod to start playing the next song on the list. I want it to stop or pause at the end. It will be a hassle for me to have to manually stop it at the right moment, and I might miss it, and it will start playing the next song.
    Any way to set it to play one song, and then stop? If so, please tell me.
    If not, I would hope that Apple would add that capability to the next firmware upgrade. Do they read here for user's suggestions? Is there another place to make suggestions for improvement in the Ipod firmware?
    Thank you for your input.

    Thank you for the reply, Chris.
    I thought of that idea, a separate playlist for each song. That would be fine, if I was only playing one song. But I want to have the list of songs ready to play, so was going to put them in a playlist together. I need to be able to get to the next song quickly, without a lot of messing around with the Ipod.
    Is it possible to put playlists within playlists? Then, perhaps I could make an individual playlist for each song, and make a playlist with all those one-song playlists together. If that is possible, it probably still would make it too complicated to go to the next song, probably having to use the menu button to go back to the higher playlist, etc. I want to keep playback simple.
    I may try your idea of creating a blank "song" to put between tracks. (Is there also no way currently otherwise, to put a certain amount of empty space in between tracks?)
    Thanks also for the feedback link. I will send this concern to Apple, and hope they add that capability soon.

  • TS1424 downloaded music and song cuts out and goes to play next song

    Hi
    I've downloaded songs from the iTunes store and have realised that the song cuts out before it is due to finish and goes to play the next song.
    How can this be fixed? or can I get a credit back on the songs I've purchased which have been cutting out?
    Very frustrating.......

    Fix involves deleting song and redownloading from purchased section
    Delete song from library > restart itunes> Go to itunes store > sign in on top right if not already logged in > under quick links select "purchased" > select music on top > find the song and download it with the cloud icon

  • Songs cut off then play next song

    When I play a series of songs they play about 90% of a song and then start to play the next song.

    I am having the same problem. This may be the same problem identified in an earlier posting by "The Dark Man" (posted 12/30/05,7:53 am); and perhaps also in "Chad Koenig" (last posted 12/30/05, 11:41 AM). On mine, it is a matter of the iPod displaying an incorrect song length.
    Like "The Dark Man," I would also like to find solution.
    G4, Powerbook, iPod   Mac OS X (10.3.9)  
    G4, Powerbook, iPod   Mac OS X (10.3.9)  
    G4, Powerbook, iPod   Mac OS X (10.3.9)  

  • How to play one song then stop on iPhone?

    iTunes playlist on my computer can play one song then stop because there is the uncheck all songs feature, but apparently iPhone doesn't have the same feature.
    Need to play one song then have it stop instead of going to another song in the playlist. Creating 20+ single-song playlists is inefficient.
    I know there is the Play on Cue app for $1.99 but why should I have to have another app on my phone do what iTunes on my computer already does built-in (play one song then stop)?

    "Creating 20+ single-song playlists is inefficient." Please read next time.

  • IPod Song skips to end, freezes for a time, then plays next song

    Name pretty much explains everything
    certain songs on my iPod (so far, all by 1 band), will play the beginning, then when the song is about 20% done, it will skip to the last 2 seconds of the song and just stop for a while (i think it stops at 2 seconds for the same length that it skipped), then it will play the next song and it repeats
    ive tried restoring my iPod, but it didnt work
    any ideas?

    So what changed on your computer or iPod since it played correctly?
    Can you right click on one of the songs in iTunes, select Get Info, and copy the results and paste them here?

  • Play Next Song Syndrom

    My iPod keeps changing to the next song for no apparent reason, when ever if feels like it.
    I purchased this iPod, so technically it should not be owning me...
    I'm guessing this is because of a new firmware update?? But what do i know, i searched around a bit... but no solid answers.
    I tried to resest, restore... yadda yadda. Nothin works.
    If anyone out there has any insight on this issue, please feel free to charm in.
    guess ima have to switch to zune...
    Message was edited by: iNate iHello

    Not really. Best you can do is make a playlist and play from that.
    Patrick

Maybe you are looking for

  • ITunes 8.1 won't sync calendars to iPhone for me

    I just installed iTunes 8.1(50) and am trying to synch my iPhone. It appears to synch everything except for calendars. After synching is completed, iTunes displays an alert saying: "iTunes could not sync calendars to iPhone 'Darrin's iPhone' because

  • Toshiba 40TL963 - no 3D possible

    Just tried my Tv to play 3d movie and cant get any setting to show up when i press the "quick menu" option on the remote. Been on the phone to Toshshiba support and reset TV but still no luck. The 3d player works fine as we have tested this on anothe

  • Flatten project structure upon generation

    Hi folks, Is there an easy way to maintain a folder structure for my projects for my help files BUT, when I generate the CHM file output, for Robohelp to put all htm files at a "root level"? I'd like my application to reference the help files straigh

  • Nikon D800 Camera not listed in the Lens Correction Filter under camera models in Photoshop CC 2014

    I do not see a Nikon D 800 Camera listed in the Lens Correction Filter under camera models. Is there any way to update this ?

  • Can i use msn messnger/windows live?

    hello i'm fro mcuracao and i wanna buy an imac 17" with intel core 2 duo 2.0ghz processor. my question is can i use ms nmessenger? and which other windows programs can i use with no problems on the imac. 1 more thing (i'm confused) does the imac have