开发者

Silverlight MediaElement refusing to play audio

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 =开发者_如何学Go 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!


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