PlayToReceiver PlayToReceiver PlayToReceiver PlayToReceiver Class

Definition

Represents a Play To target.

public : sealed class PlayToReceiver : IPlayToReceiver
public sealed class PlayToReceiver : IPlayToReceiver
Public NotInheritable Class PlayToReceiver Implements IPlayToReceiver
var playToReceiver = new playToReceiver();
Attributes
Windows 10 requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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

PlayToReceiver() PlayToReceiver() PlayToReceiver() PlayToReceiver()

Creates a new instance of a Play To receiver.

public : PlayToReceiver()
public PlayToReceiver()
Public Sub New()
var playToReceiver = new playToReceiver();
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

Properties

FriendlyName FriendlyName FriendlyName FriendlyName

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

public : Platform::String FriendlyName { get; set; }
public string FriendlyName { get; set; }
Public ReadWrite Property FriendlyName As string
var string = playToReceiver.friendlyName;
playToReceiver.friendlyName = string;
Value
Platform::String string string string

The display name of the Play To target.

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer
See Also

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 IPropertySet
var iPropertySet = playToReceiver.properties;
Value
IPropertySet IPropertySet IPropertySet IPropertySet

A set of custom properties for the Play To receiver.

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer
See Also

SupportsAudio SupportsAudio SupportsAudio SupportsAudio

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

public : Platform::Boolean SupportsAudio { get; set; }
public bool SupportsAudio { get; set; }
Public ReadWrite Property SupportsAudio As bool
var bool = playToReceiver.supportsAudio;
playToReceiver.supportsAudio = bool;
Value
Platform::Boolean bool bool bool

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

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer
See Also

SupportsImage SupportsImage SupportsImage SupportsImage

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

public : Platform::Boolean SupportsImage { get; set; }
public bool SupportsImage { get; set; }
Public ReadWrite Property SupportsImage As bool
var bool = playToReceiver.supportsImage;
playToReceiver.supportsImage = bool;
Value
Platform::Boolean bool bool bool

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

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer
See Also

SupportsVideo SupportsVideo SupportsVideo SupportsVideo

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

public : Platform::Boolean SupportsVideo { get; set; }
public bool SupportsVideo { get; set; }
Public ReadWrite Property SupportsVideo As bool
var bool = playToReceiver.supportsVideo;
playToReceiver.supportsVideo = bool;
Value
Platform::Boolean bool bool bool

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

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer
See Also

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 void
playToReceiver.notifyDurationChange(duration);
Parameters
duration
TimeSpan TimeSpan TimeSpan TimeSpan

The new duration of the audio or video media.

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

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 void
playToReceiver.notifyEnded();
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

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 void
playToReceiver.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
See Also

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 void
playToReceiver.notifyLoadedMetadata();
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

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 void
playToReceiver.notifyPaused();
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

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 void
playToReceiver.notifyPlaying();
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

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 void
playToReceiver.notifyRateChange(rate);
Parameters
rate
double Double Double Double

The new value of the playback rate.

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

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 void
playToReceiver.notifySeeked();
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

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 void
playToReceiver.notifySeeking();
Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

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 void
playToReceiver.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
See Also

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 void
playToReceiver.notifyTimeUpdate(currentTime);
Parameters
currentTime
TimeSpan TimeSpan TimeSpan TimeSpan

The new time location of the playback.

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

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, bool mute)
public void NotifyVolumeChange(Double volume, Boolean mute)
Public Function NotifyVolumeChange(volume As Double, mute As Boolean) As void
playToReceiver.notifyVolumeChange(volume, mute);
Parameters
volume
double Double Double Double

The new value for the volume.

mute
bool Boolean Boolean Boolean

True if the volume was muted; otherwise false.

Additional features and requirements
Device family
Windows 10 (introduced v10.0.10240.0)
API contract
Windows.Foundation.UniversalApiContract (introduced v1)
Capabilities
privateNetworkClientServer

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
See Also

StartAsync() StartAsync() StartAsync() StartAsync()

Start receiving Play To commands.

public : IAsyncAction StartAsync()
public IAsyncAction StartAsync()
Public Function StartAsync() As IAsyncAction
Windows.Media.PlayTo.PlayToReceiver.startAsync().done( /* Your success and error handlers */ );
Returns

An asynchronous handler that's called when the start operation is complete.

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
See Also

StopAsync() StopAsync() StopAsync() StopAsync()

Stop receiving Play To commands.

public : IAsyncAction StopAsync()
public IAsyncAction StopAsync()
Public Function StopAsync() As IAsyncAction
Windows.Media.PlayTo.PlayToReceiver.stopAsync().done( /* Your success and error handlers */ );
Returns

An asynchronous handler that's called when the stop operation is complete.

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
See Also

Events

CurrentTimeChangeRequested CurrentTimeChangeRequested CurrentTimeChangeRequested CurrentTimeChangeRequested

Occurs when the time location of the playback has changed.

public : event TypedEventHandler CurrentTimeChangeRequested<PlayToReceiver, CurrentTimeChangeRequestedEventArgs>
public event TypedEventHandler CurrentTimeChangeRequested<PlayToReceiver, CurrentTimeChangeRequestedEventArgs>
Public Event TypedEventHandler CurrentTimeChangeRequested( Of ( Of PlayToReceiver ), ( Of CurrentTimeChangeRequestedEventArgs ))
function onCurrentTimeChangeRequested(eventArgs){/* Your code */}


playToReceiver.addEventListener("currentTimeChangeRequested", onCurrentTimeChangeRequested);
playToReceiver.removeEventListener("currentTimeChangeRequested", onCurrentTimeChangeRequested);

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
See Also

