/// Pauses the Audio/Video. public void Pause() { if (player.Source != null) { player.Pause(); } }
public LADSVideoBubble(String filename, double width, double height) { _filename = filename; _video = new MediaElement(); _controls = new VideoItem(); _sliderTimer = new DispatcherTimer(); _preferredSize = new Size(width, height); _layoutRoot = new Grid(); _video.MediaOpened += new RoutedEventHandler(video_MediaOpened); _video.MediaEnded += new RoutedEventHandler(video_MediaEnded); _video.ScrubbingEnabled = true; _video.LoadedBehavior = MediaState.Manual; _video.Source = new Uri(_filename, UriKind.RelativeOrAbsolute); //fire the MediaOpened event _video.Play(); _video.Pause(); _controls.HorizontalAlignment = HorizontalAlignment.Center; _controls.VerticalAlignment = VerticalAlignment.Center; _controls.Hide(); _controls.playButton.Click += new RoutedEventHandler(playButton_Click); _controls.stopButton.Click += new RoutedEventHandler(stopButton_Click); _controls.videoSlider.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(videoSlider_PreviewMouseLeftButtonDown); _controls.videoSlider.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(videoSlider_PreviewMouseLeftButtonUp); _controls.videoSlider.PreviewTouchDown += new System.EventHandler<TouchEventArgs>(videoSlider_PreviewTouchDown); _controls.videoSlider.PreviewTouchUp += new System.EventHandler<TouchEventArgs>(videoSlider_PreviewTouchUp); _controls.videoSlider.IsMoveToPointEnabled = false; _controls.videoSlider.SmallChange = 0; _controls.videoSlider.LargeChange = 0; _sliderTimer.Interval = new TimeSpan(0, 0, 0, 0, SLIDER_TIMER_RESOLUTION); _sliderTimer.Tick += new EventHandler(sliderTimer_Tick); _layoutRoot.RowDefinitions.Add(new RowDefinition()); _layoutRoot.RowDefinitions.Add(new RowDefinition()); _layoutRoot.RowDefinitions[1].Height = new GridLength(50); Grid.SetRow(_controls, 1); Grid.SetRow(_video, 0); _layoutRoot.Children.Add(_video); this.AddChild(_layoutRoot); //this.MouseEnter += new MouseEventHandler(VideoBubble_MouseEnter); //this.MouseLeave += new MouseEventHandler(VideoBubble_MouseLeave); this.SizeChanged += new SizeChangedEventHandler(LADSVideoBubble_SizeChanged); }
public static void PlayMedia(MediaElement mediaElement, TimeSpan start, TimeSpan length, bool muted) { mediaElement.Stop(); mediaElement.Position = start; mediaElement.IsMuted = muted; Console.WriteLine("Playing video at {0}", start); mediaElement.Play(); DispatcherTimer timer = null; n++; int x = n; timer = new DispatcherTimer(length, DispatcherPriority.Send, (_s, _e) => { if (x == n) { mediaElement.Pause(); timer.Stop(); } }, mediaElement.Dispatcher); }
public AssociatedDocListBoxItem(String labeltext, String imageUri, String _scatteruri, ArtworkModeWindow lb, string description) { _helpers = new Helpers(); _description = description; scatteruri = _scatteruri; _lb = lb; opened = false; dp = new DockPanel(); this.Content = dp; //if image if (_helpers.IsImageFile(_scatteruri)) { image = new Image(); _helpers = new Helpers(); FileStream stream = new FileStream(imageUri, FileMode.Open); System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream); System.Windows.Controls.Image wpfImage = _helpers.ConvertDrawingImageToWPFImage(dImage); stream.Close(); wpfImage.SetCurrentValue(DockPanel.DockProperty, Dock.Left); wpfImage.SetCurrentValue(HeightProperty, 50.0); wpfImage.SetCurrentValue(WidthProperty, 50 * wpfImage.Source.Width / wpfImage.Source.Height); dp.Children.Add(wpfImage); label = new Label(); label.Content = labeltext; label.FontSize = 18; label.SetCurrentValue(DockPanel.DockProperty, Dock.Right); dp.Children.Add(label); this.PreviewTouchDown += new EventHandler<TouchEventArgs>(onTouch); this.PreviewMouseDown += new MouseButtonEventHandler(onTouch); lb.getAssociatedDocToolBar().Items.Add(this); } //equivalent for videos else if (_helpers.IsVideoFile(_scatteruri)) { if (_helpers.IsDirShowFile(_scatteruri)) //can easily create nice thumbnails of the video using DirectShow { image = new Image(); imageUri = System.IO.Path.GetFullPath(imageUri); int decrement = System.IO.Path.GetExtension(imageUri).Length; imageUri = imageUri.Remove(imageUri.Length - decrement, decrement); imageUri += ".bmp"; FileStream stream = new FileStream(imageUri, FileMode.Open); System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream); System.Windows.Controls.Image wpfImage = _helpers.ConvertDrawingImageToWPFImage(dImage); stream.Close(); wpfImage.SetCurrentValue(DockPanel.DockProperty, Dock.Left); wpfImage.SetCurrentValue(HeightProperty, 50.0); wpfImage.SetCurrentValue(WidthProperty, 50 * wpfImage.Source.Width / wpfImage.Source.Height); dp.Children.Add(wpfImage); label = new Label(); label.Content = labeltext; label.FontSize = 18; label.SetCurrentValue(DockPanel.DockProperty, Dock.Right); dp.Children.Add(label); this.PreviewTouchDown += new EventHandler<TouchEventArgs>(onTouch); this.PreviewMouseDown += new MouseButtonEventHandler(onTouch); lb.getAssociatedDocToolBar().Items.Add(this); } //Code for not actually creating thumbnails of videos, but instead creating paused, unplayable media elements to act as thumbnails else { MediaElement thumVid = new MediaElement(); thumVid.Source = new Uri(scatteruri, UriKind.RelativeOrAbsolute); thumVid.LoadedBehavior = MediaState.Manual; thumVid.ScrubbingEnabled = true; thumVid.Play(); thumVid.Pause(); thumVid.Position = new TimeSpan(0, 0, 0, 0); thumVid.SetCurrentValue(DockPanel.DockProperty, Dock.Left); thumVid.SetCurrentValue(HeightProperty, 50.0); thumVid.SetCurrentValue(WidthProperty, 50 * thumVid.Width / thumVid.Height); dp.Children.Add(thumVid); label = new Label(); label.Content = labeltext; label.FontSize = 18; label.SetCurrentValue(DockPanel.DockProperty, Dock.Right); dp.Children.Add(label); this.PreviewTouchDown += new EventHandler<TouchEventArgs>(onTouch); this.PreviewMouseDown += new MouseButtonEventHandler(onTouch); lb.getAssociatedDocToolBar().Items.Add(this); } } }
private static void InitialiseFlickerVideo(MediaElement flicker) { flicker.AutoPlay = false; flicker.Volume = 0.7; flicker.Opacity = 0.6; flicker.HorizontalAlignment = HorizontalAlignment.Stretch; flicker.VerticalAlignment = VerticalAlignment.Stretch; flicker.Stretch = Stretch.Fill; flicker.Visibility = Visibility.Collapsed; flicker.Position = TimeSpan.Zero; flicker.Pause(); }
private static void DeactivateFlickerVideo(MediaElement flicker) { flicker.Pause(); flicker.Visibility = Visibility.Collapsed; flicker.Position = TimeSpan.Zero; }
/// <summary> /// Load data inside the hotspot detail control, can be text or image. /// </summary> /// private void scatterItem_Loaded(object sender, RoutedEventArgs e) { firstTime = true; Name.Content = m_hotspotData.Name; //if (m_hotspotData.Type.ToLower().Contains("image")) //{ // MinX = 402; // MinY = 320; // BitmapImage img = new BitmapImage(); // String imgUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Hotspots\\Images\\" + m_hotspotData.Description; // img.BeginInit(); // img.UriSource = new Uri(imgUri, UriKind.Absolute); // img.CacheOption = BitmapCacheOption.OnLoad; // img.EndInit(); // HotspotImage.Source = img; // HotspotImage.Visibility = Visibility.Visible; // HotspotImage.IsEnabled = true; // double maxWidth = 800.0; // if (img.PixelWidth > maxWidth) // { // HotspotImage.SetCurrentValue(HeightProperty, maxWidth * img.PixelHeight / img.PixelWidth); // HotspotImage.SetCurrentValue(WidthProperty, maxWidth); // } // else // { // HotspotImage.SetCurrentValue(HeightProperty, (double) img.PixelHeight); // HotspotImage.SetCurrentValue(WidthProperty, (double) img.PixelWidth); // } // this.SetCurrentValue(HeightProperty, HotspotImage.Height + 47.0); // this.SetCurrentValue(WidthProperty, HotspotImage.Width + 24.0); // hotspotCanvas.Width = HotspotImage.Width + 24.0; // hotspotCanvas.Height = HotspotImage.Height + 47.0; // this.Width = hotspotCanvas.Width; // this.Height = hotspotCanvas.Height; // HotspotTextBox.Visibility = Visibility.Hidden; // //textBoxScroll.Visibility = Visibility.Hidden; // VideoStackPanel.Visibility = Visibility.Collapsed; // AudioScroll.Visibility = Visibility.Hidden; //} if (m_hotspotData.Type.ToLower().Contains("text")) { HotspotTextBox.Text = m_hotspotData.Description; //HotspotTextBox.IsHitTestVisible = false; HotspotTextBox.Visibility = Visibility.Visible; //textBoxScroll.Visibility = Visibility.Visible; HotspotImage.Visibility = Visibility.Hidden; HotspotImage.IsEnabled = false; VideoStackPanel.Visibility = Visibility.Collapsed; AudioScroll.Visibility = Visibility.Hidden; this.CanScale = false; this.Width = 420; } else if (m_hotspotData.Type.ToLower().Contains("audio")) { Width = 300; Height = 200; hotspotCanvas.Width = Width - 8; hotspotCanvas.Height = Height - 8; VideoStackPanel.Visibility = Visibility.Collapsed; //textBoxScroll.Visibility = Visibility.Collapsed; //creates new audio myMediaElement = new MediaElement(); String newaudioUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Hotspots\\Audios\\" + m_hotspotData.Description; myMediaElement.Source = new Uri(newaudioUri); AudioScroll.Children.Add(myMediaElement); myMediaElement.Width = VideoStackPanel.Width; myMediaElement.Height = VideoStackPanel.Height - 30; Name.Width = Width - (422 - 335); VideoStackPanel.Visibility = Visibility.Collapsed; videoCanvas.Visibility = Visibility.Collapsed; //textBoxScroll.Visibility = Visibility.Collapsed; HotspotTextBox.Visibility = Visibility.Hidden; myMediaElement.MediaOpened += new RoutedEventHandler(myMediaElement_MediaOpened); myMediaElement.MediaEnded += new RoutedEventHandler(myMediaElement_MediaEnded); //need to fill in method myMediaElement.LoadedBehavior = MediaState.Manual; String audioUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Hotspots\\Audios\\" + m_hotspotData.Description; myMediaElement.Source = new Uri(audioUri); AudioScroll.Visibility = Visibility.Visible; timelineSlider.Visibility = Visibility.Visible; VideoStackPanel.Visibility = Visibility.Collapsed; AudioScroll.Width = hotspotCanvas.Width - 24; AudioScroll.Height = hotspotCanvas.Height + AudioTextbox.ActualHeight - 47; if (m_hotspotData.fileDescription == "") { AudioTextbox.Visibility = Visibility.Hidden; } else { AudioTextbox.Content = "Description: " + m_hotspotData.fileDescription; AudioTextbox.Width = hotspotCanvas.Width; } this.UpdateLayout(); AudioTextbox.Width = this.ActualWidth-8; hotspotCanvas.SetCurrentValue(HeightProperty, hotspotCanvas.Height + AudioTextbox.ActualHeight+40); this.SetCurrentValue(HeightProperty, hotspotCanvas.Height+8); //fire Media Opened in order to set the actual length myMediaElement.Play(); myMediaElement.Pause(); this.CanScale = false; PlayButton.Click += new RoutedEventHandler(PlayButton_Click); PauseButton.Click += new RoutedEventHandler(PauseButton_Click); StopButton.Click += new RoutedEventHandler(StopButton_Click); this.showAudioIcon(); _dragging = false; _sliderTimer = new System.Windows.Threading.DispatcherTimer(); timelineSlider.PreviewMouseLeftButtonDown += new MouseButtonEventHandler(timelineSlider_PreviewMouseLeftButtonDown); timelineSlider.PreviewMouseLeftButtonUp += new MouseButtonEventHandler(timelineSlider_PreviewMouseLeftButtonUp); timelineSlider.PreviewTouchDown += new System.EventHandler<TouchEventArgs>(timelineSlider_PreviewTouchDown); timelineSlider.PreviewTouchUp += new System.EventHandler<TouchEventArgs>(timelineSlider_PreviewTouchUp); timelineSlider.IsMoveToPointEnabled = false; timelineSlider.SmallChange = 0; timelineSlider.LargeChange = 0; _sliderTimer.Interval = new TimeSpan(0, 0, 0, 0, SLIDER_TIMER_RESOLUTION); _sliderTimer.Tick += new EventHandler(sliderTimer_Tick); _sliderTimer.Stop(); } else if (m_hotspotData.Type.ToLower().Contains("video")) { String videoUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Hotspots\\Videos\\" + m_hotspotData.Description; videoElement = new MediaElement(); videoElement.Source = new Uri(videoUri); videoTimer = new DispatcherTimer(); videoTimer.Interval = new TimeSpan(0, 0, 0, 0, 100); videoTimer.Tick += new EventHandler(videoTimer_Tick); videoElement.MediaOpened += new RoutedEventHandler(videoElement_MediaOpened); videoElement.MediaEnded += VideoElementDone; videoElement.LoadedBehavior = MediaState.Manual; videoElement.Play(); videoElement.Pause(); VideoStackPanel.Children.Insert(1,videoElement); //textBoxScroll.Visibility = Visibility.Collapsed; AudioScroll.Visibility = Visibility.Collapsed; hasVideo = true; Grid g = new Grid(); g.Height = 30; g.Width = 100; g.HorizontalAlignment = HorizontalAlignment.Left; Polygon p = new Polygon(); PointCollection ppoints = new PointCollection(); ppoints.Add(new System.Windows.Point(4, 5)); ppoints.Add(new System.Windows.Point(4, 26)); ppoints.Add(new System.Windows.Point(23, 14)); p.Points = ppoints; p.Fill = Brushes.Green; //p.Opacity = 1; p.Visibility = Visibility.Visible; p.Margin = new Thickness(0, 0, 0, 0); p.Stroke = Brushes.Black; p.StrokeThickness = 1; p.HorizontalAlignment = HorizontalAlignment.Left; p.VerticalAlignment = VerticalAlignment.Center; p.Height = 36; p.Width = 30; Polygon pause = new Polygon(); PointCollection pausepoints = new PointCollection(); pausepoints.Add(new System.Windows.Point(29, -1)); pausepoints.Add(new System.Windows.Point(29, 22)); pausepoints.Add(new System.Windows.Point(37, 22)); pausepoints.Add(new System.Windows.Point(37, -1)); pause.Points = pausepoints; pause.Fill = Brushes.Blue; //p.Opacity = 1; pause.Visibility = Visibility.Visible; pause.Margin = new Thickness(0, 0, 0, 0); pause.Stroke = Brushes.Black; pause.StrokeThickness = 1; pause.HorizontalAlignment = HorizontalAlignment.Left; pause.VerticalAlignment = VerticalAlignment.Center; Polygon pause2 = new Polygon(); PointCollection pausepoints2 = new PointCollection(); pausepoints2.Add(new System.Windows.Point(43, -1)); pausepoints2.Add(new System.Windows.Point(43, 22)); pausepoints2.Add(new System.Windows.Point(51, 22)); pausepoints2.Add(new System.Windows.Point(51, -1)); pause2.Points = pausepoints2; pause2.Fill = Brushes.Blue; //p.Opacity = 1; pause2.Visibility = Visibility.Visible; pause2.Margin = new Thickness(0, 0, 0, 0); pause2.Stroke = Brushes.Black; pause2.StrokeThickness = 1; pause2.HorizontalAlignment = HorizontalAlignment.Left; pause2.VerticalAlignment = VerticalAlignment.Center; g.Children.Add(p); g.Children.Add(pause); g.Children.Add(pause2); g.Visibility = Visibility.Visible; SurfacePlayButton.Content = g; HotspotTextBox.Visibility = Visibility.Hidden; Canvas.SetTop(VideoStackPanel, 35); if (m_hotspotData.fileDescription == "") { VideoText.Visibility = Visibility.Hidden; } else { VideoText.Content = "Description: " + m_hotspotData.fileDescription; } } else if((m_hotspotData.Type.ToLower().Contains("image"))) { sizeChanged = false; BitmapImage img = new BitmapImage(); String imgUri = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location) + "\\Data\\Hotspots\\Images\\" + m_hotspotData.Description; img.BeginInit(); img.UriSource = new Uri(imgUri, UriKind.Absolute); img.CacheOption = BitmapCacheOption.OnLoad; img.EndInit(); HotspotImageMix.Source = img; HotspotImageMix.Visibility = Visibility.Visible; HotspotImageMix.IsEnabled = true; double maxWidth = 600.0; if (img.PixelWidth > maxWidth) { HotspotImageMix.SetCurrentValue(HeightProperty, maxWidth * img.PixelHeight / img.PixelWidth); HotspotImageMix.SetCurrentValue(WidthProperty, maxWidth); } else { HotspotImageMix.SetCurrentValue(HeightProperty, (double)img.PixelHeight); HotspotImageMix.SetCurrentValue(WidthProperty, (double)img.PixelWidth); } if (m_hotspotData.fileDescription == "") { HotspotTextBoxMix.Visibility = Visibility.Hidden; } else { HotspotTextBoxMix.Content = "Description: "+m_hotspotData.fileDescription; HotspotTextBoxMix.Width = HotspotImageMix.Width; } this.UpdateLayout(); this.SetCurrentValue(HeightProperty, HotspotImageMix.Height + 10.0 + HotspotTextBoxMix.ActualHeight); this.SetCurrentValue(WidthProperty, HotspotImageMix.Width + 10.0); HotspotTextBox.Visibility = Visibility.Hidden; hotspotCanvas.Width = HotspotImageMix.Width; hotspotCanvas.Height = HotspotImageMix.Height + HotspotTextBoxMix.ActualHeight; //textBoxScroll.Visibility = Visibility.Visible; Mix.Visibility = Visibility.Visible; Canvas.SetZIndex(Mix, 100); this.UpdateLayout(); this.CanScale = true; Canvas.SetZIndex(closeButton, 100); //HotspotTextBox.Visibility = Visibility.Hidden; //textBoxScroll.Visibility = Visibility.Hidden; VideoStackPanel.Visibility = Visibility.Collapsed; AudioScroll.Visibility = Visibility.Hidden; // windowSize = new Size(this.Width, this.Height); } Double[] size = this.findImageSize(); screenPosX = (m_msi.GetZoomableCanvas.Scale * m_hotspotData.PositionX *size[0]) - m_msi.GetZoomableCanvas.Offset.X; screenPosY = (m_msi.GetZoomableCanvas.Scale * m_hotspotData.PositionY *size[1]) - m_msi.GetZoomableCanvas.Offset.Y; this.Center = new Point(screenPosX + this.Width/2.0, screenPosY + this.Height/2.0); sizeChanged = true; firstTime = false; }
public void prepare() { if (path != null) { if (mediaElement == null) { mediaElement = new MediaElement(); MainPage.m_mainPage.LayoutRoot.Children.Add(mediaElement); mediaElement.MediaOpened += mediaElement_MediaOpened; mediaElement.MediaFailed += mediaElement_MediaFailed; mediaElement.MediaEnded += mediaElement_MediaEnded; if (mediaElement.Source == null) { mediaElement.Source = new Uri(path, UriKind.RelativeOrAbsolute); mediaElement.Play(); mediaElement.Pause(); } } timeLastPlayed = DateTime.Now; } }
/// <summary> /// MovieChange /// </summary> /// <param name="message"></param> public void MovieChange(MovieChangeMessage message) { Movie = message.Movie; if(Movie == null) { MovieObj.MediaOpened -= new System.Windows.RoutedEventHandler(MovieObj_MediaOpened); return; } if (MovieObj != null) { MovieObj.Close(); MovieObj = null; } MovieObj = new MediaElement() { LoadedBehavior = MediaState.Manual, ScrubbingEnabled = true, Stretch = System.Windows.Media.Stretch.Uniform, }; MovieObj.MediaOpened += new System.Windows.RoutedEventHandler(MovieObj_MediaOpened); MovieObj.Source = new Uri(Movie.FullPath); MovieObj.Pause(); // Popup Thumbnail ThumbMovieObj = new MediaElement() { LoadedBehavior = MediaState.Manual, ScrubbingEnabled = true, Stretch = System.Windows.Media.Stretch.Uniform, }; ThumbMovieObj.Source = new Uri(Movie.FullPath); ThumbMovieObj.Pause(); }