PlayToReceiver class

Applies to Windows only

Represents a Play To target.

Syntax


Public NotInheritable Class PlayToReceiver

Attributes

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

Members

The PlayToReceiver class has these types of members:

Constructors

The PlayToReceiver class has these constructors.

ConstructorDescription
PlayToReceiver Creates a new instance of a Play To receiver.

 

Events

The PlayToReceiver class has these events.

EventDescription
CurrentTimeChangeRequested Occurs when the time location of the playback has changed.
MuteChangeRequested Occurs when the audio has been muted or unmuted.
PauseRequested Occurs when audio or video playback has been paused.
PlaybackRateChangeRequested Occurs when the rate of audio or video playback has changed.
PlayRequested Occurs when audio or video playback starts.
SourceChangeRequested Occurs when the source media for the Play To receiver have changed.
StopRequested Occurs when a request has been made for the Play To receiver to stop playing the streamed media.
TimeUpdateRequested Occurs when the current playback position has changed.
VolumeChangeRequested Occurs when the volume for the source audio or video has changed.

 

Methods

The PlayToReceiver class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

MethodDescription
NotifyDurationChange Notifies the Play To receiver that the duration of the audio or video playback has changed.
NotifyEnded Notifies the Play To receiver that the audio or video playback has ended.
NotifyError Notifies the Play To receiver that an error has occurred in displaying or playing the media.
NotifyLoadedMetadata Notifies the Play To receiver that metadata for the media has finished loading.
NotifyPaused Notifies the Play To receiver that the audio or video playback has been paused.
NotifyPlaying Notifies the Play To receiver that the audio or video playback has started.
NotifyRateChange Notifies the Play To receiver that the rate of the audio or video playback has changed.
NotifySeeked Notifies the Play To receiver that the audio or video playback element has started at a new playback location.
NotifySeeking Notifies the Play To receiver that the audio or video playback element is seeking a new playback location.
NotifyStopped Notifies the Play To receiver that the audio or video playback has stopped.
NotifyTimeUpdate Notifies the Play To receiver that the time location of the audio or video playback has changed.
NotifyVolumeChange Notifies the Play To receiver that the volume of the audio or video playback has changed.
StartAsync Start receiving Play To commands.
StopAsync Stop receiving Play To commands.

 

Properties

The PlayToReceiver class has these properties.

PropertyAccess typeDescription

FriendlyName

Read/writeGets or sets the display name of the Play To target.

Properties

Read-onlyGets a set of custom properties for the Play To receiver.

SupportsAudio

Read/writeGets or sets a value that indicates whether the Play To target supports audio.

SupportsImage

Read/writeGets or sets a value that indicates whether the Play To target supports images.

SupportsVideo

Read/writeGets or sets a value that indicates whether the Play To target supports video.

 

Remarks

You can use the PlayToReceiver class to create a custom software Play To receiver that is a digital media renderer for computers on your network. You can include a PlayToReceiver object in your app to handle communication with Play To client computers, and then play or display content streamed from those computers using your own media elements or controls.

The members of the PlayToReceiver class consist of the following:

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.

