I have a WPF window, there is a ContentPresenter inside it, and two User Controls (one host MediaUriElement, the other host other things) and two buttons (to switch between User Controls).
When I switch to MediaUriElement User Control, I assign a video Uri to it, and the video play very well, then I switch to the other User Control, at this time, the MediaClosed event fired, when I switch back, the video cannot be played.
I want the video can be played from the beginning or continue play at last switch away, How shall I do?
Very appreciated for any help.
The
MediaElementBase(and descendants) hook on the Unloaded event and close the media. Unclosed media still hold some resources.You can change this behaviour by the
MediaElementBase.UnloadedBehaviorproperty. Set it whatever else thanMediaState.Close. But be careful: you have to callClose()by yourself then, otherwise you can have memory leaks in your app.