Stavros Koureas Stavros Koureas - 2 months ago 38
C# Question

Find stream (mp3) info (duration,bitrate)

I am searching a way to get the bitrate and duration from a audio stream in C# on Windows Phone 7 platform.

First, I, tried to get it by calculate using formula (let's say that i can have duration of stream, that i am going to download as number)

bitrate = ((((filesize)/duration)/1024)*8)

I can download the audio (mp3) in stream from webclient and store or play it but i want to check for some rules first, for theese rules i need the bitrate that i can calculate without duration and bytes using some kind of formula as the audio stream may has variable bitrate and deeper calculations will be wrong.

Also sometimes, a part of the stream is downloaded within the app, so i do not have the full filesize and duration, so the bitrate is not right calculated, so i need a sure way.

So how can i get bitrate or duration from a stream using some function of Windows Phone 7 framework without actualy play it?


The only solution seems to be, a well written class that i had made whitch reads the bytes of the song's header (mp3 container) and extracts details like duration and bitrate.

An another elegant solution i found whitch that does not meet my requirement is to be played first and use the AudioBackroundAgent to take theese details, then we can do the math with filesize and duration of track to get the bitrate!