Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SmoothStreamingMediaElement.Play() - Exception thrown but player starts

When I set my SmoothStreamingSource and then call .Play() I get the following exception...

"Play is not allowed when there is no source set."

The odd thing, is that if I handle this exception (shown in the code below), the video does start playing. Odd? According to the msdn, the SmoothStreamingSource property sets the Source property automatically so I shouldn't be getting an exception. Stepping through the code confirms that the Source property is set after setting the SmoothStreamingSource property.

I'd rather not just handle the exception and go on my merry way if this is a sign of a greater issue internally.

What's up with this? My code...

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);
        }
like image 506
Ben Avatar asked Oct 10 '22 10:10

Ben


1 Answers

When you set the SmoothStreamingSource property you are just setting an Uri variable nothing else.

In order for the player to start playing, you need to wait for the SmoothStreamingMediaElement to download the manifest containing all information required for playing the stream.

So, in your case I would not call the Play method right away after you set the SmoothStreamingSource property, but subscribe to the ManifestReady or MediaOpened event and only then call the Play method.

like image 111
Mike Avatar answered Jan 01 '23 11:01

Mike