How to keep the display on during audio/video playback
Language: HTML | XAML

How to keep the display on during audio/video playback (XAML)

[ This article is for Windows 8.x and Windows Phone 8.x developers writing Windows Runtime apps. If you’re developing for Windows 10, see the latest documentation ]

Learn how to keep the display on while playing back local or streaming video by using the DisplayRequest class. Normally, a device running a Windows Runtime app will dim the display (and eventually turn it off) to save battery life when the user is away, but video apps need to keep the screen on so the user can see the video. The DisplayRequest class lets you tell Windows to keep the display turned on so the user can see the video.

To see this feature in action as part of a complete media-playback sample, see Media playback, start to finish.

What you need to know

Technologies

Prerequisites

Instructions

Step 1: Create a DisplayRequest object

Create a global DisplayRequest variable. Initialize it to null.

No code example is currently available or this language may not be supported.

Step 2: Activate the DisplayRequest just before starting video playback

Call requestActive to notify Windows that the app requires the display to remain on.

The following example activates the request before starting video playback:

No code example is currently available or this language may not be supported.

Step 3: Deactivate the DisplayRequest when video playback stops or is paused

Call requestRelease to release the display request whenever video playback is stopped, paused, or interrupted by a playback error. When your app no longer has any active display requests, Windows will save battery life by dimming the display (and eventually turn it off) when the device is not being used.

The following example deactivates the request:

No code example is currently available or this language may not be supported.

Remarks

Note  Windows automatically deactivates your app's active display requests when it is moved off screen, and re-activates them when your app comes back to the foreground.
 

You can also use this API to keep the screen on while giving directions in a GPS app. In this case, substitute navigation events for video playback events.

To see similar code in the context of functions, download the display power state sample.

Related topics

Quickstart: video and audio
Display power state sample
Media playback, start to finish

 

 

Show:
© 2017 Microsoft