PlayToReceiver.PlayToReceiver constructor

Applies to Windows only

Creates a new instance of a Play To receiver.

Syntax


public PlayToReceiver()

Parameters

This constructor has no parameters.

Remarks

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


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 + "'.";
    }
}


Requirements

Minimum supported client

Windows 8

Minimum supported server

Windows Server 2012

Minimum supported phone

None supported

Namespace

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

Metadata

Windows.winmd

Capabilities

privateNetworkClientServer

See also

PlayToReceiver
Samples
Play To sample
PlayToReceiver sample
Media Server sample

 

 

Show:
© 2014 Microsoft