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); }
//constructor for VIDEOS public DockableItem(ScatterView _mainScatterView, ArtworkModeWindow _win, SurfaceListBox _bar, string _targetVid, AssociatedDocListBoxItem _aldbi, LADSVideoBubble _video, VideoItem _vidctrl, String description) { isVideo = true; scatteruri = _targetVid; vidBub = _video; _helpers = new Helpers(); _description = description; image = new Image(); aldbi = null; String thumbFileName = _targetVid; //the video thumbnail filename is the same name with a different extension. This gets that extension int decrement = System.IO.Path.GetExtension(thumbFileName).Length; thumbFileName = thumbFileName.Remove(thumbFileName.Length - decrement, decrement); thumbFileName += ".bmp"; thumbFileName = System.IO.Path.GetFileName(thumbFileName); thumbFileName = "Data\\Videos\\Metadata\\" + thumbFileName; //opens in filestream to prevent errors from the file already being open FileStream stream = new FileStream(thumbFileName, FileMode.Open); System.Drawing.Image dImage = System.Drawing.Image.FromStream(stream); System.Windows.Controls.Image wpfImage = _helpers.ConvertDrawingImageToWPFImage(dImage); image.Source = wpfImage.Source; stream.Close(); this.isAnimating = false; this.Background = Brushes.LightGray; this.AddChild(vidBub); this.UpdateLayout(); mainScatterView = _mainScatterView; bar = _bar; win = _win; isDocked = false; touchDown = false; aldbi = _aldbi; DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(ScatterViewItem.CenterProperty, typeof(ScatterViewItem)); dpd.AddValueChanged(this, CenterChangedListener); this.PreviewTouchUp += new EventHandler<TouchEventArgs>(AddtoDock); this.PreviewMouseUp += new MouseButtonEventHandler(AddtoDock); this.PreviewMouseWheel += new MouseWheelEventHandler(DockableItem_PreviewMouseWheel); this.CaptureMouse(); mainScatterView.Items.Add(this); Random rnd = new Random(); Point pt = new Point(rnd.Next((int)(win.ActualWidth * .2 + vidBub.ActualWidth * 3), (int)(win.ActualWidth - vidBub.ActualWidth * 3 - 100)), rnd.Next((int)(vidBub.ActualHeight * 3), (int)(win.ActualHeight * .8 - vidBub.ActualHeight * 3))); this.SetCurrentValue(CenterProperty, pt); this.Orientation = rnd.Next(-20, 20); imageURIPath = _targetVid; MediaElement vid = vidBub.getVideo(); vid.MediaOpened += new RoutedEventHandler(video_MediaOpened); vid.Loaded += new RoutedEventHandler(video_MediaOpened); this.MinHeight = 100; }