Ejemplo n.º 1
0
        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;

                // <SnippetProperties>
                receiver.FriendlyName  = "Sample Play To Receiver";
                receiver.SupportsAudio = false;
                receiver.SupportsVideo = true;
                receiver.SupportsImage = false;
                // </SnippetProperties>

                // 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;

                // <SnippetStartAsync>
                // 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.";
                // </SnippetStartAsync>
            }
            catch
            {
                receiver             = null;
                StatusTextBlock.Text = "Failed to start receiver.";
            }
        }
Ejemplo n.º 2
0
        // </SnippetTimeUpdateRequested>

        // <SnippetVolumeChangeRequested>
        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;
            });
        }
Ejemplo n.º 3
0
        // </SnippetSourceChangeRequested>

        // <SnippetStopRequested>
        async void receiver_StopRequested(
            Windows.Media.PlayTo.PlayToReceiver sender,
            object args)
        {
            await dispatcher.RunAsync(
                Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
            {
                VideoPlayer.Stop();
            });
        }
Ejemplo n.º 4
0
        // </SnippetStartAndStop>

        // <SnippetReceiverEvents>
        // <SnippetCurrentTimeChangeRequested>
        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;
            });
        }
Ejemplo n.º 5
0
        // </SnippetStopRequested>

        // <SnippetTimeUpdateRequested>
        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);
                }
            });
        }
Ejemplo n.º 6
0
        // </SnippetPlayRequested>

        // <SnippetSourceChangeRequested>
        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);
                });
            }
        }