Silverlight MediaElement 拒绝播放音频

发布于 2024-10-07 12:15:55 字数 1522 浏览 1 评论 0原文

我最难解决这个问题。我有一个 Silverlight 4 应用程序,可以从 URL 加载音频和视频文件。 URL 与托管应用程序的域相同,并且非常适合视频。

URL 实际上是 asp.net mvc 控制器,负责从服务器上的共享位置读取文件并返回文件流。 URL 如下所示:

http://localhost:31479/CourseMedia?path=\omnisandbox1\ ILMSShare2\Demo-Fire+Behavior\media\Disclaim.wma&encrypted=False&id=00000000-0000-0000-0000-000000000000

如果我将 URL 直接放入浏览器中,则文件会在 Windows Media Player 中加载并播放,如果我使用单独的测试 silverlight 项目来加载 url,它也可以工作,但在我的一生中,我无法让它在我的主项目中正常工作。

这是我实际用来进行源设置的例程:

protected void SetPlayerURL(MediaElement player, string url)
{
        if (player != null && url.Length > 0)
        {
            player.ClearValue(MediaElement.SourceProperty);
            player.Source = new Uri(this.Packet.GetMediaUrl(url, false, Guid.Empty));                
        }
}

GetMediaURL 函数只是构建上面看到的 URL 格式:

public string GetMediaUrl(
        string path, 
        bool encrypted, 
        Guid key)
    {
        StringBuilder builder = new StringBuilder();

        builder.AppendFormat("http://{0}/CourseMedia?path={1}&encrypted={2}&id={3}",
             this.Host,
             System.Windows.Browser.HttpUtility.UrlEncode(path),
             encrypted,
             key);

        return builder.ToString();
    }

当媒体是音频时,永远不会向控制器发出请求。我觉得很奇怪,因为这个确切的代码适用于视频。 MediaElement 状态永远不会离开“Closed”,并且永远不会触发 CurrentStateChanged、MediaOpened 和 MediaFailed 事件。

我很茫然!

I am having the hardest time figuring this problem out. I have a Silverlight 4 application that loads audio and video files from URLs. The URLs are the same domain as the application is hosted on and it works great for video.

The URLs are actually asp.net mvc controllers that are responsible for reading the file from a shared location on and the server and serving back a filestream. The URLs look something like this:

http://localhost:31479/CourseMedia?path=\omnisandbox1\ILMSShare2\Demo-Fire+Behavior\media\Disclaim.wma&encrypted=False&id=00000000-0000-0000-0000-000000000000

If I put the URL directly into the browser the file loads and plays in windows media player just fine, and if I use a separate test silverlight project to load the url it also works, but for the life of me I can not get it to work properly in my main project.

This is the routine I use to actually do the source setting:

protected void SetPlayerURL(MediaElement player, string url)
{
        if (player != null && url.Length > 0)
        {
            player.ClearValue(MediaElement.SourceProperty);
            player.Source = new Uri(this.Packet.GetMediaUrl(url, false, Guid.Empty));                
        }
}

and the GetMediaURL function simply builds the URL format seen above:

public string GetMediaUrl(
        string path, 
        bool encrypted, 
        Guid key)
    {
        StringBuilder builder = new StringBuilder();

        builder.AppendFormat("http://{0}/CourseMedia?path={1}&encrypted={2}&id={3}",
             this.Host,
             System.Windows.Browser.HttpUtility.UrlEncode(path),
             encrypted,
             key);

        return builder.ToString();
    }

The request to the controller is never made for the media when it is audio. Seems odd to me as this exact code works fine for video. The MediaElement state never leaves "Closed" and the CurrentStateChanged,, MediaOpened, and MediaFailed events are never triggered.

I am at a loss!

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

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

发布评论

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

评论(1

愿与i 2024-10-14 12:15:55

尝试将 MediaElement 的 ScrubbingEnabled 设置为 false,Framework 版本 3.5 和音频存在一些问题,解决方法是将其设置为 false。可能值得尝试。

还可以尝试捕获 BufferingStarted、BufferingEnded、MediaEnded 以及 MediaFailed 和 MediaOpened 事件。我很好奇这是否是一个缓冲问题。

Try setting ScrubbingEnabled of the MediaElement to false, there were some problems with Framework version 3.5 and audio and the workaround was setting that to false. Might be worth trying.

Also try capturing BufferingStarted, BufferingEnded, MediaEnded along with your MediaFailed and MediaOpened events. I'm curious if it is a buffering issue.

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