public void Play() { if (VideoPlayerElement.Source != null) { VideoPlayerElement.Play(); this.Background = Brushes.Gray; MediaState = MediaState.Play; } }
public void Stop() { if (VideoPlayerElement.Source != null) { VideoPlayerElement.Stop(); this.Background = Brushes.DarkGray; MediaState = MediaState.Stop; } }
private void OnDownloadOrPlayClick(object sender, RoutedEventArgs e) { if (media == null) { return; } if (!downloaded) { PlaybackButton.IsEnabled = false; PlaybackButton.Content = "downloading..."; MessageMediaVideoConstructor mediaVideo = (MessageMediaVideoConstructor)media; Task.Run(() => TelegramSession.Instance.Files.DownloadVideo(mediaVideo.video, Handler)).ContinueWith( (result) => { Deployment.Current.Dispatcher.BeginInvoke(() => { videoSource = result.Result; PlaybackButton.Content = "play"; PlaybackButton.IsEnabled = true; PlaybackProgress.Visibility = Visibility.Collapsed; downloaded = true; }); }); } else { PlaybackButton.Visibility = Visibility.Collapsed; if (videoSource == null) { return; } using (var isf = IsolatedStorageFile.GetUserStoreForApplication()) { using (var isfs = new IsolatedStorageFileStream(videoSource, FileMode.Open, FileAccess.Read, FileShare.Read, isf)) { VideoPlayerElement.SetSource(isfs); VideoPlayerElement.Play(); } } } }
/// <summary> /// Sometimes MediaElement crashes - black window /// I will replace it with the new one /// </summary> internal void RecreateMediaElement(bool flipHorizontally) { try { if (VideoPlayerElement != null) { VideoPlayerElement.Stop(); VideoPlayerElement.Close(); VideoPlayerElement.Clock = null; VideoPlayerElement.Source = null; VideoPlayerElement.Volume = 0; VideoPlayerElement = null; scrollPlayer.Content = null; GC.Collect(); GC.WaitForPendingFinalizers(); } MediaState = MediaState.Manual; VideoPlayerElement = new MediaElement(); VideoPlayerElement.Width = 1920; VideoPlayerElement.Height = 1080; VideoPlayerElement.LoadedBehavior = MediaState.Manual; VideoPlayerElement.Stretch = Stretch.Uniform; VideoPlayerElement.MouseWheel += mePlayer_MouseWheel; Volume = 0; //reset scrollPlayer.Content = VideoPlayerElement; double vOff = _scrollDragger.VerticalOffset; double zoom = _scrollDragger.Zoom; _scrollDragger = new ScrollDragZoom(VideoPlayerElement, scrollPlayer); _scrollDragger.Zoom = zoom; _scrollDragger.VerticalOffset = vOff; _scrollDragger.SizeChangedAction = () => { txtVideoResolution.Text = string.Format("{0:0}x{1:0} ({2:0.0}%)", VideoPlayerElement.ActualWidth, VideoPlayerElement.ActualHeight, 100.0 * _scrollDragger.Zoom); }; //refresh view when change position VideoPlayerElement.ScrubbingEnabled = true; AddFlipXRenderTransform(VideoPlayerElement, flipHorizontally); VideoPlayerElement.MediaOpened += (s, e) => { double zoom_save = _scrollDragger.Zoom; _scrollDragger.NaturalSize = new Size(VideoPlayerElement.NaturalVideoWidth, VideoPlayerElement.NaturalVideoHeight); _scrollDragger.Zoom = zoom_save; MediaState = GetMediaState(VideoPlayerElement); VideoStarted(this); }; VideoPlayerElement.MediaEnded += (s, e) => { VideoEnded(); }; VideoPlayerElement.MediaFailed += (s, e) => { e.Handled = VideoFailed(e, VideoPlayerElement); }; } catch (Exception err) { MessageBox.Show(err.ToString()); } }