MuteChangeRequested MuteChangeRequested MuteChangeRequested MuteChangeRequested

Occurs when the audio has been muted or unmuted.

public : event TypedEventHandler MuteChangeRequested<PlayToReceiver, MuteChangeRequestedEventArgs>
public event TypedEventHandler MuteChangeRequested<PlayToReceiver, MuteChangeRequestedEventArgs>
Public Event TypedEventHandler MuteChangeRequested( Of ( Of PlayToReceiver ), ( Of MuteChangeRequestedEventArgs ))
function onMuteChangeRequested(eventArgs){/* Your code */}


playToReceiver.addEventListener("muteChangeRequested", onMuteChangeRequested);
playToReceiver.removeEventListener("muteChangeRequested", onMuteChangeRequested);

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
See Also

PauseRequested PauseRequested PauseRequested PauseRequested

Occurs when audio or video playback has been paused.

public : event TypedEventHandler PauseRequested<PlayToReceiver, object>
public event TypedEventHandler PauseRequested<PlayToReceiver, object>
Public Event TypedEventHandler PauseRequested( Of ( Of PlayToReceiver ), ( Of object ))
function onPauseRequested(eventArgs){/* Your code */}


playToReceiver.addEventListener("pauseRequested", onPauseRequested);
playToReceiver.removeEventListener("pauseRequested", onPauseRequested);

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
See Also

PlaybackRateChangeRequested PlaybackRateChangeRequested PlaybackRateChangeRequested PlaybackRateChangeRequested

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

public : event TypedEventHandler PlaybackRateChangeRequested<PlayToReceiver, PlaybackRateChangeRequestedEventArgs>
public event TypedEventHandler PlaybackRateChangeRequested<PlayToReceiver, PlaybackRateChangeRequestedEventArgs>
Public Event TypedEventHandler PlaybackRateChangeRequested( Of ( Of PlayToReceiver ), ( Of PlaybackRateChangeRequestedEventArgs ))
function onPlaybackRateChangeRequested(eventArgs){/* Your code */}


playToReceiver.addEventListener("playbackRateChangeRequested", onPlaybackRateChangeRequested);
playToReceiver.removeEventListener("playbackRateChangeRequested", onPlaybackRateChangeRequested);

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
See Also

PlayRequested PlayRequested PlayRequested PlayRequested

Occurs when audio or video playback starts.

public : event TypedEventHandler PlayRequested<PlayToReceiver, object>
public event TypedEventHandler PlayRequested<PlayToReceiver, object>
Public Event TypedEventHandler PlayRequested( Of ( Of PlayToReceiver ), ( Of object ))
function onPlayRequested(eventArgs){/* Your code */}


playToReceiver.addEventListener("playRequested", onPlayRequested);
playToReceiver.removeEventListener("playRequested", onPlayRequested);

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
See Also

SourceChangeRequested SourceChangeRequested SourceChangeRequested SourceChangeRequested

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

public : event TypedEventHandler SourceChangeRequested<PlayToReceiver, SourceChangeRequestedEventArgs>
public event TypedEventHandler SourceChangeRequested<PlayToReceiver, SourceChangeRequestedEventArgs>
Public Event TypedEventHandler SourceChangeRequested( Of ( Of PlayToReceiver ), ( Of SourceChangeRequestedEventArgs ))
function onSourceChangeRequested(eventArgs){/* Your code */}


playToReceiver.addEventListener("sourceChangeRequested", onSourceChangeRequested);
playToReceiver.removeEventListener("sourceChangeRequested", onSourceChangeRequested);

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
See Also

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 StopRequested<PlayToReceiver, object>
public event TypedEventHandler StopRequested<PlayToReceiver, object>
Public Event TypedEventHandler StopRequested( Of ( Of PlayToReceiver ), ( Of object ))
function onStopRequested(eventArgs){/* Your code */}


playToReceiver.addEventListener("stopRequested", onStopRequested);
playToReceiver.removeEventListener("stopRequested", onStopRequested);

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
See Also

TimeUpdateRequested TimeUpdateRequested TimeUpdateRequested TimeUpdateRequested

Occurs when the current playback position has changed.

public : event TypedEventHandler TimeUpdateRequested<PlayToReceiver, object>
public event TypedEventHandler TimeUpdateRequested<PlayToReceiver, object>
Public Event TypedEventHandler TimeUpdateRequested( Of ( Of PlayToReceiver ), ( Of object ))
function onTimeUpdateRequested(eventArgs){/* Your code */}


playToReceiver.addEventListener("timeUpdateRequested", onTimeUpdateRequested);
playToReceiver.removeEventListener("timeUpdateRequested", onTimeUpdateRequested);

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
See Also

VolumeChangeRequested VolumeChangeRequested VolumeChangeRequested VolumeChangeRequested

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

public : event TypedEventHandler VolumeChangeRequested<PlayToReceiver, VolumeChangeRequestedEventArgs>
public event TypedEventHandler VolumeChangeRequested<PlayToReceiver, VolumeChangeRequestedEventArgs>
Public Event TypedEventHandler VolumeChangeRequested( Of ( Of PlayToReceiver ), ( Of VolumeChangeRequestedEventArgs ))
function onVolumeChangeRequested(eventArgs){/* Your code */}


playToReceiver.addEventListener("volumeChangeRequested", onVolumeChangeRequested);
playToReceiver.removeEventListener("volumeChangeRequested", onVolumeChangeRequested);

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
See Also

See Also