PlayToManager PlayToManager PlayToManager PlayToManager Class

Definition

Provides access to Play To capabilities.

public sealed class PlayToManagerpublic sealed class PlayToManagerPublic NotInheritable Class PlayToManagerpublic sealed class PlayToManager
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

If your application includes audio, video, or image elements, users can stream the media source for those elements to a Play To target device. You can use the PlayToManager class to customize the Play To experience for users. You can disable the default behavior by using the DefaultSourceSelection property.You can select which media is streamed by using the SourceRequested event. And you can display the Play To UI in place of the Devices charm by using the ShowPlayToUI() method.

In Play To, video starts from the current position. If you want to start the video from the beginning, simply seek to the beginning of the video as soon as the Play To connection is established.

PlayTo apps will not be suspended as long as video or music is playing on the Play To receiver or images are continuously sent to the Play To receiver. Apps have approximately 10 seconds to send a new image after the current one is displayed and approximately 10 seconds to send the next audio or video after the current one has ended.

For an example of how to use Play To in an application, see Quickstart: Using Play To in applications (JavaScript) or PlayReady DRM.

Examples

// Play To Contract

private Windows.Media.PlayTo.PlayToManager ptm = 
        Windows.Media.PlayTo.PlayToManager.GetForCurrentView();

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    ptm.SourceRequested += sourceRequestHandler;
}

private void sourceRequestHandler(
    Windows.Media.PlayTo.PlayToManager sender,
    Windows.Media.PlayTo.PlayToSourceRequestedEventArgs e)
{
    try
    {
        e.SourceRequest.SetSource(mediaElement.PlayToSource);
    }
    catch (Exception ex)
    {
        messageBlock.Text += "Exception encountered: " + ex.Message + "\n";
    }
}
// Play To Contract

var ptm = Windows.Media.PlayTo.PlayToManager.getForCurrentView();
ptm.addEventListener("sourcerequested", sourceRequestHandler, false);

function sourceRequestHandler(e) {
    try {
        e.sourceRequest.setSource(mediaElement.msPlayToSource);

    } catch (ex) {
        id("messageDiv").innerHTML += "Exception encountered: " + ex.message + "<br/>";
    }
}
' Play To Contract

Private ptm As Windows.Media.PlayTo.PlayToManager =
        Windows.Media.PlayTo.PlayToManager.GetForCurrentView()

Protected Overrides Sub OnNavigatedTo(e As Navigation.NavigationEventArgs)
    AddHandler ptm.SourceRequested, AddressOf sourceRequestHandler
End Sub

Private Sub sourceRequestHandler(
    sender As Windows.Media.PlayTo.PlayToManager,
    e As Windows.Media.PlayTo.PlayToSourceRequestedEventArgs)

    Try
        e.SourceRequest.SetSource(mediaElement.PlayToSource)
    Catch ex As Exception
        messageBlock.Text &= "Exception encountered: " & ex.Message & vbCrLf
    End Try
End Sub

Properties

DefaultSourceSelection DefaultSourceSelection DefaultSourceSelection DefaultSourceSelection

Enables or disables the default source selection for Play To.

public bool DefaultSourceSelection { get; set; }public bool DefaultSourceSelection { get; set; }Public ReadWrite Property DefaultSourceSelection As boolpublic bool DefaultSourceSelection { get; set; }
Value
bool bool bool bool

True to enable default source selection; otherwise false. The default is true.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

An app that contains media elements has Play To enabled by default. If a user invokes the Devices charm while running the app and selects a target device to stream media to, Play To will stream the media from the first audio, video, or image element on the current page. You can disable this default behavior by setting the DefaultSourceSelection property to false.

var ptm = Windows.Media.PlayTo.PlayToManager.getForCurrentView();
ptm.defaultSourceSelection = false;

You can exclude individual HTML elements from the default Play To behavior by adding the -ms-playToDisabled attribute in your HTML markup.

<video src="http://www.example.com/videos/video.mp4" x-ms-playToDisabled/>

Methods

GetForCurrentView() GetForCurrentView() GetForCurrentView() GetForCurrentView()

Gets the Play To manager for the current view.

public static PlayToManager GetForCurrentView()public static PlayToManager GetForCurrentView()Public Static Function GetForCurrentView() As PlayToManagerpublic static PlayToManager GetForCurrentView()
Returns

The Play To manager for the current view.

Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

You can use the PlayToManager instance for the current view to establish the Play To contract for the app and customize which media Play To streams to a target device. You supply the media to be streamed during the SourceRequested event by using the SetSource(PlayToSource) method.

ShowPlayToUI() ShowPlayToUI() ShowPlayToUI() ShowPlayToUI()

Displays the Play To UI.

public static void ShowPlayToUI()public static void ShowPlayToUI()Public Static Function ShowPlayToUI() As voidpublic static void ShowPlayToUI()
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

By default, users invoke the Devices charm to select a Play To target device to stream media to. You can also display the UI to enable users to select a Play To target device by using the ShowPlayToUI method.

Events

SourceRequested SourceRequested SourceRequested SourceRequested

Occurs when a user requests media to stream to a Play To target device.

public event TypedEventHandler SourceRequestedpublic event TypedEventHandler SourceRequestedPublic Event SourceRequestedpublic event TypedEventHandler SourceRequested
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

The SourceRequested event is fired when a user selects the Devices charm in a Play To– enabled application. You supply the audio, video, or image that Play To will stream to a target device during the SourceRequested event.

If you do not supply a media source within 200 milliseconds, the SourceRequested event will time out and the Devices charm will not display any Play To targets for your app.

The SourceRequested event occurs before the user selects the target device. After the user has selected the target device, the SourceSelected event is fired. If the user exits the Devices charm without selecting a target device, the SourceSelected event isn't fired.

SourceSelected SourceSelected SourceSelected SourceSelected

Occurs when a Play To source element has been selected.

public event TypedEventHandler SourceSelectedpublic event TypedEventHandler SourceSelectedPublic Event SourceSelectedpublic event TypedEventHandler SourceSelected
Attributes
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)

Remarks

In a Play To– enabled app, the user selects the Devices charm (or the Play To UI) to stream audio, video, or images from the app to a target device. The SourceSelected event is fired after the user has selected a target device. If the user exits the Devices charm or the Play To UI without selecting a target device, the SourceSelected event isn't fired.