PlayToConnection class

Applies to Windows and Windows Phone

Provides information about a Play To connection.

Syntax

Public NotInheritable Class PlayToConnection

Attributes

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

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 ptm As Windows.Media.PlayTo.PlayToManager =
            Windows.Media.PlayTo.PlayToManager.GetForCurrentView()

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

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

        Try
            Dim controller = mediaElement.PlayToSource

            AddHandler controller.Connection.Error, AddressOf playToConnectionError
            AddHandler controller.Connection.StateChanged, AddressOf playToConnectionStageChanged
            AddHandler controller.Connection.Transferred, AddressOf playToConnectionTransferred

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

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

    Private Sub sourceSelectedHandler(
        sender As Windows.Media.PlayTo.PlayToManager,
        e As Windows.Media.PlayTo.PlayToSourceSelectedEventArgs)

        If mediaElement.Name = "iplayer" Then
            If Not e.SupportsImage Then
                messageBlock.Text &= e.FriendlyName & " does not support streaming images. " &
                                     "Please select a different device."
                Return
            End If
        End If

        If mediaElement.Name = "vplayer" Then
            If Not e.SupportsVideo Then
                messageBlock.Text &= e.FriendlyName & " does not support streaming video. " &
                                     "Please select a different device."
                Return
            End If
        End If

        If mediaElement.Name = "aplayer" Then
            If Not e.SupportsAudio Then
                messageBlock.Text &= e.FriendlyName & " does not support streaming audio. " &
                                     "Please select a different device."
                Return
            End If
        End If

        Dim iconStream = e.Icon
        Dim iconBitmap = New Windows.UI.Xaml.Media.Imaging.BitmapImage()
        iconBitmap.SetSource(iconStream)
        playToDeviceIconImage.Source = iconBitmap

        playToDeviceFriendlyNameBlock.Text = e.FriendlyName
    End Sub

    Private Sub playToConnectionError(
        connection As Windows.Media.PlayTo.PlayToConnection,
        e As Windows.Media.PlayTo.PlayToConnectionErrorEventArgs)

        If e.Code = Windows.Media.PlayTo.PlayToConnectionError.DeviceError OrElse
            e.Code = Windows.Media.PlayTo.PlayToConnectionError.DeviceNotResponding Then

            messageBlock.Text &= "Error occurred. Disconnecting." & vbCrLf
        End If

        messageBlock.Text &= "Error: Message = " & e.Message.ToString() & vbCrLf
    End Sub

    Private Sub playToConnectionStageChanged(
        connection As Windows.Media.PlayTo.PlayToConnection,
        e As Windows.Media.PlayTo.PlayToConnectionStateChangedEventArgs)

        messageBlock.Text &= "StateChanged: PreviousState = " & e.PreviousState.ToString() & vbCrLf
        messageBlock.Text &= "StateChanged: CurrentState = " & e.CurrentState.ToString() & vbCrLf
    End Sub

    Private Sub playToConnectionTransferred(
        connection As Windows.Media.PlayTo.PlayToConnection,
        e As Windows.Media.PlayTo.PlayToConnectionTransferredEventArgs)

        messageBlock.Text &= "Transferred: PreviousSource = " & e.PreviousSource.ToString() & vbCrLf
        messageBlock.Text &= "Transferred: CurrentSource = " & e.CurrentSource.ToString() & vbCrLf
    End Sub

Requirements

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

See also

Samples
Play To sample
PlayToReceiver sample
Media Server sample

 

 

Show:
© 2014 Microsoft