PlayToReceiver PlayToReceiver PlayToReceiver PlayToReceiver Class

Represents a Play To target.

Syntax

Declaration

public sealed class PlayToReceiverpublic sealed class PlayToReceiverPublic NotInheritable Class PlayToReceiverpublic sealed class PlayToReceiver

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 Media casting or Media casting.

var receiver;
var display;
var videoPlayer;

function startReceiverButton_Click() {
    try {
        if (receiver == null) {
            receiver = new Windows.Media.PlayTo.PlayToReceiver();
        }

        // Add Play To Receiver events and properties
        receiver.addEventListener("currenttimechangerequested", receiver_CurrentTimeChangeRequested);
        receiver.addEventListener("mutechangerequested", receiver_MuteChangeRequested);
        receiver.addEventListener("pauserequested", receiver_PauseRequested);
        receiver.addEventListener("playbackratechangerequested", receiver_PlaybackRateChangeRequested);
        receiver.addEventListener("playrequested", receiver_PlayRequested);
        receiver.addEventListener("sourcechangerequested", receiver_SourceChangeRequested);
        receiver.addEventListener("stoprequested", receiver_StopRequested);
        receiver.addEventListener("timeupdaterequested", receiver_TimeUpdateRequested);
        receiver.addEventListener("volumechangerequested", receiver_VolumeChangeRequested);

        receiver.friendlyName = "Sample Play To Receiver";
        receiver.supportsAudio = false;
        receiver.supportsVideo = true;
        receiver.supportsImage = false;

        // Add MediaElement events
        videoPlayer = document.getElementById("videoPlayer");
        videoPlayer.addEventListener("durationchange",videoPlayer_DurationChange); 
        videoPlayer.addEventListener("ended", videoPlayer_Ended); 
        videoPlayer.addEventListener("error", videoPlayer_Error);
        videoPlayer.addEventListener("loadedmetadata", videoPlayer_LoadedMetadata); 
        videoPlayer.addEventListener("pause", videoPlayer_Pause); 
        videoPlayer.addEventListener("playing", videoPlayer_Playing); 
        videoPlayer.addEventListener("ratechange", videoPlayer_RateChange); 
        videoPlayer.addEventListener("seeked", videoPlayer_Seeked); 
        videoPlayer.addEventListener("seeking", videoPlayer_Seeking); 
        videoPlayer.addEventListener("volumechange", videoPlayer_VolumeChange); 

        // Advertise the receiver on the local network and start receiving commands
        receiver.startAsync().done(function () {
            // Prevent the screen from locking
            if (display == null) {
                display = new Windows.System.Display.DisplayRequest();
            }
            display.requestActive();

            statusDiv.innerHTML = "'" + receiver.friendlyName + "' started.";
        });


    }
    catch(e) {
        receiver = null;
        statusDiv.innerHTML = "Failed to start receiver.";
    }
}

function stopReceiverButton_Click(e) {
    try {
        if (receiver != null) {
            receiver.stopAsync().done(function() {
                if (display != null)
                    display.requestRelease();

                // Remove Play To Receiver events
                receiver.removeEventListener("currenttimechangerequested", receiver_CurrentTimeChangeRequested);
                receiver.removeEventListener("mutechangerequested", receiver_MuteChangeRequested);
                receiver.removeEventListener("pauserequested", receiver_PauseRequested);
                receiver.removeEventListener("playbackratechangerequested", receiver_PlaybackRateChangeRequested);
                receiver.removeEventListener("playrequested", receiver_PlayRequested);
                receiver.removeEventListener("sourcechangerequested", receiver_SourceChangeRequested);
                receiver.removeEventListener("stoprequested", receiver_StopRequested);
                receiver.removeEventListener("timeupdaterequested", receiver_TimeUpdateRequested);
                receiver.removeEventListener("volumechangerequested", receiver_VolumeChangeRequested);

                //  Remove MediaElement events
                videoPlayer = document.getElementById("videoPlayer");
                if (videoPlayer.readyState != 0) {
                    videoPlayer.pause();
                    videoPlayer.currentTime = 0;
                }

                videoPlayer.removeEventListener("durationchange",videoPlayer_DurationChange); 
                videoPlayer.removeEventListener("ended", videoPlayer_Ended); 
                videoPlayer.removeEventListener("error", videoPlayer_Error);
                videoPlayer.removeEventListener("loadedmetadata", videoPlayer_LoadedMetadata); 
                videoPlayer.removeEventListener("pause", videoPlayer_Pause); 
                videoPlayer.removeEventListener("playing", videoPlayer_Playing); 
                videoPlayer.removeEventListener("ratechange", videoPlayer_RateChange); 
                videoPlayer.removeEventListener("seeked", videoPlayer_Seeked); 
                videoPlayer.removeEventListener("seeking", videoPlayer_Seeking); 
                videoPlayer.removeEventListener("volumechange", videoPlayer_VolumeChange); 

                statusDiv.innerHTML = "Stopped receiver.";
            });
        }
    }
    catch (e) {
        statusDiv.innerHTML = "Failed to stop '" + receiver.FriendlyName + "'.";
    }
}
Windows.Media.PlayTo.PlayToReceiver receiver;
Windows.System.Display.DisplayRequest display;
Windows.UI.Core.CoreDispatcher dispatcher;
bool seeking = false;

private async void StartReceiverButton_Click(object sender, RoutedEventArgs e)
{
    try
    {
        dispatcher = Window.Current.CoreWindow.Dispatcher;

        if (receiver == null)
        {
            receiver = new Windows.Media.PlayTo.PlayToReceiver();
        }

        // Add Play To Receiver events and properties
        receiver.CurrentTimeChangeRequested += receiver_CurrentTimeChangeRequested;
        receiver.MuteChangeRequested += receiver_MuteChangeRequested;
        receiver.PauseRequested += receiver_PauseRequested;
        receiver.PlaybackRateChangeRequested += receiver_PlaybackRateChangeRequested;
        receiver.PlayRequested += receiver_PlayRequested;
        receiver.SourceChangeRequested += receiver_SourceChangeRequested;
        receiver.StopRequested += receiver_StopRequested;
        receiver.TimeUpdateRequested += receiver_TimeUpdateRequested;
        receiver.VolumeChangeRequested += receiver_VolumeChangeRequested;

        receiver.FriendlyName = "Sample Play To Receiver";
        receiver.SupportsAudio = false;
        receiver.SupportsVideo = true;
        receiver.SupportsImage = false;

        // Add MediaElement events
        VideoPlayer.CurrentStateChanged += VideoPlayer_CurrentStateChanged;
        VideoPlayer.MediaEnded += VideoPlayer_MediaEnded;
        VideoPlayer.MediaFailed += VideoPlayer_MediaFailed;
        VideoPlayer.MediaOpened += VideoPlayer_MediaOpened;
        VideoPlayer.RateChanged += VideoPlayer_RateChanged;
        VideoPlayer.SeekCompleted += VideoPlayer_SeekCompleted;
        VideoPlayer.VolumeChanged += VideoPlayer_VolumeChanged;

        // Advertise the receiver on the local network and start receiving commands
        await receiver.StartAsync();

        // Prevent the screen from locking
        if (display == null)
            display = new Windows.System.Display.DisplayRequest();
        display.RequestActive();

        StatusTextBlock.Text = "'" + receiver.FriendlyName + "' started.";
    }
    catch
    {
        receiver = null;
        StatusTextBlock.Text = "Failed to start receiver.";
    }
}

