使用 MediaStreamSource 的 WP7 Shoutcast
我正在尝试通过 MediaStreamSource 将 Shoutcast 流式传输到我的 MediaElement。这是包含一些基础知识的代码。使用 ReadData 方法,我可以下载原始音频数据(MP3 样本),我的问题是如何将流设置为 MediaStreamSource。这样它就不起作用(它编译并且 MediaFailed 事件没有错误,但我听不到任何声音)。也许我应该在我的自定义 ShoutcastMediaStreamSource 中实现所有这些?固定流没有问题,非固定流就有问题。有人可以给我一些建议吗?
在 WP7 上,无法设置“useUnsafeHeaderParsing”,因此我无法获取带有 Shoutcast 元数据的 http 标头 - 仅原始数据。 在 ShoutcastMediaStreamSource 中,我实现了 ManagedMediaHelpers 的一些代码。
谢谢
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);
}
}
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);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要开发自定义 MediaStreamSource。
您可以在这里找到我为我的一个项目开发的原型:
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
尝试代码中的版本=2。更改一行代码后,它现在对我有用
Try version =2 in the code. It works for me now after changing one line of code