Dec 28, 2012 at 2:24 AM
Edited Jan 9, 2013 at 7:44 PM
After much tinkering, I wonder if this issue has to do with unprocessed frames in the video buffer.
I say this for the following reasons:
When not backgrounded, MediaEnded ALWAYS fires (all video frames are processed)
When backgrounded, MediaEnded fires if you fast forward to the last 10 seconds of a video and let it play out (the video frames are not enough to stuff the buffer)
When backgrounded, MediaEnded fires if you use the Media Transport Controls to skip to another video and let it play out (i.e. the video frames for the skipped-to video never actually get processed)
I am verifying the MediaEnded is firing by supplying the PlayerFramework Source in my project and setting a breakpoint in the OnMediaEnded Method of MediaPlayer.cs
I do not believe this issue has to do with threading and even went so far as to wire events off of the dispatcher just in case. Further evidence for this not being related to threading is that I have Next and Previous methods wired up to the Media
Transport control that are ALWAYS properly called when the associated buttons are clicked on the Media Transport Control. MediaEnded is very simply, not firing at the end of playback, it's like the MediaElement does not actually think it has ended
when it should.
FWIW, I saw this behavior previously in the SMF Player for Windows Phone 7 where I implemented a Video Player that rotated 180 degrees on the y-axis to show the playlist (using Visual States to respectively alter the opacity of the player / playlist
depending on which should be shown). When a video was playing, if I flipped the player 180 degrees to the playlist and kept it playing, the video frames would not be processed. In fact, you could literally see this if you waited about 30 seconds
and flipped back, you would notice the Video Player attempt to catch up by speedily processing frames. Furthermore, if I played out an entire video while on the playlist, I would have to flip back and wait a good while for all frames to process THEN
MediaEnded would fire. I never solved this issue and instead forced the Video Player to pause when the playlist was visible.