Windows Dev Center

PlayToConnection class

Provides information about a Play To connection.

Syntax


public sealed class PlayToConnection

Members

The PlayToConnection class has these types of members:

Events

The PlayToConnection class has these events.

EventDescription
Error Occurs when an error is encountered for the Play To connection.
StateChanged Occurs when the state of the Play To connection has changed.
Transferred Occurs when the Play To connection is transferred to the next Play To source.

 

Methods

The PlayToConnection class inherits methods from the Object class (C#/VB/C++).

Properties

The PlayToConnection class has these properties.

PropertyAccess typeDescription

State

Read-onlyGets the state of the Play To connection.

 

Remarks

For an example of how to use Play To in an application, see Quickstart: Using Play To in applications (JavaScript) or Quickstart: Using Play To in applications (C#/VB).

Examples


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

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

    private void sourceRequestHandlerWithEvents(
    Windows.Media.PlayTo.PlayToManager sender,
    Windows.Media.PlayTo.PlayToSourceRequestedEventArgs e)
    {
try
{
    var controller = mediaElement.PlayToSource;

    controller.Connection.Error += playToConnectionError;
    controller.Connection.StateChanged += playToConnectionStageChanged;
    controller.Connection.Transferred += playToConnectionTransferred;

    e.SourceRequest.SetSource(controller);
}
catch (Exception ex)
{
    messageBlock.Text += "Exception encountered: " + ex.Message + "\n";
}
    }

    // Called when the user selects a Play To device to stream to.

    private void sourceSelectedHandler(
Windows.Media.PlayTo.PlayToManager sender,
Windows.Media.PlayTo.PlayToSourceSelectedEventArgs e)
    {
if (mediaElement.Name == "iplayer") {
    if (!e.SupportsImage) {
        messageBlock.Text += e.FriendlyName + " does not support streaming images. " +
                             "Please select a different device.";
        return;
    }
}

if (mediaElement.Name == "vplayer") {
    if (!e.SupportsVideo) {
        messageBlock.Text += e.FriendlyName + " does not support streaming video. " +
                             "Please select a different device.";
        return;
    }
}

if (mediaElement.Name == "aplayer") {
    if (!e.SupportsAudio) {
        messageBlock.Text += e.FriendlyName + " does not support streaming audio. " +
                             "Please select a different device.";
        return;
    }
}

Windows.Storage.Streams.IRandomAccessStream iconStream = e.Icon;
Windows.UI.Xaml.Media.Imaging.BitmapImage iconBitmap = 
        new Windows.UI.Xaml.Media.Imaging.BitmapImage();
iconBitmap.SetSource(iconStream);
playToDeviceIconImage.Source = iconBitmap;

playToDeviceFriendlyNameBlock.Text = e.FriendlyName;
    }

    private void playToConnectionError(
Windows.Media.PlayTo.PlayToConnection connection,
Windows.Media.PlayTo.PlayToConnectionErrorEventArgs e)
    {
if (e.Code == Windows.Media.PlayTo.PlayToConnectionError.DeviceError ||
    e.Code == Windows.Media.PlayTo.PlayToConnectionError.DeviceNotResponding) 
{
    messageBlock.Text += "Error occurred. Disconnecting.\n";
}

messageBlock.Text += "Error: Message = " + e.Message.ToString() + "\n";
    }

   private void playToConnectionStageChanged(
       Windows.Media.PlayTo.PlayToConnection connection, 
       Windows.Media.PlayTo.PlayToConnectionStateChangedEventArgs e) 
    {
messageBlock.Text += "StateChanged: PreviousState = " + e.PreviousState.ToString() + "\n";
messageBlock.Text += "StateChanged: CurrentState = " + e.CurrentState.ToString() + "\n";
    }

   private void playToConnectionTransferred(
       Windows.Media.PlayTo.PlayToConnection connection, 
       Windows.Media.PlayTo.PlayToConnectionTransferredEventArgs e)
    {
messageBlock.Text += "Transferred: PreviousSource = " + e.PreviousSource.ToString() + "\n";
messageBlock.Text += "Transferred: CurrentSource = " + e.CurrentSource.ToString() + "\n";
    }


Requirements (Windows 10 device family)

Device family

Universal

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

Windows.Media.PlayTo
Windows::Media::PlayTo [C++]

Metadata

Windows.Foundation.UniversalApiContract.winmd

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Runtime apps only]

Namespace

Windows.Media.PlayTo
Windows::Media::PlayTo [C++]

Metadata

Windows.winmd

Attributes

[Deprecated()]
[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

See also

Object
Samples
Play To sample
PlayToReceiver sample
Media Server sample

 

 

Show:
© 2015 Microsoft