23.01.2018 Views

MICROSOFT_PRESS_EBOOK_PROGRAMMING_WINDOWS_8_APPS_WITH_HTML_CSS_AND_JAVASCRIPT_PDF

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Here’s how such apps generally work:<br />

• Set up the necessary communication channels over the network, which could be a peer-to-peer<br />

system or could involve a central service of some kind.<br />

• Capture audio or video to a stream using the WinRT APIs we’ve seen (specifically<br />

Media-Capture.startRecordToStreamAsync) or capturing to a custom sink.<br />

• Do any additional processing to the stream data. Note, however, that effects are plugged into<br />

the capture mechanism (MediaCapture.addEffectAsync) rather than something you do in<br />

post-processing.<br />

• Encode the stream for transmission however you need.<br />

• Transmit the stream over the network channel.<br />

• Receive transmissions from other connected apps.<br />

• Decode transmitted streams and convert to a blob by using MSApp.createBlobFromRandom-<br />

AccessStream.<br />

• Use URL.createObjectURL to hook an audio or video element to the stream.<br />

To see such features in action, check out the Real-time communications sample that implements<br />

video chat in Scenario 2 and demonstrates working with different latency modes in Scenario 1. The<br />

latter two steps in the list above are also shown in the PlayToReceiver sample that is set up to receive a<br />

media stream from another source.<br />

PlayTo<br />

The final case of streaming is centered on the PlayTo capabilities that were introduced in Windows 7.<br />

Simply said, PlayTo is a means through which an app can connect local playback/display for audio,<br />

video, and img elements to a remote device.<br />

The details happen through the Windows.Media.PlayTo APIs along with the extension methods<br />

added to media elements. If, for example, you want to specifically start a process of streaming to a<br />

PlayTo device, invoking the selection UI directly, you’d do the following:<br />

• Windows.Media.PlayTo.PlayToManager:<br />

o<br />

o<br />

o<br />

getForCurrentView returns the object.<br />

showPlayToUI invokes the flyout UI where the user selects a receiver.<br />

sourceRequested event is fired when user selects a receiver.<br />

• In sourceRequested<br />

o<br />

Get PlayToSource object from audio, video, or img element (msPlayToSource property) and<br />

pass to e.setSource.<br />

463

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

Saved successfully!

Ooh no, something went wrong!