Welcome to WebmasterWorld Guest from 54.158.228.55

Forum Moderators: open

Message Too Old, No Replies

Getting the length of audio file

AS3 audio length

     
2:33 pm on Mar 31, 2009 (gmt 0)

5+ Year Member



How do I get the length of an audio file? I need this value to set up a timer that depends on the length of the song playing.

I have tried the following, but only get a value of ZERO. The audio plays just fine. Please advice!

from my code:

var gettheme:URLRequest;
var nextA: Sound;
var SC_A:SoundChannel;
var songLong : Number = 5; // just to set a number

gettheme = "mysong.mp3"
nextA = new Sound(gettheme);
SC_A = nextA.play();
songLong = nextA.length;
trace("Song length is: ", songLong );

If I try songLong = nextA.length(); // ie, .length();
I get an error:
1195: Attempted access of inaccessible method length through a reference with static type flash.media:Sound.

Please advice!

regards,
Jaxz

8:05 pm on Mar 31, 2009 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



I think you might have to do a bytesLoaded/bytesTotal check as you won't know the length until it's completely loaded. When bytesLoaded=bytesTotal, then you might be able to query for length, which will give you length in milliseconds. With .flv files, this is inherent in the file (presuming in the file headers) so you can get a video length as soon as it loads, but appears to be different with the Sound() object.

Dig around the Sound() class in the AS3 manual of the help files.

 

Featured Threads

Hot Threads This Week

Hot Threads This Month