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);
}
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With