23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

The Media Control UI<br />

As mentioned in the previous section, providing handlers for the MediaControl object events is required<br />

for background audio so that the user can control the audio through hardware buttons (built into many<br />

devices, including keyboards and remote controls) without needing to switch to the app. This is<br />

especially important because background audio continues to play not only when the user switches to<br />

another app, but also when they switch to the Start screen switch to the desktop, or lock the device.<br />

The default media control UI appears as shown in Figure 10-3 in the upper left of the screen,<br />

regardless of what is on the screen at the time. Tapping the app name will switch to the app.<br />

FIGURE 10-3 The media control UI appearing above the Start screen (left) and the desktop (right)<br />

You can see in these images that the app’s Display Name from the manifest is what’s shown by<br />

default in the UI. Although this is an acceptable fallback, audio apps should ideally provide richer audio<br />

metadata to the MediaControl, specifically it’s albumArt, trackName, and artistName properties (the<br />

latter two of which must be less than 128 characters). This is done in the Configure keys for media<br />

sample, which demonstrates how to obtain album art for a track, a subject we’ll return to later.<br />

With such metadata the media control UI will appear as follows; tapping the album art, track name<br />

or artist name will switch back to the audio app.<br />

You’ll notice in the images above that the forward and backward buttons are disabled. This is<br />

because the app does not have listeners for the nexttrackpressed and previoustrackpressed events<br />

of the MediaControl object; we’ll see how to use these in the next section. There are other events as well,<br />

such as channeldownpressed, channeluppressed, fastforwardpressed, rewindpressed,<br />

recordpressed, and stoppressed, though these aren’t represented in the media control UI.<br />

428

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!