private async void StopReceiverButton_Click(object sender, RoutedEventArgs e)
{
    try
    {
        if (receiver != null)
        {
            await receiver.StopAsync();

            if (display != null)
                display.RequestRelease();

            // Remove Play To Receiver events
            receiver.CurrentTimeChangeRequested -= receiver_CurrentTimeChangeRequested;
            receiver.MuteChangeRequested -= receiver_MuteChangeRequested;
            receiver.PauseRequested -= receiver_PauseRequested;
            receiver.PlaybackRateChangeRequested -= receiver_PlaybackRateChangeRequested;
            receiver.PlayRequested -= receiver_PlayRequested;
            receiver.SourceChangeRequested -= receiver_SourceChangeRequested;
            receiver.StopRequested -= receiver_StopRequested;
            receiver.TimeUpdateRequested -= receiver_TimeUpdateRequested;
            receiver.VolumeChangeRequested -= receiver_VolumeChangeRequested;

            //  Remove MediaElement events
            VideoPlayer.Pause();

            VideoPlayer.CurrentStateChanged -= VideoPlayer_CurrentStateChanged;
            VideoPlayer.MediaEnded -= VideoPlayer_MediaEnded;
            VideoPlayer.MediaFailed -= VideoPlayer_MediaFailed;
            VideoPlayer.MediaOpened -= VideoPlayer_MediaOpened;
            VideoPlayer.RateChanged -= VideoPlayer_RateChanged;
            VideoPlayer.SeekCompleted -= VideoPlayer_SeekCompleted;
            VideoPlayer.VolumeChanged -= VideoPlayer_VolumeChanged;

            StatusTextBlock.Text = "Stopped '" + receiver.FriendlyName + "'.";
        }
    }
    catch
    {
        StatusTextBlock.Text = "Failed to stop '" + receiver.FriendlyName + "'.";
    }
}
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).

Constructors summary

Creates a new instance of a Play To receiver.

Properties summary

Gets or sets the display name of the Play To target.

Gets a set of custom properties for the Play To receiver.

Gets or sets a value that indicates whether the Play To target supports audio.

Gets or sets a value that indicates whether the Play To target supports images.

Gets or sets a value that indicates whether the Play To target supports video.

Methods summary

Notifies the Play To receiver that the duration of the audio or video playback has changed.

Notifies the Play To receiver that the audio or video playback has ended.

Notifies the Play To receiver that an error has occurred in displaying or playing the media.

Notifies the Play To receiver that metadata for the media has finished loading.

Notifies the Play To receiver that the audio or video playback has been paused.

Notifies the Play To receiver that the audio or video playback has started.

Notifies the Play To receiver that the rate of the audio or video playback has changed.

Notifies the Play To receiver that the audio or video playback element has started at a new playback location.

Notifies the Play To receiver that the audio or video playback element is seeking a new playback location.

Notifies the Play To receiver that the audio or video playback has stopped.

Notifies the Play To receiver that the time location of the audio or video playback has changed.

Notifies the Play To receiver that the volume of the audio or video playback has changed.

Start receiving Play To commands.

Stop receiving Play To commands.

Events summary

Occurs when the time location of the playback has changed.

Occurs when the audio has been muted or unmuted.

Occurs when audio or video playback has been paused.

Occurs when the rate of audio or video playback has changed.

Occurs when audio or video playback starts.

Occurs when the source media for the Play To receiver have changed.

Occurs when a request has been made for the Play To receiver to stop playing the streamed media.

Occurs when the current playback position has changed.

Occurs when the volume for the source audio or video has changed.

