| Ultrashock Forums
• help with sound.length |
|||
![]() |
||||
| Search this Thread | Thread Tools | Display Modes |
|
|
|||||||||||||||||||||||||
![]() |
Ultrashock Member Comments:
17 Creative Assets
|
2009-06-22
#2 |
||
|
|
2009-06-23
#3 |
||
|
Can you post another link? I checked it out yesterday and when I got up to implement it today it's been taken down
|
|
|
2009-06-23
#4 |
||
|
never mind, google cached it
|
|
|
2009-06-23
#5 |
||
|
I'm still getting zero for a Sound.length. Here's my implemntation of your code: Calling it: Code:
var music:Sound = new Sound();
//jsAlert("From Flash: new sound is created");
music.load(new URLRequest(newTrack));
//jsAlert("From Flash: music loading");
sc = music.play();
sc.addEventListener(Event.SOUND_COMPLETE, loadNextTrack);
//get song length
var songLength:Number = getLength( music );
//and send it to javascript:setHighlight to time the pulses
ExternalInterface.call("setHighlight", newTrack, index, songLength);
isPlaying = true;
Code:
function getLength( snd:Sound ):Number
{
var length:Number = 0;
if( snd.bytesLoaded )
{
length = snd.length * ( snd.bytesTotal / snd.bytesLoaded );
}
return length;
}
Thanks for the assistance... |
|
17 Creative Assets
|
2009-06-23
#6 |
||
|
You're not waiting for the file to start loading, Sound.load() isn't a synchronous method. When the file does begin loading you can then read the sound length but it will only be a "best guess" until the file has fully loaded, Flash can't [for example] predict the sound length of variable-bit-rate sound files. If you want the actual sound length before the file is loaded, or has fully loaded, then you will need to use a ByteArray, and assuming the file is MP3, read all of the MPEG audio tags to determine the total sound length. An alternative would be to store the sound length in a XML file or something and load it when needed. This will be my last post for a while so I wish you all the best with your project. |
|
|
2009-06-23
#7 |
||
|
Thanks man, I'll work it out
|
|
17 Creative Assets
|
2009-07-03
#8 |
||
|
Did you manage to get things working?
|
|
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|


7 comments
| 321 views


17 Creative Assets
Linear Mode
I have a solution for this in my blog:
www.si-robertson.com/actionscript-tips/#total-time-of-streaming-music