homepage Welcome to WebmasterWorld Guest from 54.234.2.88
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
Forum Library, Charter, Moderator: open

Flash and Shockwave Forum

    
Getting the length of audio file
AS3 audio length
jaxz




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

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

 

rocknbil




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Flash and Shockwave
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved