4 Replies Latest reply on Feb 9, 2010 3:27 PM by cdoor84

    Song duration/streaming help

    cdoor84

      Hi, I am new to this site. I am working on a website where users can upload music to be rated by other users. I recently discovered a problem where the song duration doesn't appear correctly if the user's computer hasn't streamed that particular song before. It will play with the incorrect song duration displayed and then once the song has been loaded fully, the correct information appears and the song starts over. What do I need to do to get the correct duration to show up right away, or at least keep the song from starting over once it does show up? You can view the site here www.songfeedback.com and login with username 'tester' and password 'tester' so you dont have to register. I posted the functions that deal with the time display. I can post more if needed.

      Thanks!

      Chris

       

      This code just selects the song that will play (this sample code is only showing 1 out of the 15 songs on the list)

      1. //initiate sound
      2. var sound1 = new Sound();
      3. //select song
      4. _root.list1.onRelease = function(){
      5.     playertitle = title1;//getting the song info from php file
      6.     playerartist = artist1;
      7.     currentfile = filename1;
      8.     artistcom = artistcom1;
      9.     sound1.loadSound("uploads/"+filename1, true);
      10.     sound1.onLoad = function(){
      11.         sound1.start();
      12.         sound1playing = true;
      13.         _root.soundicon.gotoAndStop(1);
      14.         durpos ();
      15.     }
      16. }

       


      This all runs once a song has been selected:

      1. //song time
      2. function durpos () {
      3.     cont1 = false;//these reset some buttons when a new song is selected
      4.     cont2 = false;
      5.     cont3 = false;
      6.     cont4 = false;
      7.     cont5 = false;
      8.     cont6 = false;
      9.     cont7 = false;
      10.     cont8 = false;
      11.     cont9 = false;
      12.     cont10 = false;
      13.     submitted = 0;
      14.     _root.resetme = 1;
      15.     commentz.currentfile = currentfile;//these two lines load the comments section for the song playing
      16.     commentz.sendAndLoad("comment.php", commentz, "POST");
      17.     //get the total time for the song
      18.     soundpos = sound1.duration/1000;
      19.     minutesTotal = Math.floor(soundpos / 60);
      20.     secondsTotal = Math.floor(soundpos-minutesTotal*60);
      21.     if (secondsTotal <= 9){
      22.         totaltime = "/ " + minutesTotal + ":0" + secondsTotal;
      23.     }
      24.     else{
      25.         totaltime = "/ " + minutesTotal + ":" + secondsTotal;
      26.     }
      27. }
      28. var doInterval;
      29. doInterval = setInterval(pos,100);
      30. function pos () {
      31.     soundposition = sound1.position/1000;
      32.     seconds = Math.floor((sound1.position/1000)%60);
      33.     minutes = Math.floor((sound1.position/1000)/60);
      34.     if (isNaN(seconds)){
      35.         timegone = "0:00";
      36.     }
      37.     else if (seconds <= 9){
      38.         timegone = minutes + ":0" + seconds;
      39.     }
      40.     else{
      41.         timegone = minutes + ":" + seconds;
      42.     }
      43.     //submittal permission
      44.     halfway = soundpos/2;
      45.     if (soundposition > halfway && _root.submitted == 0){
      46.         _root.ratebutton._x= 501;
      47.     }
      48.     else{
      49.         _root.ratebutton._x = 600;
      50.     }
      51. }
        • 1. Re: Song duration/streaming help
          kglad Adobe Community Professional & MVP

          check for the duration property of your sound in its onLoad() method.  that's when the duration reported will first be accurate.  and, fix your pos() function to only reference your sound's duration when it's defined.

           

          p.s.  you don't need to apply the start() method to a streaming sound.

           

          p.p.s.  you could check if your sound has an id3 property.  if it does, you can check the id3's TLEN property.

          1 person found this helpful
          • 2. Re: Song duration/streaming help
            cdoor84 Level 1

            Hey, thanks for the response. Removing the start() method made it so the songs don't restart now when its fully loaded, thanks!


            As for the other tips, the duration property only gets called in the durpos() function, which is called in the onLoad() method when a song is first selected. Are you saying that I should check for the duration before I call durpos()?

             

            Also, I don't understand the suggestion to fix the pos() function because it never references duration, only position.

             

            Thanks again!

            • 3. Re: Song duration/streaming help
              kglad Adobe Community Professional & MVP

              my mistake:  make sure your sound's duration is defined before trying to use it.

              • 4. Re: Song duration/streaming help
                cdoor84 Level 1

                I actually discovered a problem now that the start() method was taken out of the onLoad(). When a new song is selected, the song position does not get reset, so if the first song was at 13 seconds, the next song starts at the beginning but the clock says it starts at 13 seconds. Then if I pause and play, the song skips ahead to match the clock.