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.

o<br />

Set PlayToSource.next property to the msPlayToSource of another element for continual<br />

playing.<br />

• Pick up the media element’s ended event to stage additional media<br />

Another approach, as demonstrated in the Media Play To sample, is to go ahead and play media<br />

locally and then let the user choose a PlayTo device on the fly from the Devices charm. In this case you<br />

don’t need to do anything because Windows will pick up the current playback element and direct it<br />

accordingly. But the app can listen to the statechanged event of the element’s msPlayToSource.-<br />

connection object (a PlayToConnection) that will fire when the user selects a PlayTo device and when<br />

other changes happen.<br />

Generally speaking, PlayTo is primarily intended for streaming to a media receiver device that’s<br />

probably connected to a TV or other large screen. This way you can select local content on a Windows 8<br />

device and send it straight to that receiver. But it’s also possible to make a software receiver—that is, an<br />

app that can receive streamed content from a PlayTo source. The PlayToReceiver sample does exactly<br />

this, and when you run it on another device on your local network, it will show up in the Devices charms<br />

as follows:<br />

You can even run the app from your primarily machine using the remote debugging tools of Visual<br />

Studio, allowing you to step through the code of both source and receiver apps at the same time!<br />

(Another option is to run Windows Media Player on one machine and check its Stream > Allow Remote<br />

Control of My Player menu option. This should make that machine appear in the PlayTo target list.)<br />

To be a receiver, an app will generally want to declare some additional networking capabilities in the<br />

manifest—namely, Internet (Client & Server) and Private Networks (Client & Server)—otherwise it won’t<br />

see much action! It then creates an instance of Windows.Media.PlayTo.PlayToReceiver, as shown in the<br />

PlayTo Receiver sample’s startPlayToReceiver function (js/audiovideoptr.js):<br />

function startPlayToReceiver() {<br />

if (!g_receiver) {<br />

g_receiver = new Windows.Media.PlayTo.PlayToReceiver();<br />

}<br />

464

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

Saved successfully!

Ooh no, something went wrong!