For an example of creating a software Play To receiver, see Quickstart: Creating a Play To Receiver (JavaScript) or Quickstart: Creating a Play To Receiver (C#/VB).


Private receiver As Windows.Media.PlayTo.PlayToReceiver
Private display As Windows.System.Display.DisplayRequest
Private seeking As Boolean = False

Private Async Sub StartReceiverButton_Click()
    Try
        If receiver Is Nothing Then
            receiver = New Windows.Media.PlayTo.PlayToReceiver()
        End If

        ' Add Play To Receiver events and properties
        AddHandler receiver.CurrentTimeChangeRequested, AddressOf receiver_CurrentTimeChangeRequested
        AddHandler receiver.MuteChangeRequested, AddressOf receiver_MuteChangeRequested
        AddHandler receiver.PauseRequested, AddressOf receiver_PauseRequested
        AddHandler receiver.PlaybackRateChangeRequested, AddressOf receiver_PlaybackRateChangeRequested
        AddHandler receiver.PlayRequested, AddressOf receiver_PlayRequested
        AddHandler receiver.SourceChangeRequested, AddressOf receiver_SourceChangeRequested
        AddHandler receiver.StopRequested, AddressOf receiver_StopRequested
        AddHandler receiver.TimeUpdateRequested, AddressOf receiver_TimeUpdateRequested
        AddHandler receiver.VolumeChangeRequested, AddressOf receiver_VolumeChangeRequested

        receiver.FriendlyName = "Sample Play To Receiver"
        receiver.SupportsAudio = False
        receiver.SupportsVideo = True
        receiver.SupportsImage = False

        ' Add MediaElement events
        AddHandler VideoPlayer.CurrentStateChanged, AddressOf VideoPlayer_CurrentStateChanged
        AddHandler VideoPlayer.MediaEnded, AddressOf VideoPlayer_MediaEnded
        AddHandler VideoPlayer.MediaFailed, AddressOf VideoPlayer_MediaFailed
        AddHandler VideoPlayer.MediaOpened, AddressOf VideoPlayer_MediaOpened
        AddHandler VideoPlayer.RateChanged, AddressOf VideoPlayer_RateChanged
        AddHandler VideoPlayer.SeekCompleted, AddressOf VideoPlayer_SeekCompleted
        AddHandler VideoPlayer.VolumeChanged, AddressOf VideoPlayer_VolumeChanged

        ' Advertise the receiver on the local network and start receiving commands
        Await receiver.StartAsync()

        ' Prevent the screen from locking
        If display Is Nothing Then
            display = New Windows.System.Display.DisplayRequest()
            display.RequestActive()

            StatusTextBlock.Text = "'" & receiver.FriendlyName & "' started."
        End If
    Catch
        receiver = Nothing
        StatusTextBlock.Text = "Failed to start receiver. "
    End Try
End Sub

Private Async Sub StopReceiverButton_Click()
    Try
        If receiver IsNot Nothing Then
            Await receiver.StopAsync()

            If display IsNot Nothing Then display.RequestRelease()

            ' Remove Play To Receiver events
            RemoveHandler receiver.CurrentTimeChangeRequested, AddressOf receiver_CurrentTimeChangeRequested
            RemoveHandler receiver.MuteChangeRequested, AddressOf receiver_MuteChangeRequested
            RemoveHandler receiver.PauseRequested, AddressOf receiver_PauseRequested
            RemoveHandler receiver.PlaybackRateChangeRequested, AddressOf receiver_PlaybackRateChangeRequested
            RemoveHandler receiver.PlayRequested, AddressOf receiver_PlayRequested
            RemoveHandler receiver.SourceChangeRequested, AddressOf receiver_SourceChangeRequested
            RemoveHandler receiver.StopRequested, AddressOf receiver_StopRequested
            RemoveHandler receiver.TimeUpdateRequested, AddressOf receiver_TimeUpdateRequested
            RemoveHandler receiver.VolumeChangeRequested, AddressOf receiver_VolumeChangeRequested

            '  Remove MediaElement events
            VideoPlayer.Pause()

            RemoveHandler VideoPlayer.CurrentStateChanged, AddressOf VideoPlayer_CurrentStateChanged
            RemoveHandler VideoPlayer.MediaEnded, AddressOf VideoPlayer_MediaEnded
            RemoveHandler VideoPlayer.MediaFailed, AddressOf VideoPlayer_MediaFailed
            RemoveHandler VideoPlayer.MediaOpened, AddressOf VideoPlayer_MediaOpened
            RemoveHandler VideoPlayer.RateChanged, AddressOf VideoPlayer_RateChanged
            RemoveHandler VideoPlayer.SeekCompleted, AddressOf VideoPlayer_SeekCompleted
            RemoveHandler VideoPlayer.VolumeChanged, AddressOf VideoPlayer_VolumeChanged

            StatusTextBlock.Text = "Stopped '" & receiver.FriendlyName & "'."
        End If
    Catch
        StatusTextBlock.Text = "Failed to stop '" & receiver.FriendlyName & "'."
    End Try
End Sub


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.

Note  : This class is not agile, which means that you need to consider its threading model and marshaling behavior. For more info, see Threading and Marshaling (C++/CX) and Using Windows Runtime objects in a multithreaded environment (.NET).

Requirements

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

None supported

Namespace

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

Metadata

Windows.winmd

Capabilities

privateNetworkClientServer

See also

Samples
Play To sample
PlayToReceiver sample
Media Server sample

 

 

Show:
© 2014 Microsoft