SmoothStreamingMediaElement.Play() - 抛出异常但播放器启动

Ben*_*Ben 5 silverlight mediaelement smooth-streaming

当我设置我的SmoothStreamingSource然后调用.Play()时,我得到以下异常...

"没有源设置时,不允许播放."

奇怪的是,如果我处理这个异常(如下面的代码所示),视频就会开始播放.奇?根据msdn,SmoothStreamingSource属性自动设置Source属性,所以我不应该得到异常.单步执行代码确认在设置SmoothStreamingSource属性后设置了Source属性.

如果这是内部更大问题的标志,我宁愿不只是处理异常并继续我的快乐方式.

怎么了?我的代码......

try
        {
            Uri uri = (Uri)((Button)source).Tag;

            smoothStreamingMediaElement1.SmoothStreamingSource = uri;

            if (smoothStreamingMediaElement1.SmoothStreamingSource != null)
                MessageBox.Show(smoothStreamingMediaElement1.SmoothStreamingSource.ToString());
            else
                MessageBox.Show("SmoothStreamingSource is NULL");

            smoothStreamingMediaElement1.Play();
        }
        catch (Exception ex)
        {
            MessageBox.Show(ex.Message);
        }
Run Code Online (Sandbox Code Playgroud)

Mik*_*ike 4

当您设置 SmoothStreamingSource 属性时,您只是设置一个 Uri 变量,仅此而已。

为了让播放器开始播放,您需要等待 SmoothStreamingMediaElement 下载包含播放流所需的所有信息的清单。

因此,在您的情况下,我不会在设置 SmoothStreamingSource 属性后立即调用 Play 方法,而是订阅 ManifestReady 或 MediaOpened 事件,然后才调用 Play 方法。