我想在我的 window phone 7 应用程序中播放 shoutcast 流
我像这样启动一个异步 HttpWebRequest
//Init Request
HttpWebRequest myHttpWebRequest = (HttpWebRequest)WebRequest.Create("http://ACommonoShoutCastUrl:8000");
myHttpWebRequest.Headers["Icy-MetaData"] = "1";
myHttpWebRequest.UserAgent = "WinampMPEG/5.09";
myHttpWebRequest.AllowReadStreamBuffering = true;
//Call
// Create an instance of the RequestState and assign the previous myHttpWebRequest object to its request field.
RequestState myRequestState = new RequestState();
myRequestState.request = myHttpWebRequest;
// Start the asynchronous request.
IAsyncResult result = (IAsyncResult)myHttpWebRequest.BeginGetResponse(new AsyncCallback(RespCallBack), myRequestState);
问题是永远不会调用 CallBack->RespCallBack...
此代码在其他环境中对我来说正常但在手机上不起作用...
我也厌倦了使用似乎流式传输数据的 WebClient,
这种情况下的问题是它永远不会调用结束 OpenReadCompleted 因为 endelss shoutcast 流
感谢支持
任何帮助将不胜感激
最佳答案
SHOUTcast 实现了自己的协议(protocol),因此您无法直接访问和播放它。您可以使用 DownloadStringAsync (为此您需要一个 WebClient 实例)下载 PLS 文件并借助 RegEx 读取 URL。
当你得到 URL 后,你可以通过实现 MediaStreamSource 来读取原始音频数据。然后使用 MediaElement播放内容。
您可以找到 MediaStreamSource 的示例实现 here .
关于Windows Phone7 上用于 ShoutCast 的 HttpWebRequest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3734843/