Constructors

  • PlayToReceiver()
    PlayToReceiver()
    PlayToReceiver()
    PlayToReceiver()

    Creates a new instance of a Play To receiver.

    public PlayToReceiver()public New()Public Sub New()public PlayToReceiver()

    Remarks

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

    Windows.Media.PlayTo.PlayToReceiver receiver;
    Windows.System.Display.DisplayRequest display;
    Windows.UI.Core.CoreDispatcher dispatcher;
    bool seeking = false;
    
    private async void StartReceiverButton_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            dispatcher = Window.Current.CoreWindow.Dispatcher;
    
            if (receiver == null)
            {
                receiver = new Windows.Media.PlayTo.PlayToReceiver();
            }
    
            // Add Play To Receiver events and properties
            receiver.CurrentTimeChangeRequested += receiver_CurrentTimeChangeRequested;
            receiver.MuteChangeRequested += receiver_MuteChangeRequested;
            receiver.PauseRequested += receiver_PauseRequested;
            receiver.PlaybackRateChangeRequested += receiver_PlaybackRateChangeRequested;
            receiver.PlayRequested += receiver_PlayRequested;
            receiver.SourceChangeRequested += receiver_SourceChangeRequested;
            receiver.StopRequested += receiver_StopRequested;
            receiver.TimeUpdateRequested += receiver_TimeUpdateRequested;
            receiver.VolumeChangeRequested += receiver_VolumeChangeRequested;
    
            receiver.FriendlyName = "Sample Play To Receiver";
            receiver.SupportsAudio = false;
            receiver.SupportsVideo = true;
            receiver.SupportsImage = false;
    
            // Add MediaElement events
            VideoPlayer.CurrentStateChanged += VideoPlayer_CurrentStateChanged;
            VideoPlayer.MediaEnded += VideoPlayer_MediaEnded;
            VideoPlayer.MediaFailed += VideoPlayer_MediaFailed;
            VideoPlayer.MediaOpened += VideoPlayer_MediaOpened;
            VideoPlayer.RateChanged += VideoPlayer_RateChanged;
            VideoPlayer.SeekCompleted += VideoPlayer_SeekCompleted;
            VideoPlayer.VolumeChanged += VideoPlayer_VolumeChanged;
    
            // Advertise the receiver on the local network and start receiving commands
            await receiver.StartAsync();
    
            // Prevent the screen from locking
            if (display == null)
                display = new Windows.System.Display.DisplayRequest();
            display.RequestActive();
    
            StatusTextBlock.Text = "'" + receiver.FriendlyName + "' started.";
        }
        catch
        {
            receiver = null;
            StatusTextBlock.Text = "Failed to start receiver.";
        }
    }
    
    private async void StopReceiverButton_Click(object sender, RoutedEventArgs e)
    {
        try
        {
            if (receiver != null)
            {
                await receiver.StopAsync();
    
                if (display != null)
                    display.RequestRelease();
    
                // Remove Play To Receiver events
                receiver.CurrentTimeChangeRequested -= receiver_CurrentTimeChangeRequested;
                receiver.MuteChangeRequested -= receiver_MuteChangeRequested;
                receiver.PauseRequested -= receiver_PauseRequested;
                receiver.PlaybackRateChangeRequested -= receiver_PlaybackRateChangeRequested;
                receiver.PlayRequested -= receiver_PlayRequested;
                receiver.SourceChangeRequested -= receiver_SourceChangeRequested;
                receiver.StopRequested -= receiver_StopRequested;
                receiver.TimeUpdateRequested -= receiver_TimeUpdateRequested;
                receiver.VolumeChangeRequested -= receiver_VolumeChangeRequested;
    
                //  Remove MediaElement events
                VideoPlayer.Pause();
    
                VideoPlayer.CurrentStateChanged -= VideoPlayer_CurrentStateChanged;
                VideoPlayer.MediaEnded -= VideoPlayer_MediaEnded;
                VideoPlayer.MediaFailed -= VideoPlayer_MediaFailed;
                VideoPlayer.MediaOpened -= VideoPlayer_MediaOpened;
                VideoPlayer.RateChanged -= VideoPlayer_RateChanged;
                VideoPlayer.SeekCompleted -= VideoPlayer_SeekCompleted;
                VideoPlayer.VolumeChanged -= VideoPlayer_VolumeChanged;
    
                StatusTextBlock.Text = "Stopped '" + receiver.FriendlyName + "'.";
            }
        }
        catch
        {
            StatusTextBlock.Text = "Failed to stop '" + receiver.FriendlyName + "'.";
        }
    }
    
    var receiver;
    var display;
    var videoPlayer;
    
    function startReceiverButton_Click() {
        try {
            if (receiver == null) {
                receiver = new Windows.Media.PlayTo.PlayToReceiver();
            }
    
            // Add Play To Receiver events and properties
            receiver.addEventListener("currenttimechangerequested", receiver_CurrentTimeChangeRequested);
            receiver.addEventListener("mutechangerequested", receiver_MuteChangeRequested);
            receiver.addEventListener("pauserequested", receiver_PauseRequested);
            receiver.addEventListener("playbackratechangerequested", receiver_PlaybackRateChangeRequested);
            receiver.addEventListener("playrequested", receiver_PlayRequested);
            receiver.addEventListener("sourcechangerequested", receiver_SourceChangeRequested);
            receiver.addEventListener("stoprequested", receiver_StopRequested);
            receiver.addEventListener("timeupdaterequested", receiver_TimeUpdateRequested);
            receiver.addEventListener("volumechangerequested", receiver_VolumeChangeRequested);
    
            receiver.friendlyName = "Sample Play To Receiver";
            receiver.supportsAudio = false;
            receiver.supportsVideo = true;
            receiver.supportsImage = false;
    
            // Add MediaElement events
            videoPlayer = document.getElementById("videoPlayer");
            videoPlayer.addEventListener("durationchange",videoPlayer_DurationChange); 
            videoPlayer.addEventListener("ended", videoPlayer_Ended); 
            videoPlayer.addEventListener("error", videoPlayer_Error);
            videoPlayer.addEventListener("loadedmetadata", videoPlayer_LoadedMetadata); 
            videoPlayer.addEventListener("pause", videoPlayer_Pause); 
            videoPlayer.addEventListener("playing", videoPlayer_Playing); 
            videoPlayer.addEventListener("ratechange", videoPlayer_RateChange); 
            videoPlayer.addEventListener("seeked", videoPlayer_Seeked); 
            videoPlayer.addEventListener("seeking", videoPlayer_Seeking); 
            videoPlayer.addEventListener("volumechange", videoPlayer_VolumeChange); 
    
            // Advertise the receiver on the local network and start receiving commands
            receiver.startAsync().done(function () {
                // Prevent the screen from locking
                if (display == null) {
                    display = new Windows.System.Display.DisplayRequest();
                }
                display.requestActive();
    
                statusDiv.innerHTML = "'" + receiver.friendlyName + "' started.";
            });
    
    
        }
        catch(e) {
            receiver = null;
            statusDiv.innerHTML = "Failed to start receiver.";
        }
    }
    
    function stopReceiverButton_Click(e) {
        try {
            if (receiver != null) {
                receiver.stopAsync().done(function() {
                    if (display != null)
                        display.requestRelease();
    
                    // Remove Play To Receiver events
                    receiver.removeEventListener("currenttimechangerequested", receiver_CurrentTimeChangeRequested);
                    receiver.removeEventListener("mutechangerequested", receiver_MuteChangeRequested);
                    receiver.removeEventListener("pauserequested", receiver_PauseRequested);
                    receiver.removeEventListener("playbackratechangerequested", receiver_PlaybackRateChangeRequested);
                    receiver.removeEventListener("playrequested", receiver_PlayRequested);
                    receiver.removeEventListener("sourcechangerequested", receiver_SourceChangeRequested);
                    receiver.removeEventListener("stoprequested", receiver_StopRequested);
                    receiver.removeEventListener("timeupdaterequested", receiver_TimeUpdateRequested);
                    receiver.removeEventListener("volumechangerequested", receiver_VolumeChangeRequested);
    
                    //  Remove MediaElement events
                    videoPlayer = document.getElementById("videoPlayer");
                    if (videoPlayer.readyState != 0) {
                        videoPlayer.pause();
                        videoPlayer.currentTime = 0;
                    }
    
                    videoPlayer.removeEventListener("durationchange",videoPlayer_DurationChange); 
                    videoPlayer.removeEventListener("ended", videoPlayer_Ended); 
                    videoPlayer.removeEventListener("error", videoPlayer_Error);
                    videoPlayer.removeEventListener("loadedmetadata", videoPlayer_LoadedMetadata); 
                    videoPlayer.removeEventListener("pause", videoPlayer_Pause); 
                    videoPlayer.removeEventListener("playing", videoPlayer_Playing); 
                    videoPlayer.removeEventListener("ratechange", videoPlayer_RateChange); 
                    videoPlayer.removeEventListener("seeked", videoPlayer_Seeked); 
                    videoPlayer.removeEventListener("seeking", videoPlayer_Seeking); 
                    videoPlayer.removeEventListener("volumechange", videoPlayer_VolumeChange); 
    
                    statusDiv.innerHTML = "Stopped receiver.";
                });
            }
        }
        catch (e) {
            statusDiv.innerHTML = "Failed to stop '" + receiver.FriendlyName + "'.";
        }
    }
    
    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
    

