Example #1
0
 public static void Play(this IPreviewFrame previewFrame)
 {
     RunOnVideo(previewFrame.Holder, mediaElement =>
     {
         mediaElement.Play();
     });
 }
Example #2
0
 public static void SetVideoPosition(this IPreviewFrame previewFrame, TimeSpan position)
 {
     RunOnVideo(previewFrame.Holder, mediaElement =>
     {
         mediaElement.Position = position;
     });
 }
Example #3
0
 public static TimeSpan GetVideoPosition(this IPreviewFrame previewFrame)
 {
     return(RunOnVideo(previewFrame.Holder, mediaElement =>
     {
         return mediaElement.Position;
     }));
 }
Example #4
0
 public static void Pause(this IPreviewFrame previewFrame)
 {
     RunOnVideo(previewFrame.Holder, mediaElement =>
     {
         if (mediaElement.CanPause)
         {
             mediaElement.Pause();
         }
     });
 }
Example #5
0
        public static void SetImage(this IPreviewFrame previewFrame)
        {
            Grid holder = previewFrame.Holder;

            if (HasChild <PaddingFrame>(holder))
            {
                // There is already an image on here.
                RemoveVideo(holder);
                return;
            }

            RemoveChildren(holder);

            PreviewWindowViewModel viewModel;

            var paddingFrame = new PaddingFrame();

            paddingFrame.SetBinding(PaddingFrame.SourceProperty, nameof(viewModel.PreviewImageServiceClient) + "." + nameof(viewModel.PreviewImageServiceClient.PreviewImage));
            paddingFrame.SetBinding(PaddingFrame.OutputSizeProperty, nameof(viewModel.PreviewImageService) + "." + nameof(viewModel.PreviewImageService.OutputSizeInfo));
            paddingFrame.SetBinding(PaddingFrame.PadColorProperty, nameof(viewModel.PreviewImageService) + "." + nameof(viewModel.PreviewImageService.PadColor));

            previewFrame.Holder.Children.Add(paddingFrame);
        }
Example #6
0
        public static void SetVideo(this IPreviewFrame previewFrame, Action onCompleted, Action onFailed, IObservable <double> volume)
        {
            Grid holder = previewFrame.Holder;

            if (HasChild <MediaElement>(holder))
            {
                // There is already a video in here.
                RemoveImage(holder);
                return;
            }

            // Close any video that was there before.
            RemoveVideo(holder);

            // Add on a new video
            var mediaElement = new MediaElement
            {
                Stretch = Stretch.Fill,
                Opacity = 0
            };

            var viewModel = (PreviewWindowViewModel)previewFrame.Holder.DataContext;

            mediaElement.SetBinding(MediaElement.SourceProperty, nameof(viewModel.PreviewFilePath));
            mediaElement.LoadedBehavior   = MediaState.Manual;
            mediaElement.ScrubbingEnabled = true;
            mediaElement.MediaOpened     += (sender, args) =>
            {
                if (mediaElement.NaturalDuration.HasTimeSpan)
                {
                    viewModel.PreviewVideoDuration = mediaElement.NaturalDuration.TimeSpan;
                }
                else
                {
                    viewModel.PreviewVideoDuration = TimeSpan.Zero;
                }

                // Video starts out black so we want to hold it at the start until it displays fully.
                mediaElement.Pause();

                DispatchUtilities.BeginInvoke(() =>
                {
                    OnVideoPlaying(holder);
                    mediaElement.Play();
                });
            };

            mediaElement.MediaFailed += (sender, args) =>
            {
                onFailed();
            };

            mediaElement.MediaEnded += (sender, args) =>
            {
                onCompleted();
            };

            volume.Subscribe(v =>
            {
                mediaElement.Volume = v;
            });

            mediaElement.Play();

            holder.Children.Add(mediaElement);
        }
Example #7
0
 public static void CloseVideo(this IPreviewFrame previewFrame)
 {
     RemoveVideo(previewFrame.Holder);
 }
Example #8
0
 public static void Close(this IPreviewFrame previewFrame)
 {
     RemoveChildren(previewFrame.Holder);
 }