访问流缓冲区HttpWebRequest

时间:2011-09-02 13:24:37

标签: c# windows-phone-7 httpwebrequest streaming

我正在尝试在Windows Phone 7应用中流式传输广播,为此我正在使用ManagedMediaHelpers。获取连续流的HttpWebRequest有效,但由于连续流而未调用回调Url。

如何在没有回调Url帮助的情况下访问流?在其他帖子上有人说O需要使用反射,但是有人知道热实现吗?这是我的代码:

req = (HttpWebRequest) WebRequest.Create(
    "http://streamer-dtc-aa01.somafm.com:80/stream/1018");

// if this is false it will fire up the callback Url 
// but the mediastreamsource will throw an exception 
// saying the it needs to be true
req.AllowReadStreamBuffering = true; 

IAsyncResult result = req.BeginGetResponse(RequestComplete,null);

private void RequestComplete(IAsyncResult r)
{
    HttpWebResponse resp = req.EndGetResponse(r) as HttpWebResponse;
    Stream str = resp.GetResponseStream();

    mss = new Mp3MediaStreamSource(str, resp.ContentLength);
    Deployment.Current.Dispatcher.BeginInvoke(() => {
        this.me.Volume = 100;
        this.me.SetSource(mss);
    });
}

1 个答案:

答案 0 :(得分:1)

有同样的问题,所以这就是我如何解决它:

Getting bytes from continuous streams on Windows Phone 7

您的网址可能也存在问题 - 请确保如果您在应用程序外部运行请求,则会获得必要的数据量。