Disclaimer!: I am not a Window Phone Expert though dabble occasionally…
The Media Element on Windows Phone 8 sometimes/often fails to play media under the lock screen. Forcing a layout update works around the problem.
My app features several pages that load automatically in a sequence to play various pieces of audio. (These same pages do other things too when the phone is unlocked, but when locked everything else is disabled except the playing of the audio).
Each page plays a piece of audio using the Media Player. On some pages the audio was playing happily under the lock screen. On other pages the audio refused to play (no error, the call to the media player was seemingly ignored).
After several hours of comparing the pages I tracked down the single line of code that was making the difference. On pages where the audio was playing, the following line was present and this single line made the all important difference:
Guessing that this might be triggering a layout update, I swapped this line for the following:
Same effect. When this line was executed before the call to the MediaPlayer element, the audio played. If I skipped calling this line, the audio didn’t play.
The simple project I used to explore this issue can be downloaded here. Leaving the “Force Layout Updates” box unticked demonstrates the problem. Ticking the box runs the extra line of code and the audio plays fine.
I haven’t tested this on the latest version of the WP8 Emulators. I have however tested it on my Lumia 920 which is running the latest updates and the behaviour is the same.