PDA

View Full Version : Get total song duration



ponsho
June 17th, 2007, 08:59 PM
How can i get the total duration of a song with AS3.

zellers
June 17th, 2007, 11:38 PM
check out onID3 for that song
give me a few minutes, i will try to look it up...

zellers
June 17th, 2007, 11:45 PM
k, if you are loading the sound, you should just be able to go








mySound.onID3 = function() {
trace (mySound.id3.TLEN);
}





Not sure if that works, cuz i havn't tested it, i just looked it up in the adobe live docs

TheCanadian
June 17th, 2007, 11:53 PM
This is the AS3 forum by the way, and AS3 doesn't have a loadSound method.

Also, the id3 information will only work for mp3s which have the metadata defined for them.

zellers
June 18th, 2007, 12:20 AM
whoops, didn't even check what forum i was in, i am just using an rss feed to link to these pages, so i didn't even know... sorry, my bad

ponsho
June 18th, 2007, 12:20 AM
Sorry it was my bad, im actually using AS3, im using this now



player_sound = new Sound();
player_sound.addEventListener(Event.ID3, id3Handler);

function id3Handler(my_event:Event):void
{
trace(player_sound.id3.artist);
trace(player_sound.id3.TLEN);
}

var file_request:URLRequest = new URLRequest("../music/my_song.mp3");
player_sound.load(file_request);


With those trace gives me the artist name correctly but for the lenght it gives me undefined.

ponsho
June 18th, 2007, 12:32 AM
I found how to get the song duration, just getting the length property

player_sound.length

thanks

zellers
June 18th, 2007, 12:33 AM
idk, that is using ID3 1.0 tags, i would think you would actually need the 2.0 tag, such as the artist tag, for length, idk what it would be though

ponsho
June 18th, 2007, 04:00 AM
the problem i found getting the length from de id3 tag is that not all the mp3 files have the length registered. But the problem its solved, i just used the .length property