private async Task StopVideo() { if (VideoElement.MediaState != MediaPlaybackState.Play) { return; } await VideoElement.Stop(); }
protected override void OnNavigatedFrom(NavigationEventArgs e) { base.OnNavigatedFrom(e); VideoElement.Stop(); _timer.Stop(); _timer.Tick -= UpdateVideoPosition; SystemNavigationManager.GetForCurrentView().BackRequested -= NavigateBackRequested; }
private void SetupVideo() { VideoElement.Source = new Uri(Settings.Default.VideoSource); VideoElement.MediaEnded += (sender, args) => { VideoElement.Stop(); PlayButton.Visibility = Visibility.Visible; _mainWindows.Show(); }; }
private async void Command_UnloadMedia(object sender, ExecutedRoutedEventArgs e) { //MediaPlayer.Stop(); await VideoElement.Stop(); await VideoElement.Close(); MediaLoaded = false; Position.Time = 0; }
private void ControllerViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { var property = typeof(TelloControllerViewModel).GetProperty(e.PropertyName); var value = property.GetValue(sender); Debug.WriteLine($"{nameof(ControllerViewModel_PropertyChanged)} - property '{e.PropertyName}', value '{value}'"); if (e.PropertyName == nameof(TelloControllerViewModel.IsVideoStreaming) && (bool)value) { VideoElement.Play(); } else { VideoElement.Stop(); } }
//返回按鍵,關閉聲音撥放計算 private void back_Click(object sender, RoutedEventArgs e) { times = 0; second = 0; unit = 0; action = 0; res[0] = 0; res[1] = 0; finish = 0; VideoElement.Stop(); GoodElement.Stop(); LeftNegativeElement.Stop(); LeftPositiveElement.Stop(); RightNegativeElement.Stop(); RightPositiveElement.Stop(); BGMusicElement.Stop(); this.NavigationService.Navigate(menu); }
private async Task ClearVideoElement(bool seek) { await Task.Run(async() => { await VideoElement.Stop(); Dispatcher.Invoke(() => { VideoElement.Position = new TimeSpan(0); VideoElement.Source = null; VideoElement.Dispose(); VideoElement = null; VideoElementBorder.Visibility = Visibility.Hidden; VideoElement = new Unosquare.FFME.MediaElement { IsMuted = true, LoadedBehavior = MediaState.Manual, Visibility = System.Windows.Visibility.Visible, }; VideoElement.MediaOpened += VideoElement_MediaOpened; VideoElement.MediaFailed += VideoElement_MediaFailed; VideoElement.MediaEnded += (sender, e) => { VideoElement.Position = TimeSpan.FromSeconds(0); }; if (seek) { VideoElement.SeekingStarted += (sender, e) => { }; VideoElement.SeekingEnded += (sender, e) => { if (!_videoPlay) { return; } PlayMedia(); }; } VideoElementBorder.Children.Add(VideoElement); }); }); }
//動作完成時,影片重複播放 private void ResetTime() { if (preTime != times) { VideoElement.Stop(); VideoElement.Play(); sec = 100; preTime = times; A.Value = 100; failSecond = 1; if (unit == 1 || unit == 2) { finish = 1; } else if (unit == 3 || unit == 4) { finish = 2; } else { finish = 0; } } }
private async Task SafelyRecreateVideoElement(bool showVideo) { await Task.Run(async() => { await VideoElement.Stop(); Dispatcher.Invoke(() => { VideoElement.Position = TimeSpan.Zero; VideoElement.Source = null; VideoElement.MediaOpened -= OnMediaOpened; VideoElement.MediaFailed -= OnMediaFailed; VideoElement.MediaEnded -= OnMediaEnded; VideoElement.SeekingStarted -= OnSeekingStarted; VideoElement.SeekingEnded -= OnSeekingEnded; //VideoElement.Dispose(); VideoElement = null; VideoElementBorder.Visibility = Visibility.Hidden; VideoElement = new Unosquare.FFME.MediaElement { IsMuted = true, LoadedBehavior = MediaPlaybackState.Manual, Visibility = Visibility.Visible, }; VideoElement.MediaOpened += OnMediaOpened; VideoElement.MediaFailed += OnMediaFailed; VideoElement.MediaEnded += OnMediaEnded; if (showVideo) { VideoElement.SeekingStarted += OnSeekingStarted; VideoElement.SeekingEnded += OnSeekingEnded; } VideoElementBorder.Children.Add(VideoElement); }); }); async void OnMediaOpened(object sender, MediaOpenedEventArgs e) { VideoElementBorder.Visibility = Visibility.Visible; if (!_videoPlay) { return; } await Task.Run(() => _waitAction?.Invoke()); if (VideoElement == null /* || VideoElement.IsDisposed*/) { return; } await VideoElement.Play(); VideoElement.Position = _position; } async void OnMediaFailed(object sender, MediaFailedEventArgs e) { VideoElementBorder.Visibility = Visibility.Hidden; //MsgBox.Show(this, e.ErrorException.ToString(), "不支持的视频格式", MessageBoxButton.OK, MessageBoxImage.Error); if (!_videoPlay) { return; } await SafelyRecreateVideoElement(false); PlayMedia(); } void OnMediaEnded(object sender, EventArgs e) { if (VideoElement == null /*|| VideoElement.IsDisposed*/) { return; } VideoElement.Position = TimeSpan.Zero; } void OnSeekingStarted(object sender, EventArgs e) { } void OnSeekingEnded(object sender, EventArgs e) { if (!_videoPlay) { return; } PlayMedia(); } }
private void Window_Closing(object sender, System.ComponentModel.CancelEventArgs e) { VideoElement.Stop(); }
void runtime_SkeletonFrameReady(object sender, SkeletonFrameReadyEventArgs e) { bool receivedData = false; using (SkeletonFrame SFrame = e.OpenSkeletonFrame()) { if (SFrame != null) { Skeleton[] FrameSkeletons = new Skeleton[SFrame.SkeletonArrayLength]; SFrame.CopySkeletonDataTo(FrameSkeletons); skeletons = new Skeleton[SFrame.SkeletonArrayLength]; SFrame.CopySkeletonDataTo(skeletons); // The image processing took too long. More than 2 frames behind. receivedData = true; } } if (receivedData) { Skeleton currentSkeleton = (from s in skeletons where s.TrackingState == SkeletonTrackingState.Tracked select s).FirstOrDefault(); if (currentSkeleton != null) { //取得骨架關節點 3D(X、Y、Z)座標值。 head = currentSkeleton.Joints[JointType.Head]; rightHand = currentSkeleton.Joints[JointType.HandRight]; leftHand = currentSkeleton.Joints[JointType.HandLeft]; leftShoulder = currentSkeleton.Joints[JointType.ShoulderLeft]; rightShoulder = currentSkeleton.Joints[JointType.ShoulderRight]; centerShoulder = currentSkeleton.Joints[JointType.ShoulderCenter]; leftAnkle = currentSkeleton.Joints[JointType.AnkleLeft]; rightAnkle = currentSkeleton.Joints[JointType.AnkleRight]; leftElbow = currentSkeleton.Joints[JointType.ElbowLeft]; rightElbow = currentSkeleton.Joints[JointType.ElbowRight]; leftFoot = currentSkeleton.Joints[JointType.FootLeft]; rightFoot = currentSkeleton.Joints[JointType.FootRight]; leftHip = currentSkeleton.Joints[JointType.HipLeft]; rightHip = currentSkeleton.Joints[JointType.HipRight]; centerHip = currentSkeleton.Joints[JointType.HipCenter]; leftKnee = currentSkeleton.Joints[JointType.KneeLeft]; rightKnee = currentSkeleton.Joints[JointType.KneeRight]; leftWrist = currentSkeleton.Joints[JointType.WristLeft]; rightWrist = currentSkeleton.Joints[JointType.WristRight]; spine = currentSkeleton.Joints[JointType.Spine]; //設定紅點座標 SetEllipsePosition(ellipseHead, head, false); SetEllipsePosition(ellipseLeftHand, leftHand, false); SetEllipsePosition(ellipseRightHand, rightHand, false); SetEllipsePosition(ellipseLeftFoot, leftFoot, false); SetEllipsePosition(ellipseRightFoot, rightFoot, false); SetEllipsePosition(ellipseLeftElbow, leftElbow, false); SetEllipsePosition(ellipseRightElbow, rightElbow, false); SetEllipsePosition(ellipseLeftAnkle, leftAnkle, false); SetEllipsePosition(ellipseRightAnkle, rightAnkle, false); SetEllipsePosition(ellipseLeftWrist, leftWrist, false); SetEllipsePosition(ellipseRightWrist, rightWrist, false); SetEllipsePosition(ellipseLeftShoulder, leftShoulder, false); SetEllipsePosition(ellipseRightShoulder, rightShoulder, false); SetEllipsePosition(ellipseLeftKnee, leftKnee, false); SetEllipsePosition(ellipseRightKnee, rightKnee, false); SetEllipsePosition(ellipseCenterShoulder, centerShoulder, false); SetEllipsePosition(ellipseLeftHip, leftHip, false); SetEllipsePosition(ellipseRightHip, rightHip, false); SetEllipsePosition(ellipseCenterHip, centerHip, false); SetEllipsePosition(ellipseSpine, spine, false); actiontime++; //設定頁面標籤內容 TimesLabel.Content = times; AllTimesLabel.Content = "5"; if (times == 0) { beforehour = Convert.ToInt32(DateTime.Now.ToString("hh")); beforemin = Convert.ToInt32(DateTime.Now.ToString("mm")); beforesec = Convert.ToInt32(DateTime.Now.ToString("ss")); } //當完成次數為5,改變動作與聲音 if (times == 5) { action++; afterhour = Convert.ToInt32(DateTime.Now.ToString("hh")); aftermin = Convert.ToInt32(DateTime.Now.ToString("mm")); aftersec = Convert.ToInt32(DateTime.Now.ToString("ss")); actiontime = (afterhour - beforehour) * 60 * 60 + (aftermin - beforemin) * 60 + (aftersec - beforesec); HttpGet(); actiontime = 0; wrongnumber = 0; differece = 0; totaldifferece = 0; if (action <= 2) { changeVoice(); } times = 0; } //判別單元 if (finish == 1) { if (AAction.handputdown(leftShoulder, leftHand, leftElbow, leftWrist, rightShoulder, rightHand, rightElbow, rightWrist)) { finish = 0; } } else if (finish == 2) { if (AAction.twoLeg(leftKnee, leftHip, rightKnee, rightHip)) { finish = 0; } } else if (finish == 0) { actionunit = unit; actionname = action; //判斷單元 if (unit == 1) { res = UAC.Unit1_Check(action, leftShoulder, rightShoulder, leftElbow, rightElbow); second = unit_1.SecondSet(); failSecond = unit_1.failSecondSet(); loadingSet(); preTime = times; times = unit_1.StartUnit1(action, times, centerShoulder, leftShoulder, rightShoulder, leftHand, rightHand, leftElbow, rightElbow, leftWrist, rightWrist); } if (unit == 2) { res = UAC.Unit2_Check(action, leftShoulder, rightShoulder, leftElbow, rightElbow); second = unit_2.SecondSet(); failSecond = unit_2.failSecondSet(); loadingSet(); preTime = times; times = unit_2.StartUnit2(action, times, centerShoulder, leftShoulder, rightShoulder, leftHand, rightHand, leftElbow, rightElbow, leftWrist, rightWrist, leftKnee, rightKnee); } if (unit == 3) { //a = UAC.Unit2_Check(action, leftShoulder, rightShoulder, leftElbow, rightElbow); failSecond = unit_3.failSecondSet(); loadingSet(); preTime = times; second = unit_3.SecondSet(); times = unit_3.StartUnit3(action, times, rightKnee, rightAnkle, rightHip, leftKnee, leftAnkle, leftHip); } if (unit == 4) { wrongnumber = unit_4.failSecondSet(); failSecond = unit_4.failSecondSet(); loadingSet(); preTime = times; second = unit_4.SecondSet(); times = unit_4.StartUnit4(action, times, rightKnee, rightAnkle, rightFoot, leftKnee, leftAnkle, leftFoot); } if (unit == 5) { second = WU.SecondSet(); times = WU.StartUnit5(action, times, centerShoulder, leftShoulder, rightShoulder, leftHand, rightHand, leftElbow, rightElbow, leftWrist, rightWrist, leftKnee, rightKnee, head); label.Content = "第" + times + "次"; } } //回傳次數為1000時表示已完成所有動作,重置所有變數、聲音並回歸Menu頁面 if (times == 1000) { times = 0; unit = 0; action = 0; VideoElement.Stop(); GoodElement.Stop(); LeftNegativeElement.Stop(); LeftPositiveElement.Stop(); RightNegativeElement.Stop(); RightPositiveElement.Stop(); MessageBox.Show("恭喜您完成此單元訓練!"); this.NavigationService.Navigate(menu); } ResetTime(); FailMessage(res); label.Content = "第" + times + "次"; actselect.Content = action; if (unit != 0) { actioning.Content = sign.ReturnAct(unit, action); } } } }
private void btn_stop_Click(object sender, RoutedEventArgs e) { VideoElement.Stop(); // 控制影片停止 }