C# Silverlight MediaElement 无法从网络播放 mp3

发布于 2024-12-12 01:59:24 字数 1061 浏览 0 评论 0原文

您好,过去几天我一直在为此烦恼,我在 Silverlight 应用程序中有一个用 C# 编写的媒体元素,

我试图通过 http 流式传输 MP3 并通过 silverlight 应用程序播放。尽管它不断捕获一个异常:

AG_E_NETWORK_ERROR

mp3 不会播放,并且 MediaElement.MediaOpened 事件永远不会触发

在网上搜索后,此错误似乎是由于 curropt 源造成的,但当我将网络浏览器指向 mp3 时,mp3 播放正常。

这是代码

private void button1_Click(object sender, RoutedEventArgs e)
        {

            Uri source = new Uri("http://www.sm-testing.co.uk/mixes/youdontknow.mp3");
            mediaElement1.Source = source;
            mediaElement1.MediaFailed += new EventHandler<ExceptionRoutedEventArgs>(mediaElement1_MediaFailed);
            mediaElement1.MediaOpened +=new RoutedEventHandler(mediaElement1_MediaOpened);


        }


        void mediaElement1_MediaFailed(object sender, ExceptionRoutedEventArgs e)
        {
            MessageBox.Show( e.ErrorException.ToString());
        }

        private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
        {

            mediaElement1.Play();
        }

Hi Ive been pulling my hair out over this for the last couple of days, I have a mediaelement in a Silverlight App written in C#

Im trying to stream an MP3 over http and play it through the silverlight app. Although it keeps catching an exception that says

AG_E_NETWORK_ERROR

The mp3 will not play and the MediaElement.MediaOpened event never fires

After searching on the net it appears this error is due to a curropt source but the mp3 plays fine when I point a webbrowser at the mp3.

heres the code

private void button1_Click(object sender, RoutedEventArgs e)
        {

            Uri source = new Uri("http://www.sm-testing.co.uk/mixes/youdontknow.mp3");
            mediaElement1.Source = source;
            mediaElement1.MediaFailed += new EventHandler<ExceptionRoutedEventArgs>(mediaElement1_MediaFailed);
            mediaElement1.MediaOpened +=new RoutedEventHandler(mediaElement1_MediaOpened);


        }


        void mediaElement1_MediaFailed(object sender, ExceptionRoutedEventArgs e)
        {
            MessageBox.Show( e.ErrorException.ToString());
        }

        private void mediaElement1_MediaOpened(object sender, RoutedEventArgs e)
        {

            mediaElement1.Play();
        }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

长梦不多时 2024-12-19 01:59:24

我发现您在示例中使用了实际的 URL。我检查了您的网站,没有 http://www.sm-testing.co.uk /ClientAccessPolicy.xml 文件或 http://www.sm-testing.co.uk/crossdomain.xml 文件。

没有这些文件中的任何一个(最好是 ClientAccessPolicy.xml,因为另一个是旧的 Flash 兼容格式并且缺少一些功能)Silverlight 将仅从其托管的域中检索文件。这是一项安全功能,可阻止 Silverlight 应用程序在未经许可的情况下从任何地方获取数据或图像。

下面的 ClientAccessPolicy.xml 示例允许对任何 http 或 https 请求进行任何访问:

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="*">
            <domain uri="http://*" />
            <domain uri="https://*" />
          </allow-from>
          <grant-to>
            <resource path="/" include-subpaths="true"/>
          </grant-to>
        </policy>
      </cross-domain-access>
</access-policy>

您也不需要 crossdomain.xml,除非您也想开放对 Flash 应用程序的访问:)

I see you have used an actual URL in your example. I checked your site and there is no http://www.sm-testing.co.uk/ClientAccessPolicy.xml file or http://www.sm-testing.co.uk/crossdomain.xml file.

Without either of those files (preferably ClientAccessPolicy.xml as the other is an old Flash compatibility format and missing some features) Silverlight will only retrieve files from the domain it is hosted on. This is a security feature to stop Silverlight app taking data or images from just anywhere without permission.

Example ClientAccessPolicy.xml below allows any access to any http or https request:

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
      <cross-domain-access>
        <policy>
          <allow-from http-request-headers="*">
            <domain uri="http://*" />
            <domain uri="https://*" />
          </allow-from>
          <grant-to>
            <resource path="/" include-subpaths="true"/>
          </grant-to>
        </policy>
      </cross-domain-access>
</access-policy>

You don't need a crossdomain.xml as well unless you want to open up access to Flash apps too :)

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