4 Replies Latest reply on Apr 11, 2007 2:32 PM by TheDoubleG

    Sound.duration for streaming contents

    abeall Level 3
      Is it possible to know the duration of a streamed MP3 before it is fully loaded? Sound.duration gives only the amount that has been loaded. The Sound.id3.TLEN gives undefined.
        • 1. Re: Sound.duration for streaming contents
          abeall Level 3
          To review, I don't have access to the duration via Sound.id3.TLEN, and converting MP3s to id3 v2 with TLEN is not an option. I am progressively downloading the file, and Sound.duration gives the milleseconds loaded so far. There is no way to retrieve the duration without setting it to event sound(Sound.loadSound('sound.mp3',false)), which is not an option as my MP3s are large.

          Solution? I can roughly calculate the time based on the seconds of audio downloaded, bytes downloaded and the total amount of bytes in the file:
          var percent = _sound.getBytesLoaded()/_sound.getBytesTotal();
          var duration = _sound.duration/percent;

          It's not perfect, of course, as there are a few hiccups where Flash is downloading header/footer data, but it works good enough for me!

          HTH helps anyone with the same issue.
          • 2. Re: Sound.duration for streaming contents
            abeall Level 3
            Erm, actually, I'm getting something really strange now. I found that the results were not quite correct. Long story short, try this:

            var s = new Sound();
            onEnterFrame = function(){
            var a = s.duration+"ms : "+s.getBytesLoaded()+" / "+s.getBytesTotal();

            publish and simulate download, and notice something really weird, here's a snip:
            45166ms : 201558 / 201584
            45322ms : 201584 / 201584
            45558ms : 201584 / 201584
            45793ms : 201584 / 201584

            notice how after all the bytes have been loaded(201584 / 201584, Sound.duration(ms) continues to increase! Why? I tested on a web server and it did the same. I think I'm stuck at this point.
            • 3. Re: Sound.duration for streaming contents
              Actionscripted Level 1
              I'm having a very similar problem. I have a streaming player that plays MP3 or FLV files from a podcast feed.

              This play has a playback slider. FLV playback is fine with the player because who ever wrote that class did a great job. MP3 playback is where things go nuts. If the MP3 is missing the ID3.TLEN property, playback will resume normally, but I will be unable to accurately track progress.

              There are some rather hack-ish fixes using a timer and checking downloaded/total bytes, but I have yet to find a reliable and/or accurate solution.

              Sorry to add to the ***** pile instead of clearing it, but I haven't found a good fix for this. If you find/devise one, please post it here.

              NOTE TO ADOBE
              Please for the love of f*cking christ update the Sound class. It really hasn't changed over the years, and it's a rotting piece of crap. Half of the methods don't work the way they're supposed to, and the rest are so poorly implemented it's disgusting. Take a few notes from the NetStream class, if you must. The pause() method and the playback tracking are both wonderful examples.
              • 4. Re: Sound.duration for streaming contents
                Has anybody found an accurate solution for this? I've tried this to find the actual duration of a streaming mp3:

                totalDuration = (song_sound.duration/((song_sound.getBytesLoaded()/song_sound.getBytesTotal())*100))*100;

                However, this still doesn't produce accurate enough results... at least not for what i'm doing.