PlayToReceiver constructor

PlayToReceiver.PlayToReceiver constructor

Creates a new instance of a Play To receiver.

Syntax


Public Sub New ()

Parameters

This constructor has no parameters.

Remarks

For an example of creating a software Play To receiver, see Media casting or Media casting.


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


Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Capabilities

privateNetworkClientServer

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

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

None supported

Namespace

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

Metadata

Windows.winmd

Capabilities

privateNetworkClientServer

See also

PlayToReceiver
Samples
Play To sample
PlayToReceiver sample
Media Server sample

 

 

Show:
© 2016 Microsoft