Reputation: 27673
When using a MediaElement
's SetSource
method, the media MediaElement
's Source
remains null
. So how do we check if it has a source, that is, how do we check if Play
will actually play something?
Upvotes: 1
Views: 838
Reputation: 5876
In addition to MediaOpened
event MediaElement
has also MediaFailed
event which is raised when selected source can't be opened
Upvotes: 1
Reputation: 15758
To check if MediaElement
has a valid Source
, we can take advantage of MediaElement.MediaOpened event. This event occurs when the media stream has been validated and opened, and the file headers have been read. So if this event occurs, it must be able to actually play something.
Besides this event, we can also check MediaElement.CurrentState property, this property returns the current state of this MediaElement. The state can be one of the following (as defined in the MediaElementState enumeration): Buffering, Closed, Opening, Paused, Playing, or Stopped. The default value is Closed. And Closed represents the MediaElement contains no media. So while the current state is closed, It means there is no source and if the state is not closed, it should be able to play something.
Upvotes: 2