Skip to main content
January 28, 2009
Question

ID3 MetaData Streaming MP3

  • January 28, 2009
  • 1 reply
  • 466 views
hi,

so here's one for you. I've been trying very diligently to recieve id3 metadata from a streaming mp3. I have it streaming and it works great, but I need to grab the duration in the metadata.

here's the jist of my code, i've googled this for hours and have found little help, but what I did find is here:

id3_ns = new NetStream(connection);
id3_ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
id3_ns.addEventListener(Event.ID3, id3Handler)
id3_ns.client= new CustomClientAudio();
id3_ns.play("id3:" + videoName))

ns = new NetStream(connection);
ns.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
ns.play("mp3:" + videoName),0);

private function id3Handler(id3:Object):void
{
trace("duration: " + id3.duration);
}

public class CustomClientAudio
{
public function onMetaData(infoObject:Object):void
{
}
public function onPlayStatus(infoObject:Object):void{
}
}
}


The only other thing I can think of trying is see if my mp3 is screwed-up, but I don't think it is because I can see the metadata in the properties of the file.

If anyone can point me in a right direction, I would be forever greatful.


Thanks!
Drew
This topic has been closed for replies.

1 reply

Colin Holgate
Inspiring
January 28, 2009
Sadly, the duration of the MP3 is not a standard entry in the ID3 tags. There is a tag, TLEN, that does exactly the right thing, but you would have had to create the MP3 in a program that adds that tag, and most don't. I've used LAME just to add that tag, and it works, but even then it does mean that you have to wait for the metadata to arrive before you know the duration, and often you need to know it ahead of time.

Some people solve the problem by having a server side function that can tell you the duration of the MP3 stream you're connecting to, but a much better, easier solution is to include the duration value in the xml that you're using to set up the url for the MP3.