Properties

  • FriendlyName
    FriendlyName
    FriendlyName
    FriendlyName

    Gets or sets the display name of the Play To target.

    public string FriendlyName { get; set; }public string FriendlyName { get; set; }Public ReadWrite Property FriendlyName As stringpublic string FriendlyName { get; set; }

    Property Value

    • string
      string
      string
      string

      The display name of the Play To target.

  • Properties
    Properties
    Properties
    Properties

    Gets a set of custom properties for the Play To receiver.

    public IPropertySet Properties { get; }public IPropertySet Properties { get; }Public ReadOnly Property Properties As IPropertySetpublic IPropertySet Properties { get; }

    Property Value

  • SupportsAudio
    SupportsAudio
    SupportsAudio
    SupportsAudio

    Gets or sets a value that indicates whether the Play To target supports audio.

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

    Property Value

    • bool
      bool
      bool
      bool

      True if the Play To target supports audio; otherwise false.

  • SupportsImage
    SupportsImage
    SupportsImage
    SupportsImage

    Gets or sets a value that indicates whether the Play To target supports images.

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

    Property Value

    • bool
      bool
      bool
      bool

      True if the Play To target supports images; otherwise false.

  • SupportsVideo
    SupportsVideo
    SupportsVideo
    SupportsVideo

    Gets or sets a value that indicates whether the Play To target supports video.

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

    Property Value

    • bool
      bool
      bool
      bool

      True if the Play To target supports video; otherwise false.

