# Getting the length of audio file \[AS3\]

**URL:** <https://forum.kirupa.com/t/getting-the-length-of-audio-file-as3/285413>\
**Category:** Uncategorized\
**Created:** [March 31, 2009, 2:50pm UTC](https://forum.kirupa.com/t/getting-the-length-of-audio-file-as3/285413 "2009-03-31T14:50:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![jaxz](https://avatars.discourse-cdn.com/v4/letter/j/c6cbf5/32.png) [@jaxz](https://forum.kirupa.com/u/jaxz)\
**Post date:** [March 31, 2009, 2:50pm UTC](https://forum.kirupa.com/t/getting-the-length-of-audio-file-as3/285413/1 "2009-03-31T14:50:17Z")

</div>

[FONT=Calibri][SIZE=3]How do I get the length of an audio file? [/SIZE][/FONT]  
[FONT=Calibri][SIZE=3]I need this value to set up a timer that depends on the length of the song playing.[/SIZE][/FONT]

[FONT=Calibri][SIZE=3]I have tried the following, but only get a value of ZERO. [/SIZE][/FONT]  
[FONT=Calibri][SIZE=3]The audio plays just fine. Please advice![/SIZE][/FONT]

[FONT=Calibri][SIZE=3]from my code:[/SIZE][/FONT]

[FONT=Calibri][SIZE=3]var gettheme:URLRequest;[/SIZE][/FONT]  
[FONT=Calibri][SIZE=3]var nextA: Sound;[/SIZE][/FONT]  
[FONT=Calibri][SIZE=3]var SC\_A:SoundChannel;[/SIZE][/FONT]  
[FONT=Calibri][SIZE=3]var songLong : Number = 5; // just to set a number[/SIZE][/FONT]  
[SIZE=3][FONT=Calibri]gettheme = “mysong.mp3”[/FONT][/SIZE]  
[SIZE=3][FONT=Calibri]nextA = new Sound(gettheme);[/FONT][/SIZE]  
[SIZE=3][FONT=Calibri]SC\_A = nextA.play(); [/FONT][/SIZE]  
[SIZE=3][FONT=Calibri]songLong = nextA.length;[/FONT][/SIZE]  
[SIZE=3][FONT=Calibri]trace("Song length is: ", songLong );[/FONT][/SIZE]

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

[FONT=Calibri][SIZE=3]Please advice![/SIZE][/FONT]  
Jaxz
