使用 MediaStreamSource 的 WP7 Shoutcast

发布于 2024-10-05 16:04:14 字数 1791 浏览 6 评论 0原文

我正在尝试通过 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤独患者 2024-10-12 16:04:14

您需要开发自定义 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

隔岸观火 2024-10-12 16:04:14

尝试代码中的版本=2。更改一行代码后,它现在对我有用

Try version =2 in the code. It works for me now after changing one line of code

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文