Methods

  • NotifyDurationChange(TimeSpan)
    NotifyDurationChange(TimeSpan)
    NotifyDurationChange(TimeSpan)
    NotifyDurationChange(TimeSpan)

    Notifies the Play To receiver that the duration of the audio or video playback has changed.

    public void NotifyDurationChange(TimeSpan duration)public void NotifyDurationChange(TimeSpan duration)Public Function NotifyDurationChange(duration As TimeSpan) As voidpublic void NotifyDurationChange(TimeSpan duration)

    Parameters

    Remarks

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

    void VideoPlayer_MediaOpened(object sender, RoutedEventArgs e)
    {
        if (receiver != null)
        {
            receiver.NotifyDurationChange(VideoPlayer.NaturalDuration.TimeSpan);
            receiver.NotifyLoadedMetadata();
        }
    }
    
    function videoPlayer_DurationChange() {
        if (videoPlayer.duration !== Infinity)
        {
            receiver.notifyDurationChange(videoPlayer.duration * 1000);
        }
    }
    
    function videoPlayer_LoadedMetadata () { 
        receiver.notifyLoadedMetadata(); 
    }
    
    Sub VideoPlayer_MediaOpened()
        If receiver IsNot Nothing Then
            receiver.NotifyDurationChange(VideoPlayer.NaturalDuration.TimeSpan)
            receiver.NotifyLoadedMetadata()
        End If
    End Sub
    
  • NotifyEnded()
    NotifyEnded()
    NotifyEnded()
    NotifyEnded()

    Notifies the Play To receiver that the audio or video playback has ended.

    public void NotifyEnded()public void NotifyEnded()Public Function NotifyEnded() As voidpublic void NotifyEnded()

    Remarks

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

    void VideoPlayer_MediaEnded(object sender, RoutedEventArgs e)
    {
        if (receiver != null)
        {
            receiver.NotifyEnded();
            VideoPlayer.Stop();
        }
    }
    
    function videoPlayer_Ended () { 
        receiver.notifyEnded(); 
    }
    
    Sub VideoPlayer_MediaEnded()
        If receiver IsNot Nothing Then
            receiver.NotifyEnded()
            VideoPlayer.Stop()
        End If
    End Sub
    
  • NotifyError()
    NotifyError()
    NotifyError()
    NotifyError()

    Notifies the Play To receiver that an error has occurred in displaying or playing the media.

    public void NotifyError()public void NotifyError()Public Function NotifyError() As voidpublic void NotifyError()

    Remarks

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

    void VideoPlayer_CurrentStateChanged(object sender, RoutedEventArgs e)
    {
        if (receiver != null)
        {
            switch (VideoPlayer.CurrentState)
            {
                case MediaElementState.Playing:
                    receiver.NotifyPlaying();
                    break;
                case MediaElementState.Paused:
                    receiver.NotifyPaused();
                    break;
                case MediaElementState.Stopped:
                    receiver.NotifyStopped();
                    break;
            }
        }
    }
    
    void VideoPlayer_MediaFailed(object sender, ExceptionRoutedEventArgs e)
    {
        if (receiver != null) { receiver.NotifyError(); }
    }
    
    function videoPlayer_Error() {
        receiver.notifyError();
        receiver.notifyStopped();
    }
    
    function videoPlayer_Pause () { 
        receiver.notifyPaused(); 
    }
    
    function videoPlayer_Playing () { 
        receiver.notifyPlaying(); 
    }
    
    Sub VideoPlayer_CurrentStateChanged()
    
        If receiver IsNot Nothing Then
            Select Case VideoPlayer.CurrentState
                Case MediaElementState.Playing
                    receiver.NotifyPlaying()
                Case MediaElementState.Paused
                    receiver.NotifyPaused()
                Case MediaElementState.Stopped
                    receiver.NotifyStopped()
            End Select
        End If
    End Sub
    
    Sub VideoPlayer_MediaFailed()
        If receiver IsNot Nothing Then receiver.NotifyError()
    End Sub
    
  • NotifyLoadedMetadata()
    NotifyLoadedMetadata()
    NotifyLoadedMetadata()
    NotifyLoadedMetadata()

    Notifies the Play To receiver that metadata for the media has finished loading.

    public void NotifyLoadedMetadata()public void NotifyLoadedMetadata()Public Function NotifyLoadedMetadata() As voidpublic void NotifyLoadedMetadata()

    Remarks

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

    void VideoPlayer_MediaOpened(object sender, RoutedEventArgs e)
    {
        if (receiver != null)
        {
            receiver.NotifyDurationChange(VideoPlayer.NaturalDuration.TimeSpan);
            receiver.NotifyLoadedMetadata();
        }
    }
    
    function videoPlayer_DurationChange() {
        if (videoPlayer.duration !== Infinity)
        {
            receiver.notifyDurationChange(videoPlayer.duration * 1000);
        }
    }
    
    function videoPlayer_LoadedMetadata () { 
        receiver.notifyLoadedMetadata(); 
    }
    
    Sub VideoPlayer_MediaOpened()
        If receiver IsNot Nothing Then
            receiver.NotifyDurationChange(VideoPlayer.NaturalDuration.TimeSpan)
            receiver.NotifyLoadedMetadata()
        End If
    End Sub
    
  • NotifyPaused()
    NotifyPaused()
    NotifyPaused()
    NotifyPaused()

    Notifies the Play To receiver that the audio or video playback has been paused.

    public void NotifyPaused()public void NotifyPaused()Public Function NotifyPaused() As voidpublic void NotifyPaused()

    Remarks

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

    void VideoPlayer_CurrentStateChanged(object sender, RoutedEventArgs e)
    {
        if (receiver != null)
        {
            switch (VideoPlayer.CurrentState)
            {
                case MediaElementState.Playing:
                    receiver.NotifyPlaying();
                    break;
                case MediaElementState.Paused:
                    receiver.NotifyPaused();
                    break;
                case MediaElementState.Stopped:
                    receiver.NotifyStopped();
                    break;
            }
        }
    }
    
    void VideoPlayer_MediaFailed(object sender, ExceptionRoutedEventArgs e)
    {
        if (receiver != null) { receiver.NotifyError(); }
    }
    
    function videoPlayer_Error() {
        receiver.notifyError();
        receiver.notifyStopped();
    }
    
    function videoPlayer_Pause () { 
        receiver.notifyPaused(); 
    }
    
    function videoPlayer_Playing () { 
        receiver.notifyPlaying(); 
    }
    
    Sub VideoPlayer_CurrentStateChanged()
    
        If receiver IsNot Nothing Then
            Select Case VideoPlayer.CurrentState
                Case MediaElementState.Playing
                    receiver.NotifyPlaying()
                Case MediaElementState.Paused
                    receiver.NotifyPaused()
                Case MediaElementState.Stopped
                    receiver.NotifyStopped()
            End Select
        End If
    End Sub
    
    Sub VideoPlayer_MediaFailed()
        If receiver IsNot Nothing Then receiver.NotifyError()
    End Sub
    
  • NotifyPlaying()
    NotifyPlaying()
    NotifyPlaying()
    NotifyPlaying()

    Notifies the Play To receiver that the audio or video playback has started.

    public void NotifyPlaying()public void NotifyPlaying()Public Function NotifyPlaying() As voidpublic void NotifyPlaying()

    Remarks

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

    void VideoPlayer_CurrentStateChanged(object sender, RoutedEventArgs e)
    {
        if (receiver != null)
        {
            switch (VideoPlayer.CurrentState)
            {
                case MediaElementState.Playing:
                    receiver.NotifyPlaying();
                    break;
                case MediaElementState.Paused:
                    receiver.NotifyPaused();
                    break;
                case MediaElementState.Stopped:
                    receiver.NotifyStopped();
                    break;
            }
        }
    }
    
    void VideoPlayer_MediaFailed(object sender, ExceptionRoutedEventArgs e)
    {
        if (receiver != null) { receiver.NotifyError(); }
    }
    
    function videoPlayer_Error() {
        receiver.notifyError();
        receiver.notifyStopped();
    }
    
    function videoPlayer_Pause () { 
        receiver.notifyPaused(); 
    }
    
    function videoPlayer_Playing () { 
        receiver.notifyPlaying(); 
    }
    
    Sub VideoPlayer_CurrentStateChanged()
    
        If receiver IsNot Nothing Then
            Select Case VideoPlayer.CurrentState
                Case MediaElementState.Playing
                    receiver.NotifyPlaying()
                Case MediaElementState.Paused
                    receiver.NotifyPaused()
                Case MediaElementState.Stopped
                    receiver.NotifyStopped()
            End Select
        End If
    End Sub
    
    Sub VideoPlayer_MediaFailed()
        If receiver IsNot Nothing Then receiver.NotifyError()
    End Sub
    
  • NotifyRateChange(Double)
    NotifyRateChange(Double)
    NotifyRateChange(Double)
    NotifyRateChange(Double)

    Notifies the Play To receiver that the rate of the audio or video playback has changed.

    public void NotifyRateChange(Double rate)public void NotifyRateChange(Double rate)Public Function NotifyRateChange(rate As Double) As voidpublic void NotifyRateChange(Double rate)

    Parameters

    • rate
      System.Double
      System.Double
      System.Double
      System.Double

      The new value of the playback rate.

    Remarks

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

    void VideoPlayer_RateChanged(object sender, RateChangedRoutedEventArgs e)
    {
        if (receiver != null)
            receiver.NotifyRateChange(VideoPlayer.PlaybackRate);
    }
    
    function videoPlayer_RateChange () { 
        receiver.notifyRateChange(videoPlayer.playbackRate); 
    }
    
    Sub VideoPlayer_RateChanged()
        If receiver IsNot Nothing Then
            receiver.NotifyRateChange(VideoPlayer.PlaybackRate)
        End If
    End Sub
    
  • NotifySeeked()
    NotifySeeked()
    NotifySeeked()
    NotifySeeked()

    Notifies the Play To receiver that the audio or video playback element has started at a new playback location.

    public void NotifySeeked()public void NotifySeeked()Public Function NotifySeeked() As voidpublic void NotifySeeked()

    Remarks

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

    void VideoPlayer_SeekCompleted(object sender, RoutedEventArgs e)
    {
        if (receiver != null)
        {
            if (!seeking)
                receiver.NotifySeeking();
            receiver.NotifySeeked();
            seeking = false;
        }
    }
    
    function videoPlayer_Seeked () { 
        receiver.notifySeeked(); 
    }
    
    function videoPlayer_Seeking () { 
        receiver.notifySeeking(); 
    }
    
    Sub VideoPlayer_SeekCompleted()
        If receiver IsNot Nothing Then
            If Not seeking Then
                receiver.NotifySeeking()
                receiver.NotifySeeked()
                seeking = False
            End If
        End If
    End Sub
    
  • NotifySeeking()
    NotifySeeking()
    NotifySeeking()
    NotifySeeking()

    Notifies the Play To receiver that the audio or video playback element is seeking a new playback location.

    public void NotifySeeking()public void NotifySeeking()Public Function NotifySeeking() As voidpublic void NotifySeeking()

    Remarks

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

    void VideoPlayer_SeekCompleted(object sender, RoutedEventArgs e)
    {
        if (receiver != null)
        {
            if (!seeking)
                receiver.NotifySeeking();
            receiver.NotifySeeked();
            seeking = false;
        }
    }
    
    function videoPlayer_Seeked () { 
        receiver.notifySeeked(); 
    }
    
    function videoPlayer_Seeking () { 
        receiver.notifySeeking(); 
    }
    
    Sub VideoPlayer_SeekCompleted()
        If receiver IsNot Nothing Then
            If Not seeking Then
                receiver.NotifySeeking()
                receiver.NotifySeeked()
                seeking = False
            End If
        End If
    End Sub
    
  • NotifyStopped()
    NotifyStopped()
    NotifyStopped()
    NotifyStopped()

    Notifies the Play To receiver that the audio or video playback has stopped.

    public void NotifyStopped()public void NotifyStopped()Public Function NotifyStopped() As voidpublic void NotifyStopped()

    Remarks

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

    void VideoPlayer_CurrentStateChanged(object sender, RoutedEventArgs e)
    {
        if (receiver != null)
        {
            switch (VideoPlayer.CurrentState)
            {
                case MediaElementState.Playing:
                    receiver.NotifyPlaying();
                    break;
                case MediaElementState.Paused:
                    receiver.NotifyPaused();
                    break;
                case MediaElementState.Stopped:
                    receiver.NotifyStopped();
                    break;
            }
        }
    }
    
    void VideoPlayer_MediaFailed(object sender, ExceptionRoutedEventArgs e)
    {
        if (receiver != null) { receiver.NotifyError(); }
    }
    
    function videoPlayer_Error() {
        receiver.notifyError();
        receiver.notifyStopped();
    }
    
    function videoPlayer_Pause () { 
        receiver.notifyPaused(); 
    }
    
    function videoPlayer_Playing () { 
        receiver.notifyPlaying(); 
    }
    
    Sub VideoPlayer_CurrentStateChanged()
    
        If receiver IsNot Nothing Then
            Select Case VideoPlayer.CurrentState
                Case MediaElementState.Playing
                    receiver.NotifyPlaying()
                Case MediaElementState.Paused
                    receiver.NotifyPaused()
                Case MediaElementState.Stopped
                    receiver.NotifyStopped()
            End Select
        End If
    End Sub
    
    Sub VideoPlayer_MediaFailed()
        If receiver IsNot Nothing Then receiver.NotifyError()
    End Sub
    
  • NotifyTimeUpdate(TimeSpan)
    NotifyTimeUpdate(TimeSpan)
    NotifyTimeUpdate(TimeSpan)
    NotifyTimeUpdate(TimeSpan)

    Notifies the Play To receiver that the time location of the audio or video playback has changed.

    public void NotifyTimeUpdate(TimeSpan currentTime)public void NotifyTimeUpdate(TimeSpan currentTime)Public Function NotifyTimeUpdate(currentTime As TimeSpan) As voidpublic void NotifyTimeUpdate(TimeSpan currentTime)

    Parameters

    Remarks

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

    async void receiver_TimeUpdateRequested(
        Windows.Media.PlayTo.PlayToReceiver sender,
        object args)
    {
        await dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                if (VideoPlayer.Position != null)
                    receiver.NotifyTimeUpdate(VideoPlayer.Position);
            });
    }
    
    function receiver_TimeUpdateRequested() {
        receiver.notifyTimeUpdate(videoPlayer.currentTime * 1000);
    }
    
    Async Sub receiver_TimeUpdateRequested(
        sender As Windows.Media.PlayTo.PlayToReceiver,
        args As Object)
    
        Await Dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
                receiver.NotifyTimeUpdate(VideoPlayer.Position)
            End Sub)
    End Sub
    
  • NotifyVolumeChange(Double, Boolean)
    NotifyVolumeChange(Double, Boolean)
    NotifyVolumeChange(Double, Boolean)
    NotifyVolumeChange(Double, Boolean)

    Notifies the Play To receiver that the volume of the audio or video playback has changed.

    public void NotifyVolumeChange(Double volume, Boolean mute)public void NotifyVolumeChange(Double volume, Boolean mute)Public Function NotifyVolumeChange(volume As Double, mute As Boolean) As voidpublic void NotifyVolumeChange(Double volume, Boolean mute)

    Parameters

    • volume
      System.Double
      System.Double
      System.Double
      System.Double

      The new value for the volume.

    • mute
      System.Boolean
      System.Boolean
      System.Boolean
      System.Boolean

      True if the volume was muted; otherwise false.

    Remarks

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

    void VideoPlayer_VolumeChanged(object sender, RoutedEventArgs e)
    {
        if (receiver != null)
            receiver.NotifyVolumeChange(VideoPlayer.Volume, VideoPlayer.IsMuted);
    }
    
    function videoPlayer_VolumeChange() {
        receiver.notifyVolumeChange(videoPlayer.volume, videoPlayer.muted);
    }
    
    Sub VideoPlayer_VolumeChanged()
        If receiver IsNot Nothing Then
            receiver.NotifyVolumeChange(VideoPlayer.Volume, VideoPlayer.IsMuted)
        End If
    End Sub
    
  • StartAsync()
    StartAsync()
    StartAsync()
    StartAsync()

    Start receiving Play To commands.

    public IAsyncAction StartAsync()public IAsyncAction StartAsync()Public Function StartAsync() As IAsyncActionpublic IAsyncAction StartAsync()

    Returns

    Remarks

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

    // Advertise the receiver on the local network and start receiving commands
    await receiver.StartAsync();
    
    // Prevent the screen from locking
    if (display == null)
        display = new Windows.System.Display.DisplayRequest();
    display.RequestActive();
    
    StatusTextBlock.Text = "'" + receiver.FriendlyName + "' started.";
    
    // Advertise the receiver on the local network and start receiving commands
    receiver.startAsync().done(function () {
        // Prevent the screen from locking
        if (display == null) {
            display = new Windows.System.Display.DisplayRequest();
        }
        display.requestActive();
    
        statusDiv.innerHTML = "'" + receiver.friendlyName + "' started.";
    });
    
    ' 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
    
  • StopAsync()
    StopAsync()
    StopAsync()
    StopAsync()

    Stop receiving Play To commands.

    public IAsyncAction StopAsync()public IAsyncAction StopAsync()Public Function StopAsync() As IAsyncActionpublic IAsyncAction StopAsync()

    Returns

    Remarks

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

    if (receiver != null)
    {
        await receiver.StopAsync();
    
        if (display != null)
            display.RequestRelease();
    
        // Remove Play To Receiver events
        receiver.CurrentTimeChangeRequested -= receiver_CurrentTimeChangeRequested;
        receiver.MuteChangeRequested -= receiver_MuteChangeRequested;
        receiver.PauseRequested -= receiver_PauseRequested;
        receiver.PlaybackRateChangeRequested -= receiver_PlaybackRateChangeRequested;
        receiver.PlayRequested -= receiver_PlayRequested;
        receiver.SourceChangeRequested -= receiver_SourceChangeRequested;
        receiver.StopRequested -= receiver_StopRequested;
        receiver.TimeUpdateRequested -= receiver_TimeUpdateRequested;
        receiver.VolumeChangeRequested -= receiver_VolumeChangeRequested;
    
        //  Remove MediaElement events
        VideoPlayer.Pause();
    
        VideoPlayer.CurrentStateChanged -= VideoPlayer_CurrentStateChanged;
        VideoPlayer.MediaEnded -= VideoPlayer_MediaEnded;
        VideoPlayer.MediaFailed -= VideoPlayer_MediaFailed;
        VideoPlayer.MediaOpened -= VideoPlayer_MediaOpened;
        VideoPlayer.RateChanged -= VideoPlayer_RateChanged;
        VideoPlayer.SeekCompleted -= VideoPlayer_SeekCompleted;
        VideoPlayer.VolumeChanged -= VideoPlayer_VolumeChanged;
    
        StatusTextBlock.Text = "Stopped '" + receiver.FriendlyName + "'.";
    }
    
    if (receiver != null) {
        receiver.stopAsync().done(function() {
            if (display != null)
                display.requestRelease();
    
            // Remove Play To Receiver events
            receiver.removeEventListener("currenttimechangerequested", receiver_CurrentTimeChangeRequested);
            receiver.removeEventListener("mutechangerequested", receiver_MuteChangeRequested);
            receiver.removeEventListener("pauserequested", receiver_PauseRequested);
            receiver.removeEventListener("playbackratechangerequested", receiver_PlaybackRateChangeRequested);
            receiver.removeEventListener("playrequested", receiver_PlayRequested);
            receiver.removeEventListener("sourcechangerequested", receiver_SourceChangeRequested);
            receiver.removeEventListener("stoprequested", receiver_StopRequested);
            receiver.removeEventListener("timeupdaterequested", receiver_TimeUpdateRequested);
            receiver.removeEventListener("volumechangerequested", receiver_VolumeChangeRequested);
    
            //  Remove MediaElement events
            videoPlayer = document.getElementById("videoPlayer");
            if (videoPlayer.readyState != 0) {
                videoPlayer.pause();
                videoPlayer.currentTime = 0;
            }
    
            videoPlayer.removeEventListener("durationchange",videoPlayer_DurationChange); 
            videoPlayer.removeEventListener("ended", videoPlayer_Ended); 
            videoPlayer.removeEventListener("error", videoPlayer_Error);
            videoPlayer.removeEventListener("loadedmetadata", videoPlayer_LoadedMetadata); 
            videoPlayer.removeEventListener("pause", videoPlayer_Pause); 
            videoPlayer.removeEventListener("playing", videoPlayer_Playing); 
            videoPlayer.removeEventListener("ratechange", videoPlayer_RateChange); 
            videoPlayer.removeEventListener("seeked", videoPlayer_Seeked); 
            videoPlayer.removeEventListener("seeking", videoPlayer_Seeking); 
            videoPlayer.removeEventListener("volumechange", videoPlayer_VolumeChange); 
    
            statusDiv.innerHTML = "Stopped receiver.";
        });
    }
    
    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
    

