I am trying to implement the Shoutcast streaming to my MediaElement via MediaStreamSource. Here is a code with some basics. With the ReadData method I can download raw audio data (MP3 samples), my question is how can I set the stream to the MediaStreamSource. In this way it doesn't work (it compiles and there are no errors on MediaFailed event but i can't hear any sound). Maybe should I implement all of these in my custom ShoutcastMediaStreamSource? There is no problem with fixed stream, just with non-fixed. Can somebody give me some advice?
On the WP7 there is no possibility to set the "useUnsafeHeaderParsing" so I can't get http headers with shoutcast metadata - only raw data. In the ShoutcastMediaStreamSource i have implemented some code of ManagedMediaHelpers.
Thanks
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://radiozetmp3-02.eurozet.pl:8400/;");
request.Method = "GET";
request.Headers["Icy-MetaData"] = "1";
request.UserAgent = "WinampMPEG/5.09";
request.AllowReadStreamBuffering = false;
request.BeginGetResponse(new AsyncCallback(RequestComplete), request);
allDone.WaitOne();
ShoutcastMediaStreamSource smss = new ShoutcastMediaStreamSource(stream);
player.SetSource(smss); // MediaElement
player.Play();
}
public void RequestComplete(IAsyncResult r)
{
HttpWebRequest request = (HttpWebRequest)r.AsyncState;
HttpWebResponse response = request.EndGetResponse(r) as HttpWebResponse;
stream = response.GetResponseStream();
IAsyncResult res = stream.BeginRead(buffer, 0, buffer.Length, callback, null);
allDone.Set();
}
public void ReadData(IAsyncResult r)
{
int bytes = stream.EndRead(r);
if (bytes == 0) { Debug.WriteLine("No bytes readed"); }
else
{
Debug.WriteLine("readed: " + buffer.Length.ToString());
stream.BeginRead(buffer, 0, buffer.Length, callback, buffer);
}
}
You need to develop custom MediaStreamSource.
You can find the prototype of one that I developed for one of my projects here: https://skydrive.live.com/redir.aspx?cid=eb0868f2135b874c&resid=EB0868F2135B874C!1037&parid=EB0868F2135B874C!169&authkey=!AGSYfCVvCasGArI
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With