Ankur Tripathi
Ankur Tripathi

Reputation: 691

C# MediaElement Sometime fail to play video

I am using MediaElement for play video and its fails sometime without any exception.. just black window comes and Calling Play() (or Pause() then Play()) fails every time.

I have ScrubbingEnabled set to True so that I can show the first frame of the video to the user

Code:-

<MediaElement x:Name="VideoPlayer" LoadedBehavior="Manual" MediaOpened="VideoPlayer_MediaOpened" MediaEnded="VideoPlayer_MediaEnded" 
 MediaFailed="VideoPlayer_MediaFailed"  UnloadedBehavior="Manual" Stretch="Uniform" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" 
 SizeChanged="VideoPlayer_SizeChanged" SourceUpdated="VideoPlayer_SourceUpdated" ></MediaElement>

And after restart exe same video play perfectly.

is am doing any thing wrong or its .Net issue ?

Upvotes: 1

Views: 201

Answers (1)

Ankur Tripathi
Ankur Tripathi

Reputation: 691

MediaElement uses EVR, which in turn uses Direct3D. EVR is a limited resource, which you are using an instance per MediaElement, and once in a while the playback hits the limit. Unfortunately, the problem is suppressed somewhere inside the API and no reasonable error reporting takes place.

You can estimate the number of playback instances using a tool referenced in this answer: Black video using multiple instances VMR 9 (there is EVR option there as well).

https://stackoverflow.com/a/23393963/5096993

Upvotes: 2

Related Questions