How to disable display timeout in WinRT

For those of you who are building multimedia related apps, you’ll want to consider disabling the display timeout of the user’s device. This prevents the screen from dimming or locking while the user is playing/recording media.

In my case, I have a view where the user is doing some video recording. so I don’t want the screen to time out on that page

1)  Create a class scope variable::

private DisplayRequest dRequest;

2) On your OnNavigatedTo event, grab a new DisplayRequest and get a deferral

if (dRequest == null)

{

     dRequest = new DisplayRequest();

     dRequest.RequestActive();

}

3) when the user is done, set it back to normal in the OnNavigatingFrom event:

if (dRequest != null)

{

     dRequest.RequestRelease();

     dRequest = null;

}

That’s it!

I’ll be also using this on media playback page, but in that case I wont use a “page loaded/unloaded” approach. Instead, I’ll wait for the media to be loaded into the MediaElement before getting the deferral and get the release on media ended.

Remember to be respectful when playing with power like this, do not do this for your whole app. Be mindful and skillful and apply it to just the parts that truly need it.

Advertisements

One thought on “How to disable display timeout in WinRT

  1. Pingback: How to disable display timeout in WinRT

If you have a comment, leave it below. If you have a question, email me directly.

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s