Events

  • CurrentTimeChangeRequested
    CurrentTimeChangeRequested
    CurrentTimeChangeRequested
    CurrentTimeChangeRequested

    Occurs when the time location of the playback has changed.

    public event TypedEventHandler CurrentTimeChangeRequestedpublic event TypedEventHandler CurrentTimeChangeRequestedPublic Event CurrentTimeChangeRequestedpublic event TypedEventHandler CurrentTimeChangeRequested

    Remarks

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

    async void receiver_CurrentTimeChangeRequested(
        Windows.Media.PlayTo.PlayToReceiver sender,
        Windows.Media.PlayTo.CurrentTimeChangeRequestedEventArgs args)
    {
        await dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                VideoPlayer.Position = args.Time;
                receiver.NotifySeeking();
                seeking = true;
            });
    }
    
    function receiver_CurrentTimeChangeRequested(args) {
        if (videoPlayer.currentTime !== 0 || args.time !== 0) {
            videoPlayer.currentTime = args.time / 1000;
        }
    }
    
    Async Sub receiver_CurrentTimeChangeRequested(
        sender As Windows.Media.PlayTo.PlayToReceiver,
        args As Windows.Media.PlayTo.CurrentTimeChangeRequestedEventArgs)
        Await Dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
                VideoPlayer.Position = args.Time
                receiver.NotifySeeking()
                seeking = True
            End Sub)
    End Sub
    
  • MuteChangeRequested
    MuteChangeRequested
    MuteChangeRequested
    MuteChangeRequested

    Occurs when the audio has been muted or unmuted.

    public event TypedEventHandler MuteChangeRequestedpublic event TypedEventHandler MuteChangeRequestedPublic Event MuteChangeRequestedpublic event TypedEventHandler MuteChangeRequested

    Remarks

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

    async void receiver_MuteChangeRequested(
        Windows.Media.PlayTo.PlayToReceiver sender,
        Windows.Media.PlayTo.MuteChangeRequestedEventArgs args)
    {
        await dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                VideoPlayer.IsMuted = args.Mute;
            });
    }
    
    function receiver_MuteChangeRequested(args) {
        videoPlayer.muted = args.mute;
    }
    
    Async Sub receiver_MuteChangeRequested(
        sender As Windows.Media.PlayTo.PlayToReceiver,
        args As Windows.Media.PlayTo.MuteChangeRequestedEventArgs)
        Await Dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
                VideoPlayer.IsMuted = args.Mute
            End Sub)
    End Sub
    
  • PauseRequested
    PauseRequested
    PauseRequested
    PauseRequested

    Occurs when audio or video playback has been paused.

    public event TypedEventHandler PauseRequestedpublic event TypedEventHandler PauseRequestedPublic Event PauseRequestedpublic event TypedEventHandler PauseRequested

    Remarks

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

    async void receiver_PauseRequested(
        Windows.Media.PlayTo.PlayToReceiver sender,
        object args)
    {
        await dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                VideoPlayer.Pause();
            });
    }
    
    function receiver_PauseRequested() {
        videoPlayer.pause();
    }
    
    
    Async Sub receiver_PauseRequested(
        sender As Windows.Media.PlayTo.PlayToReceiver,
        args As Object)
    
        Await Dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
                VideoPlayer.Pause()
            End Sub)
    End Sub
    
  • PlaybackRateChangeRequested
    PlaybackRateChangeRequested
    PlaybackRateChangeRequested
    PlaybackRateChangeRequested

    Occurs when the rate of audio or video playback has changed.

    public event TypedEventHandler PlaybackRateChangeRequestedpublic event TypedEventHandler PlaybackRateChangeRequestedPublic Event PlaybackRateChangeRequestedpublic event TypedEventHandler PlaybackRateChangeRequested

    Remarks

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

    async void receiver_PlaybackRateChangeRequested(
        Windows.Media.PlayTo.PlayToReceiver sender,
        Windows.Media.PlayTo.PlaybackRateChangeRequestedEventArgs args)
    {
        await dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                VideoPlayer.PlaybackRate = args.Rate;
            });
    }
    
    function receiver_PlaybackRateChangeRequested(args) {
        videoPlayer.playbackRate = args.rate;
    }
    
    Async Sub receiver_PlaybackRateChangeRequested(
        sender As Windows.Media.PlayTo.PlayToReceiver,
        args As Windows.Media.PlayTo.PlaybackRateChangeRequestedEventArgs)
    
        Await Dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
                VideoPlayer.PlaybackRate = args.Rate
            End Sub)
    End Sub
    
  • PlayRequested
    PlayRequested
    PlayRequested
    PlayRequested

    Occurs when audio or video playback starts.

    public event TypedEventHandler PlayRequestedpublic event TypedEventHandler PlayRequestedPublic Event PlayRequestedpublic event TypedEventHandler PlayRequested

    Remarks

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

    async void receiver_PlayRequested(
        Windows.Media.PlayTo.PlayToReceiver sender,
        object args)
    {
        await dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                VideoPlayer.Play();
            });
    }
    
    function receiver_PlayRequested() {
        videoPlayer.play();
    }
    
    Async Sub receiver_PlayRequested(
        sender As Windows.Media.PlayTo.PlayToReceiver,
        args As Object)
    
        Await Dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
                VideoPlayer.Play()
            End Sub)
    End Sub
    
  • SourceChangeRequested
    SourceChangeRequested
    SourceChangeRequested
    SourceChangeRequested

    Occurs when the source media for the Play To receiver have changed.

    public event TypedEventHandler SourceChangeRequestedpublic event TypedEventHandler SourceChangeRequestedPublic Event SourceChangeRequestedpublic event TypedEventHandler SourceChangeRequested

    Remarks

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

    async void receiver_SourceChangeRequested(
        Windows.Media.PlayTo.PlayToReceiver sender,
        Windows.Media.PlayTo.SourceChangeRequestedEventArgs args)
    {
        if (args.Stream != null)
            await dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
                {
                    var stream = args.Stream as Windows.Storage.Streams.IRandomAccessStream;
                    VideoPlayer.SetSource(stream, args.Stream.ContentType);
                });
    }
    
    function receiver_SourceChangeRequested(args) {
        if (args.stream != null) {
            var mediaStream = MSApp.createBlobFromRandomAccessStream(args.stream.contentType, args.stream);
            videoPlayer.src = URL.createObjectURL(mediaStream, false);
        }
    }
    
    Async Sub receiver_SourceChangeRequested(
        sender As Windows.Media.PlayTo.PlayToReceiver,
        args As Windows.Media.PlayTo.SourceChangeRequestedEventArgs)
    
        If args.Stream IsNot Nothing Then
            Await Dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal,
                Sub()
                    Dim stream = TryCast(args.Stream, Windows.Storage.Streams.IRandomAccessStream)
                    VideoPlayer.SetSource(stream, args.Stream.ContentType)
                End Sub)
        End If
    End Sub
    
  • StopRequested
    StopRequested
    StopRequested
    StopRequested

    Occurs when a request has been made for the Play To receiver to stop playing the streamed media.

    public event TypedEventHandler StopRequestedpublic event TypedEventHandler StopRequestedPublic Event StopRequestedpublic event TypedEventHandler StopRequested

    Remarks

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

    async void receiver_StopRequested(
        Windows.Media.PlayTo.PlayToReceiver sender,
        object args)
    {
        await dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                VideoPlayer.Stop();
            });
    }
    
    function receiver_StopRequested() {
        if (videoPlayer.readyState != 0) {
            videoPlayer.pause();
            videoPlayer.currentTime = 0;
        }
    }
    
    Async Sub receiver_StopRequested(
        sender As Windows.Media.PlayTo.PlayToReceiver,
        args As Object)
    
        Await Dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
    
                VideoPlayer.Stop()
            End Sub)
    End Sub
    
  • TimeUpdateRequested
    TimeUpdateRequested
    TimeUpdateRequested
    TimeUpdateRequested

    Occurs when the current playback position has changed.

    public event TypedEventHandler TimeUpdateRequestedpublic event TypedEventHandler TimeUpdateRequestedPublic Event TimeUpdateRequestedpublic event TypedEventHandler TimeUpdateRequested

    Remarks

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

    async void receiver_TimeUpdateRequested(
        Windows.Media.PlayTo.PlayToReceiver sender,
        object args)
    {
        await dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                if (VideoPlayer.Position != null)
                    receiver.NotifyTimeUpdate(VideoPlayer.Position);
            });
    }
    
    function receiver_TimeUpdateRequested() {
        receiver.notifyTimeUpdate(videoPlayer.currentTime * 1000);
    }
    
    Async Sub receiver_TimeUpdateRequested(
        sender As Windows.Media.PlayTo.PlayToReceiver,
        args As Object)
    
        Await Dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
                receiver.NotifyTimeUpdate(VideoPlayer.Position)
            End Sub)
    End Sub
    
  • VolumeChangeRequested
    VolumeChangeRequested
    VolumeChangeRequested
    VolumeChangeRequested

    Occurs when the volume for the source audio or video has changed.

    public event TypedEventHandler VolumeChangeRequestedpublic event TypedEventHandler VolumeChangeRequestedPublic Event VolumeChangeRequestedpublic event TypedEventHandler VolumeChangeRequested

    Remarks

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

    async void receiver_VolumeChangeRequested(
        Windows.Media.PlayTo.PlayToReceiver sender,
        Windows.Media.PlayTo.VolumeChangeRequestedEventArgs args)
    {
        await dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                VideoPlayer.Volume = args.Volume;
            });
    }
    
    function receiver_VolumeChangeRequested(args) {
        videoPlayer.volume = args.volume;
    }
    
    Async Sub receiver_VolumeChangeRequested(
        sender As Windows.Media.PlayTo.PlayToReceiver,
        args As Windows.Media.PlayTo.VolumeChangeRequestedEventArgs)
    
        Await Dispatcher.RunAsync(
            Windows.UI.Core.CoreDispatcherPriority.Normal,
            Sub()
                VideoPlayer.Volume = args.Volume
            End Sub)
    End Sub
    

Device family

Windows 10 (introduced v10.0.10240.0)

API contract

Windows.Foundation.UniversalApiContract (introduced v1)

Capabilities

privateNetworkClientServer ities privateNetworkClientServer

Attributes

Windows.Foundation.Metadata.ActivatableAttribute
Windows.Foundation.Metadata.ContractVersionAttribute
Windows.Foundation.Metadata.MarshalingBehaviorAttribute
Windows.Foundation.Metadata.ThreadingAttribute

Details

Assembly

Windows.Media.PlayTo.dll