示例#1
0
 public MediaActionSet(MediaSource mediaSource, List <MediaAction> mediaActions)
 {
     if (mediaSource != null && mediaActions != null)
     {
         MovieMediaSource = mediaSource;
         MediaActions     = mediaActions;
         MediaScene       = MediaActions[0].MediaScene.CurrentScene;
     }
     else
     {
         throw new ArgumentNullException("MediaActionの値をnullにすることはできません。");
     }
 }
示例#2
0
        private async Task Init()
        {
            if (playerType == MediaActionPlayerType.Server)
            {
                //Bluetooth の準備
                btServer = new BTServer();
                await btServer.InitializeRfcommServer();
            }
            //シリアルとシーン切り替えの準備

            /*serial = new SerialUtil();
             * await serial.InitSerial();
             * await serial.SendData(new Scene(Scene.Scenes.Arabian, 7));*/
            previousScene = actions[0].MediaScene.CurrentScene;

            //await serial.SendData(new Scene(Scene.Scenes.Arabian, 7));
            mediaPlayerElement.MediaPlayer.PlaybackSession.PlaybackStateChanged += PlaybackSession_PlaybackStateChanged;
            isInitialized = true;
        }
示例#3
0
        private async void PlaybackSession_PlaybackStateChanged(Windows.Media.Playback.MediaPlaybackSession sender, object args)
        {
            if (!isMediaStarted)
            {
                if (sender.PlaybackState == Windows.Media.Playback.MediaPlaybackState.Playing)
                {
                    isMediaStarted = true;
                    await Task.Run(async() =>
                    {
                        await dispatcher.RunAsync(CoreDispatcherPriority.High, async() =>
                        {
                            var count = 0;
                            try
                            {
                                while (count < actions.Count && mediaPlayerElement.MediaPlayer.PlaybackSession.PlaybackState == Windows.Media.Playback.MediaPlaybackState.Playing)
                                {
                                    if (ct.IsCancellationRequested)
                                    {
                                        mediaPlayerElement.MediaPlayer.Pause();
                                        ct.ThrowIfCancellationRequested();
                                    }

                                    var mediaAction = actions[count];

                                    if (TimeSpan.Compare(mediaAction.MediaTimeSpan, mediaPlayerElement.MediaPlayer.PlaybackSession.Position) <= 0)
                                    {
                                        Debug.WriteLine("/Count: " + count.ToString() + " /Action: " + mediaAction.MediaScene.CurrentSequence);

                                        var serialTask = serial.SendData(mediaAction.MediaScene);
                                        if (playerType == MediaActionPlayerType.Server)
                                        {
                                            if (previousScene != mediaAction.MediaScene.CurrentScene)
                                            {
                                                previousScene = mediaAction.MediaScene.CurrentScene;
                                                var btTask    = btServer.SendMessage(mediaAction.MediaScene);
                                                while (!(serialTask.IsCompleted && btTask.IsCompleted))
                                                {
                                                    await Task.Delay(100);
                                                }
                                            }
                                            else
                                            {
                                                while (!serialTask.IsCompleted)
                                                {
                                                    await Task.Delay(100);
                                                }
                                            }
                                        }
                                        else
                                        {
                                            while (!serialTask.IsCompleted)
                                            {
                                                await Task.Delay(100);
                                            }
                                        }


                                        count++;
                                    }

                                    await Task.Delay(200);
                                }
                            }
                            catch (OperationCanceledException)
                            {
                                return;
                            }
                        });
                    });
                }
            }
            else
            {
                if (isMediaStarted && sender.PlaybackState != Windows.Media.Playback.MediaPlaybackState.Playing && sender.PlaybackState != Windows.Media.Playback.MediaPlaybackState.Buffering)
                {
                    IsPlaying      = false;
                    isMediaStarted = false;
                }
            }
        }