James Hao
James Hao

Reputation: 905

how to prevent WPF MediaKit MediaClosed fired

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.

Upvotes: 1

Views: 162

Answers (1)

xmedeko
xmedeko

Reputation: 7800

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.UnloadedBehavior property. Set it whatever else than MediaState.Close. But be careful: you have to call Close() by yourself then, otherwise you can have memory leaks in your app.

Upvotes: 1

Related Questions