Windows Dev Center

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

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.



// Create this variable at a global scope. Set it to null.
private DisplayRequest dispRequest = null;

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:


public void StartVideoPlayback()
{
    if (dispRequest == null) 
    {
        
        // Activate a display-required request. If successful, the screen is 
        // guaranteed not to turn off automatically due to user inactivity.
        dispRequest = new DisplayRequest();
        dispRequest.RequestActive();
        
        rootPage.NotifyUser("Display request activated",
                        NotifyType.StatusMessage);
        
        
        // Insert your own code here to start the video.
        
    }
}

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:



public void StopVideoPlayback()
{
    // Insert your own code here to stop the video.
    
    if (dispRequest != null)
    {
        
        // Deactivate the display request and set the var to null.
        dispRequest.RequestRelease();
        dispRequest = null;
        
        rootPage.NotifyUser("Display request released",
                            NotifyType.StatusMessage);
        
    }
}

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:
© 2015 Microsoft