Esempio n. 1
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            mImageLeft = GetTemplateChild(PART_ImageLeft) as Image;
            if (mImageLeft != null)
            {
            }
            mImageRight = GetTemplateChild(PART_ImageRight) as Image;
            if (mImageRight != null)
            {
            }
            mSliderPosition = GetTemplateChild(PART_Slider) as Slider;
            if (mSliderPosition != null)
            {
                mSliderPosition.AddHandler(MouseLeftButtonDownEvent,
                                           new MouseButtonEventHandler((s, e) => mIsDraging = true), true);
                mSliderPosition.AddHandler(MouseLeftButtonUpEvent,
                                           new MouseButtonEventHandler(mSliderPosition_MouseLeftButtonUp), true);
                mSliderPosition.MouseLeave += (s, e) => mIsDraging = false;
            }
            mListBoxLeft = GetTemplateChild(PART_ListLeftButtons) as ListBox;
            if (mListBoxLeft != null)
            {
                mListBoxLeft.ItemsSource = mListLeftButtons;
            }
            mListBoxRight = GetTemplateChild(PART_ListRightButtons) as ListBox;
            if (mListBoxRight != null)
            {
                mListBoxRight.ItemsSource = mListRightButtons;
            }
        }
Esempio n. 2
0
        private static void AttachHandlers(Slider slider, Thumb thumb)
        {
            if (thumb == null)
            {
                thumb = (Thumb)slider.Template.FindName("Thumb", slider);
            }

            slider.DataContextChanged += slider_DataContextChanged;
            slider.AddHandler(Slider.MouseLeaveEvent, new MouseEventHandler(slider_MouseLeave));
            slider.AddHandler(Slider.MouseLeftButtonDownEvent, new MouseButtonEventHandler(slider_PreviewMouseLeftButtonDown), true);
            slider.AddHandler(Slider.MouseLeftButtonUpEvent, new MouseButtonEventHandler(slider_PreviewMouseLeftButtonUp), true);
            thumb.AddHandler(Thumb.MouseLeftButtonDownEvent, new MouseButtonEventHandler(slider_PreviewMouseLeftButtonDown), true);
            thumb.AddHandler(Thumb.MouseLeftButtonUpEvent, new MouseButtonEventHandler(slider_PreviewMouseLeftButtonUp), true);
        }
        public MainWindow()
        {
            InitializeComponent();
#if DEBUG
            this.AttachDevTools();
#endif
            Import_PlaySongButton        = this.Find <Button>("Import_PlaySongButton");
            Import_PlaySongButton.Click += Import_PlaySongButton_Click;
            Import_PathTextBox           = this.Find <TextBox>("Import_PathTextBox");

            TrackTitleTextBlock  = this.Find <TextBlock>("TrackTitleTextBlock");
            TrackArtistTextBlock = this.Find <TextBlock>("TrackArtistTextBlock");
            ProgressIndicator1   = this.Find <TextBlock>("ProgressIndicator1");
            ProgressIndicator2   = this.Find <TextBlock>("ProgressIndicator2");
            ProgressSlider       = this.Find <Slider>("ProgressSlider");
            ProgressSlider.AddHandler(Slider.PointerPressedEvent, ProgressSlider_PointerPressed, Avalonia.Interactivity.RoutingStrategies.Tunnel);
            //ProgressSlider.PointerPressed += ProgressSlider_PointerPressed;
            //ProgressSlider.PointerReleased += ProgressSlider_PointerReleased;
            ProgressSlider.AddHandler(Slider.PointerReleasedEvent, ProgressSlider_PointerReleased, Avalonia.Interactivity.RoutingStrategies.Tunnel);
            ProgressSlider.PropertyChanged += ProgressSlider_PropertyChanged;
            VolumeSlider = this.Find <Slider>("VolumeSlider");
            VolumeSlider.PropertyChanged += VolumeSlider_PropertyChanged;
            CoverArtImage = this.Find <Image>("CoverArtImage");

            PreviousTrackButton = this.Find <Button>("PreviousTrackButton");
            ShuffleButton       = this.Find <ToggleButton>("ShuffleButton");
            PlayPauseButton     = this.Find <Button>("PlayPauseButton");
            RepeatOneButton     = this.Find <ToggleButton>("RepeatOneButton");
            NextTrackButton     = this.Find <Button>("NextTrackButton");

            Tracks_TracksListBox = this.Find <ListBox>("Tracks_TracksListBox");

            try { Libraryv2 = new LiteDatabase(Path.Combine(DatabaseHandler.DatabasePath, "database.fdb2")); }
            catch { TrackTitleTextBlock.Text = "Library is not available; another instance of FMP is probably open"; }

            Player.SongChanged   += Player_SongChanged;
            Player.SongStopped   += Player_SongStopped;
            Player.SongException += Player_SongException;

            PreviousTrackButton.Click += PreviousTrackButton_Click;
            ShuffleButton.Click       += ShuffleButton_Click;
            PlayPauseButton.Click     += PlayPauseButton_Click;
            RepeatOneButton.Click     += RepeatOneButton_Click;
            NextTrackButton.Click     += NextTrackButton_Click;

            progressTimer.Elapsed += ProgressTimer_Elapsed;
            LoadLibrary();
        }
Esempio n. 4
0
        public override void OnApplyTemplate()
        {
            if (_hueSlider != null)
            {
                _hueSlider.ValueChanged -= OnHueSliderValueChanged;
                _hueSlider.MouseMove    -= OnHueSliderMouseMove;
                _hueSlider.RemoveHandler(MouseLeftButtonUpEvent, new MouseButtonEventHandler(OnHueSliderMouseLeftButtonUp));
            }

            if (_colorCanvas != null)
            {
                _colorCanvas.RemoveHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnColorCanvasMouseLeftButtonDown));
            }

            base.OnApplyTemplate();

            _hueSlider   = base.GetTemplateChild(HueSliderTemplateName) as Slider;
            _selectPath  = base.GetTemplateChild(SelectPathTemplateName) as Path;
            _colorCanvas = base.GetTemplateChild(ColorCanvasTemplateName) as Canvas;


            if (_hueSlider != null)
            {
                _hueSlider.ValueChanged += OnHueSliderValueChanged;
                _hueSlider.MouseMove    += OnHueSliderMouseMove;
                _hueSlider.AddHandler(MouseLeftButtonUpEvent, new MouseButtonEventHandler(OnHueSliderMouseLeftButtonUp), true);
            }

            if (_colorCanvas != null)
            {
                _colorCanvas.AddHandler(MouseLeftButtonDownEvent, new MouseButtonEventHandler(OnColorCanvasMouseLeftButtonDown), false);
            }
        }
Esempio n. 5
0
        public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();

            // ApplyTemplate can get called several times (switching full screen), attach to events only once.
            if (DesignerProperties.GetIsInDesignMode(this))
            {
                return;
            }

            Slider Bar = SeekBar;

            if (Bar != null)
            {
                MouseDown += UserControl_MouseDown;
                Bar.AddHandler(Slider.PreviewMouseDownEvent, new MouseButtonEventHandler(base.SeekBar_PreviewMouseLeftButtonDown), true);
                // Thumb doesn't yet exist.
                Bar.Loaded += (s, e) => {
                    Thumb SeekBarThumb = GetSliderThumb(Bar);
                    if (SeekBarThumb != null)
                    {
                        SeekBarThumb.DragStarted   += SeekBar_DragStarted;
                        SeekBarThumb.DragCompleted += SeekBar_DragCompleted;
                    }
                };
            }
        }
Esempio n. 6
0
        private async void VolumeSlider_Loaded(object sender, RoutedEventArgs e)
        {
            int volume = await Applikation.GetVolume();

            SetVolumeSliderValue(volume);
            slider = sender as Slider;
            slider.AddHandler(UIElement.PointerReleasedEvent, new PointerEventHandler(slider_PointerReleased), true);
        }
Esempio n. 7
0
        public PlaybackHeader()
        {
            InitializeComponent();

            Slider.AddHandler(PointerPressedEvent, new PointerEventHandler(Slider_PointerPressed), true);
            Slider.AddHandler(PointerReleasedEvent, new PointerEventHandler(Slider_PointerReleased), true);
            Slider.AddHandler(PointerCanceledEvent, new PointerEventHandler(Slider_PointerCanceled), true);
            Slider.AddHandler(PointerCaptureLostEvent, new PointerEventHandler(Slider_PointerCaptureLost), true);
        }
Esempio n. 8
0
 public TickableSlider()
 {
     this.InitializeComponent();
     Slider.AddHandler(PointerReleasedEvent, new PointerEventHandler(Slider_PointerReleased), true);
     ToolTipTimer.Tick    += TooltipTimer_Tick;
     ToolTipTimer.Interval = TimeSpan.FromSeconds(1);
     ToolTipFlyout.Hide();
     Out("Instance created and hide.");
 }
Esempio n. 9
0
        public PlaybackHeader()
        {
            InitializeComponent();

            Slider.AddHandler(PointerPressedEvent, new PointerEventHandler(Slider_PointerPressed), true);
            Slider.AddHandler(PointerReleasedEvent, new PointerEventHandler(Slider_PointerReleased), true);
            Slider.AddHandler(PointerCanceledEvent, new PointerEventHandler(Slider_PointerCanceled), true);
            Slider.AddHandler(PointerCaptureLostEvent, new PointerEventHandler(Slider_PointerCaptureLost), true);

            _visual1 = ElementCompositionPreview.GetElementVisual(Label1);
            _visual2 = ElementCompositionPreview.GetElementVisual(Label2);

            _visual = _visual1;
        }
Esempio n. 10
0
        private void SubscribeEvents()
        {
            if (_mediaElement != null)
            {
                _mediaElement.Loaded           += OnMediaLoaded;
                _mediaElement.MediaOpened      += OnMediaOpened;
                _mediaElement.MediaEnded       += OnMediaEnded;
                _mediaElement.BufferingStarted += OnBufferingStarted;
                _mediaElement.BufferingEnded   += OnBufferingEnded;
            }

            if (_slider != null)
            {
                _slider.ValueChanged += OnSliderValueChanged;
                _slider.MouseMove    += OnSliderMouseMove;
                _slider.AddHandler(MouseLeftButtonUpEvent, new MouseButtonEventHandler(OnSliderMouseLeftButtonUp), true);
            }
        }
Esempio n. 11
0
        public PlaybackHeader()
        {
            InitializeComponent();

            Slider.AddHandler(PointerPressedEvent, new PointerEventHandler(Slider_PointerPressed), true);
            Slider.AddHandler(PointerReleasedEvent, new PointerEventHandler(Slider_PointerReleased), true);
            Slider.AddHandler(PointerCanceledEvent, new PointerEventHandler(Slider_PointerCanceled), true);
            Slider.AddHandler(PointerCaptureLostEvent, new PointerEventHandler(Slider_PointerCaptureLost), true);

            if (!ApiInfo.IsPhoneContractPresent)
            {
                Slider.Margin = new Thickness(0, -2, 0, 0);
                Slider.Height = 6;
            }

            _visual1 = ElementCompositionPreview.GetElementVisual(Label1);
            _visual2 = ElementCompositionPreview.GetElementVisual(Label2);

            _visual = _visual1;
        }
Esempio n. 12
0
        public SliderListItem()
        {
            AvaloniaXamlLoader.Load(this);

            _slider = this.FindControl <Slider>("Slider");

            _slider.AddHandler(PointerReleasedEvent,
                               (sender, args) =>
            {
                Changed?.Invoke(this, (int)_slider.Value);
            },
                               RoutingStrategies.Tunnel);

            _slider.GetObservable(RangeBase.ValueProperty).Subscribe(d =>
            {
                try
                {
                    var subtitle = SubtitleDictionary?[(int)d];
                    if (subtitle != null)
                    {
                        Subtitle = subtitle;
                    }
                }
                catch (KeyNotFoundException)
                {
                    Log.Warning("SliderListItem: Key not in subtitle dictionary");
                    Subtitle = "";
                }
            });

            this.GetObservable(SubtitleDictionaryProperty).Subscribe(dictionary =>
            {
                var subtitle = dictionary?[(int)_slider.Value];
                if (subtitle != null)
                {
                    Subtitle = subtitle;
                }
            });

            DataContext = this;
        }
Esempio n. 13
0
        /// <summary>
        /// Creates a dockpanel containing the new slider with labels.
        /// </summary>
        /// <param name="min">The minimum value.</param>
        /// <param name="max">The maximum value.</param>
        /// <param name="startVal">The start value.</param>
        /// <param name="name">The name of the slider.</param>
        /// <param name="integerSlider">if set to <c>true</c>, snap to integer values.</param>
        /// <param name="decPlaces">The decimal places.</param>
        /// <param name="sliderLabels">The slider labels.</param>
        /// <returns>a Dockpanel containing the slider and labels</returns>
        public DockPanel createNewSliderWithLabels(double min, double max, double startVal, string name, bool integerSlider, int decPlaces, ref List <Label> sliderLabels, double snapValue)
        {
            //initialize slider
            Slider slider = new Slider();

            //set min, starting val, and max
            slider.Minimum = min;
            slider.Value   = startVal;
            slider.Maximum = max;

            //make it not focusable
            slider.Focusable = false;

            if (showTooltip)
            {
                slider.AutoToolTipPlacement = System.Windows.Controls.Primitives.AutoToolTipPlacement.TopLeft;
                slider.AutoToolTipPrecision = decPlaces;
            }

            //if Integer Slider, set ticks and snap to them
            if (integerSlider)
            {
                slider.TickFrequency       = 1.0;
                slider.IsSnapToTickEnabled = true;
                if (showTooltip)
                {
                    slider.AutoToolTipPrecision = 0;
                }
            }

            if (snapValue > 0)
            {
                slider.TickFrequency       = snapValue;
                slider.IsSnapToTickEnabled = true;
            }

            if (showTicks)
            {
                slider.TickPlacement = System.Windows.Controls.Primitives.TickPlacement.BottomRight;
            }

            //Create a label for the name of the slider
            Label label = new Label();

            label.HorizontalContentAlignment = System.Windows.HorizontalAlignment.Right;
            label.Content = name;

            if (showLabel)
            {
                //Pass it out to slider labels so its width can be reconciled later
                if (!string.IsNullOrWhiteSpace(name))
                {
                    sliderLabels.Add(label);
                }
            }


            //set up a dockpanel to contain the three elements: name label, slider, and readout label.
            DockPanel internalDockPanel = new DockPanel();

            internalDockPanel.MinWidth = 200;
            internalDockPanel.Height   = showBounds ? 40 : 32;
            internalDockPanel.Margin   = new Thickness(4);
            //set to stretch so it fills available horizontal width
            internalDockPanel.HorizontalAlignment = HorizontalAlignment.Stretch;

            if (showLabel)
            {
                //add the name label and dock it left
                if (!string.IsNullOrWhiteSpace(name))
                {
                    internalDockPanel.Children.Add(label);
                }
                DockPanel.SetDock(label, Dock.Left);
            }

            //establish format string for labels
            string numberFormat = integerSlider ? "{0:0}" : String.Concat("{0:F", decPlaces, "}");

            //Set up a value entry box for doubleclick
            SliderEntryTextBox ValueEntryBox = new SliderEntryTextBox(slider);

            slider.AddHandler(Slider.MouseDoubleClickEvent, new MouseButtonEventHandler(ValueEntryBox.TriggerAction), true);



            if (showValueReadout) //if user has opted to show the value label
            {
                //create a label for the slider readout
                Label readout = new Label();

                //convert all chars in max to 0s so the label is wide enough when measured
                var maxString     = new string(string.Format(numberFormat, max).ToCharArray().Select(c => '0').ToArray()) + "0";
                var maxStringBase = max.ToString(numberFormat, CultureInfo.InvariantCulture);
                //set to max to establish theoretical max width to avoid jumping
                readout.Content = maxString;

                //format the readout number values
                readout.ContentStringFormat = numberFormat;

                //establish desired size;
                readout.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));

                //set the width to approx max width
                readout.Width = readout.DesiredSize.Width;

                //bind it to the slider Value
                Binding myBinding = new Binding("Value");
                myBinding.Source = slider;

                readout.SetBinding(Label.ContentProperty, myBinding);
                //dock the readout to the right and add it
                DockPanel.SetDock(readout, Dock.Right);
                internalDockPanel.Children.Add(readout);
            }
            //Create a grid to contain the slider, and any under-slider labels
            Grid SliderGrid = new Grid();

            if (showBounds)
            {
                Label lowerBound = new Label();
                Label upperBound = new Label();

                lowerBound.Height = 40;
                upperBound.Height = 40;

                lowerBound.Content = String.Format(numberFormat, min);
                upperBound.Content = String.Format(numberFormat, max);

                lowerBound.FontSize = 10;
                upperBound.FontSize = 10;
                lowerBound.VerticalContentAlignment = VerticalAlignment.Bottom;
                upperBound.VerticalContentAlignment = VerticalAlignment.Bottom;

                upperBound.HorizontalAlignment        = HorizontalAlignment.Right;
                upperBound.HorizontalContentAlignment = HorizontalAlignment.Right;

                lowerBound.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));
                upperBound.Measure(new Size(Double.PositiveInfinity, Double.PositiveInfinity));

                //inset slightly so labels sit more directly below ticks
                slider.Margin = new Thickness((lowerBound.DesiredSize.Width / 2) - 5, 0, (upperBound.DesiredSize.Width / 2) - 5, 0);
                SliderGrid.Children.Add(lowerBound);
                SliderGrid.Children.Add(upperBound);
            }

            // Add the slider to the grid - if it goes last it won't lose its interaction
            SliderGrid.Children.Add(ValueEntryBox);
            SliderGrid.Children.Add(slider);

            //add the slider last - the last item added will fill the available space.
            internalDockPanel.Children.Add(SliderGrid);
            internalDockPanel.Name = "GH_Slider"; //this key is used in other methods to figure out that the panel is to be interpreted as a slider.
            return(internalDockPanel);
        }
Esempio n. 14
0
 public EvSlider()
 {
     this.InitializeComponent();
     Slider.AddHandler(PointerReleasedEvent, new PointerEventHandler(Slider_PointerReleased), true);
 }
Esempio n. 15
0
 private void ProgressSlider_Loaded(object sender, RoutedEventArgs e)
 {
     slider = sender as Slider;
     slider.AddHandler(UIElement.PointerReleasedEvent, new PointerEventHandler(slider_PointerReleased), true);
 }
        /** The media player contains the following elements:
         *  - Media element
         *  - Control panel:
         *      - Timeline panel to keep track of media progress and provide seek to functionality
         *      - Playback panel:
         *          - Pause button
         *          - Resume button
         *          - Replay button
         *          - Volume controls:
         *              - Mute/unmute
         *              - Volume slider
         */
        private static FrameworkElement RenderMediaPlayer(AdaptiveRenderContext context, AdaptiveMediaSource mediaSource, FrameworkElement uiMedia)
        {
            var uiMediaPlayer = new Grid();

            var mediaElement = new MediaElement()
            {
                Stretch = Stretch.Fill,
            };

            uiMediaPlayer.Children.Add(mediaElement);

            // Add some height to keep the controls (timeline panel + playback panel)
            if (!IsAudio(mediaSource))
            {
                uiMediaPlayer.MinHeight = _panelHeight * 2 + _childMargin * 4;
            }

            var uiControlPanel = new StackPanel()
            {
                VerticalAlignment = VerticalAlignment.Bottom,
                Background        = _controlBackgroundColor,
            };

            #region Timeline Panel

            // Using Grid to stretch the timeline slider
            var uiTimelinePanel = new Grid()
            {
                HorizontalAlignment = HorizontalAlignment.Stretch,
                Height = _panelHeight,
            };

            TextBlock uiCurrentTime = new TextBlock()
            {
                Text              = "00:00:00",
                Foreground        = _controlForegroundColor,
                VerticalAlignment = VerticalAlignment.Center,
                Margin            = _marginThickness,
            };
            uiTimelinePanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(20, GridUnitType.Auto),
            });
            Grid.SetColumn(uiCurrentTime, 0);
            uiTimelinePanel.Children.Add(uiCurrentTime);

            Slider uiTimelineSlider = new Slider()
            {
                Margin              = _marginThickness,
                IsEnabled           = false,
                HorizontalAlignment = HorizontalAlignment.Stretch,
                VerticalAlignment   = VerticalAlignment.Center,
            };
            uiTimelinePanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(20, GridUnitType.Star),
            });
            Grid.SetColumn(uiTimelineSlider, 1);
            uiTimelinePanel.Children.Add(uiTimelineSlider);

            TextBlock uiMaxTime = new TextBlock()
            {
                Text              = "00:00:00",
                Foreground        = _controlForegroundColor,
                VerticalAlignment = VerticalAlignment.Center,
                Margin            = _marginThickness,
            };
            uiTimelinePanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(20, GridUnitType.Auto),
            });
            Grid.SetColumn(uiMaxTime, 2);
            uiTimelinePanel.Children.Add(uiMaxTime);

            #endregion

            uiControlPanel.Children.Add(uiTimelinePanel);

            #region Playback + Volume Panel

            var uiPlaybackVolumePanel = new Grid()
            {
                Height = _panelHeight,
            };

            #region Create Playback Control Container

            var uiPlaybackControlContainer = new StackPanel()
            {
                VerticalAlignment   = VerticalAlignment.Center,
                HorizontalAlignment = HorizontalAlignment.Left,
                Orientation         = Orientation.Horizontal,
                Height = _panelHeight,
            };

            // Play trigger attached with the thumbnail button
            var playTrigger = new EventTrigger(UIElement.MouseUpEvent)
            {
                SourceName = "thumbnailButton",
            };

            var mediaTimeline = new MediaTimeline()
            {
                // This URI was previously confirmed to be valid
                Source = context.Config.ResolveFinalAbsoluteUri(mediaSource.Url),
            };
            Storyboard.SetTarget(mediaTimeline, mediaElement);

            var storyboard = new Storyboard()
            {
                SlipBehavior = SlipBehavior.Slip,
            };
            storyboard.Children.Add(mediaTimeline);
            var beginStoryboard = new BeginStoryboard()
            {
                // An arbitrary name is necessary for the storyboard to work correctly
                Name       = "beginStoryboard",
                Storyboard = storyboard,
            };
            playTrigger.Actions.Add(beginStoryboard);

            // The play trigger needs to be added to uiMedia since
            // uiThumbnailButton is inside uiMedia
            uiMedia.Triggers.Add(playTrigger);

            // Buffering signal
            var uiBuffering = new TextBlock()
            {
                Text              = "⏳ Buffering...",
                Foreground        = _controlForegroundColor,
                VerticalAlignment = VerticalAlignment.Center,
                Margin            = _marginThickness,
            };
            uiPlaybackControlContainer.Children.Add(uiBuffering);

            // Pause button
            var uiPauseButton = RenderPlaybackButton("⏸");
            uiPlaybackControlContainer.Children.Add(uiPauseButton);

            // Resume button
            var uiResumeButton = RenderPlaybackButton("⏵");
            uiPlaybackControlContainer.Children.Add(uiResumeButton);

            // Replay button
            var uiReplayButton = RenderPlaybackButton("🔄");
            uiPlaybackControlContainer.Children.Add(uiReplayButton);

            // Click events
            MediaState currentMediaState = MediaState.NotStarted;
            uiPauseButton.MouseUp += (sender, e) =>
            {
                storyboard.Pause(uiMedia);
                currentMediaState = MediaState.IsPaused;
                HandlePlaybackButtonVisibility(currentMediaState, uiPauseButton, uiResumeButton, uiReplayButton);
            };
            uiResumeButton.MouseUp += (sender, e) =>
            {
                storyboard.Resume(uiMedia);
                currentMediaState = MediaState.IsPlaying;
                HandlePlaybackButtonVisibility(currentMediaState, uiPauseButton, uiResumeButton, uiReplayButton);
            };

            #endregion

            // Add to control panel
            uiPlaybackVolumePanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(20, GridUnitType.Star),
            });
            Grid.SetColumn(uiPlaybackControlContainer, 0);
            uiPlaybackVolumePanel.Children.Add(uiPlaybackControlContainer);

            #region Create Volume Control Container

            var uiVolumeControlContainer = new Grid()
            {
                Height            = _panelHeight,
                VerticalAlignment = VerticalAlignment.Center,
            };

            // 2 overlapping buttons to alternate between mute/unmute states
            var uiVolumeMuteButton = new TextBlock()
            {
                Text              = "🔊",
                FontFamily        = _symbolFontFamily,
                FontSize          = _childHeight,
                Foreground        = _controlForegroundColor,
                Margin            = _marginThickness,
                VerticalAlignment = VerticalAlignment.Center,
            };
            uiVolumeControlContainer.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(20, GridUnitType.Auto),
            });
            Grid.SetColumn(uiVolumeMuteButton, 0);
            uiVolumeControlContainer.Children.Add(uiVolumeMuteButton);

            var uiVolumeUnmuteButton = new TextBlock()
            {
                Text              = "🔇",
                FontFamily        = _symbolFontFamily,
                FontSize          = _childHeight,
                Foreground        = _controlForegroundColor,
                Margin            = _marginThickness,
                VerticalAlignment = VerticalAlignment.Center,
                Visibility        = Visibility.Collapsed,
            };
            uiVolumeControlContainer.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(20, GridUnitType.Auto),
            });
            Grid.SetColumn(uiVolumeUnmuteButton, 0);
            uiVolumeControlContainer.Children.Add(uiVolumeUnmuteButton);

            Slider uiVolumeSlider = new Slider()
            {
                Orientation       = Orientation.Horizontal,
                VerticalAlignment = VerticalAlignment.Center,
                Width             = 100,

                Minimum = 0,
                Maximum = 1,
                Value   = 0.5,
            };
            uiVolumeControlContainer.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(20, GridUnitType.Auto),
            });
            Grid.SetColumn(uiVolumeSlider, 1);
            uiVolumeControlContainer.Children.Add(uiVolumeSlider);

            // Initialize media volume to 0.5
            mediaElement.Volume = uiVolumeSlider.Value;

            // Volume control handlers
            void muteVolume(object sender, MouseEventArgs e)
            {
                uiVolumeMuteButton.Visibility   = Visibility.Collapsed;
                uiVolumeUnmuteButton.Visibility = Visibility.Visible;
                mediaElement.Volume             = 0;
            }

            void unmuteVolume(object sender, RoutedEventArgs e)
            {
                uiVolumeUnmuteButton.Visibility = Visibility.Collapsed;
                uiVolumeMuteButton.Visibility   = Visibility.Visible;
                mediaElement.Volume             = uiVolumeSlider.Value;
            }

            uiVolumeMuteButton.MouseUp   += muteVolume;
            uiVolumeUnmuteButton.MouseUp += unmuteVolume;
            uiVolumeSlider.ValueChanged  += unmuteVolume;

            #endregion

            // Add to control panel
            uiPlaybackVolumePanel.ColumnDefinitions.Add(new ColumnDefinition()
            {
                Width = new GridLength(20, GridUnitType.Auto),
            });
            Grid.SetColumn(uiVolumeControlContainer, 1);
            uiPlaybackVolumePanel.Children.Add(uiVolumeControlContainer);

            #endregion

            uiControlPanel.Children.Add(uiPlaybackVolumePanel);

            uiMediaPlayer.Children.Add(uiControlPanel);

            #region Other events

            void showControlPanel(object sender, MouseEventArgs e)
            {
                uiControlPanel.Visibility = Visibility.Visible;
            }

            void collapseControlPanel(object sender, MouseEventArgs e)
            {
                uiControlPanel.Visibility = Visibility.Collapsed;
            }

            void mediaStarted(object sender, RoutedEventArgs e)
            {
                // Playback button visibility
                currentMediaState      = MediaState.IsPlaying;
                uiBuffering.Visibility = Visibility.Collapsed;
                HandlePlaybackButtonVisibility(currentMediaState, uiPauseButton, uiResumeButton, uiReplayButton);

                // Control panel visibility
                if (!IsAudio(mediaSource))
                {
                    // Hide when the video starts playing
                    uiControlPanel.Visibility = Visibility.Collapsed;

                    // Assign mouse hover events to avoid blocking the video
                    uiMediaPlayer.MouseEnter += showControlPanel;
                    uiMediaPlayer.MouseLeave += collapseControlPanel;
                }
            }

            void mediaEnded(object sender, EventArgs e)
            {
                // Playback button visibility
                currentMediaState = MediaState.NotStarted;
                HandlePlaybackButtonVisibility(currentMediaState, uiPauseButton, uiResumeButton, uiReplayButton);

                // Control panel visibility
                if (!IsAudio(mediaSource))
                {
                    // Show when the video is complete
                    uiControlPanel.Visibility = Visibility.Visible;

                    // Remove mouse hover events to always show controls
                    uiMediaPlayer.MouseEnter -= showControlPanel;
                    uiMediaPlayer.MouseLeave -= collapseControlPanel;
                }
            }

            mediaElement.MediaOpened += mediaStarted;
            storyboard.Completed     += mediaEnded;
            uiReplayButton.MouseUp   += (sender, e) =>
            {
                // Seek to beginning
                storyboard.Seek(uiMedia, new TimeSpan(0, 0, 0, 0, 0), TimeSeekOrigin.BeginTime);

                // And start the media as usual
                mediaStarted(sender, e);
            };

            // Timeline slider events
            mediaElement.MediaOpened += (sender, e) =>
            {
                uiTimelineSlider.Maximum   = mediaElement.NaturalDuration.TimeSpan.TotalMilliseconds;
                uiTimelineSlider.IsEnabled = true;

                uiMaxTime.Text = mediaElement.NaturalDuration.TimeSpan.ToString(@"hh\:mm\:ss");
            };
            storyboard.CurrentTimeInvalidated += (sender, e) => {
                uiTimelineSlider.Value = mediaElement.Position.TotalMilliseconds;

                uiCurrentTime.Text = mediaElement.Position.ToString(@"hh\:mm\:ss");
            };

            // Thumb events
            uiTimelineSlider.AddHandler(Thumb.DragStartedEvent, new DragStartedEventHandler((sender, e) =>
            {
                storyboard.Pause(uiMedia);
            }));
            uiTimelineSlider.AddHandler(Thumb.DragDeltaEvent, new DragDeltaEventHandler((sender, e) =>
            {
                int sliderValue = (int)uiTimelineSlider.Value;

                TimeSpan selectedTimeSpan = new TimeSpan(0, 0, 0, 0, sliderValue);

                uiCurrentTime.Text = selectedTimeSpan.ToString(@"hh\:mm\:ss");
            }));
            uiTimelineSlider.AddHandler(Thumb.DragCompletedEvent, new DragCompletedEventHandler((sender, e) =>
            {
                int sliderValue = (int)uiTimelineSlider.Value;
                storyboard.Seek(uiMedia, new TimeSpan(0, 0, 0, 0, sliderValue), TimeSeekOrigin.BeginTime);

                // Only resume playing if it's in playing mode
                if (currentMediaState == MediaState.IsPlaying)
                {
                    storyboard.Resume(uiMedia);
                }
            }));

            #endregion

            return(uiMediaPlayer);
        }
Esempio n. 17
0
        private TextElement walkBookTreeAndGenerateFlowDocument_audio_video(TreeNode node, TextElement parent, string textMedia)
        {
            //            if (node.Children.Count != 0 || textMedia != null && !String.IsNullOrEmpty(textMedia))
            //            {
            //#if DEBUG
            //                Debugger.Break();
            //#endif
            //                throw new Exception("Node has children or text exists when processing video ??");
            //            }

            XmlProperty xmlProp = node.GetXmlProperty();

            bool isSource = "source".Equals(xmlProp.LocalName, StringComparison.OrdinalIgnoreCase);

            XmlProperty xmlProp_ = xmlProp;

            if (isSource && node.Parent != null)
            {
                xmlProp_ = node.Parent.GetXmlProperty();
            }


            AbstractVideoMedia videoMedia = node.GetVideoMedia();
            var videoMedia_ext            = videoMedia as ExternalVideoMedia;
            var videoMedia_man            = videoMedia as ManagedVideoMedia;


            Media audioMedia     = node.GetMediaInChannel <AudioXChannel>(); // as AbstractAudioMedia;
            var   audioMedia_ext = audioMedia as ExternalAudioMedia;
            var   audioMedia_man = audioMedia as ManagedAudioMedia;



            string dirPath = Path.GetDirectoryName(m_TreeNode.Presentation.RootUri.LocalPath);

            string videoPath = null;

            if (videoMedia_ext != null)
            {
#if DEBUG
                Debugger.Break();
#endif //DEBUG

                videoPath = Path.Combine(dirPath, videoMedia_ext.Src);
            }
            else if (videoMedia_man != null)
            {
#if DEBUG
                XmlAttribute srcAttr = xmlProp.GetAttribute("src");

                DebugFix.Assert(videoMedia_man.VideoMediaData.OriginalRelativePath == FileDataProvider.UriDecode(srcAttr.Value));
#endif //DEBUG
                var fileDataProv = videoMedia_man.VideoMediaData.DataProvider as FileDataProvider;

                if (fileDataProv != null)
                {
                    videoPath = fileDataProv.DataFileFullPath;
                }
            }


            string audioPath = null;

            if (audioMedia_ext != null)
            {
#if DEBUG
                Debugger.Break();
#endif //DEBUG

                audioPath = Path.Combine(dirPath, audioMedia_ext.Src);
            }
            else if (audioMedia_man != null)
            {
#if DEBUG
                XmlAttribute srcAttr = xmlProp.GetAttribute("src");

                DebugFix.Assert(audioMedia_man.AudioMediaData.OriginalRelativePath == FileDataProvider.UriDecode(srcAttr.Value));
#endif //DEBUG
                var fileDataProv = audioMedia_man.AudioMediaData.DataProvider as FileDataProvider;

                if (fileDataProv != null)
                {
                    audioPath = fileDataProv.DataFileFullPath;
                }
            }

            if (
                (videoPath == null || FileDataProvider.isHTTPFile(videoPath))
                &&
                (audioPath == null || FileDataProvider.isHTTPFile(audioPath))
                )
            {
#if DEBUG
                Debugger.Break();
#endif //DEBUG

                return(walkBookTreeAndGenerateFlowDocument_Section(node, parent, textMedia, null));
            }

            string path = string.IsNullOrEmpty(videoPath) ? audioPath : videoPath;

            var uri = new Uri(path, UriKind.Absolute);


            string videoAudioAlt = null;


            XmlAttribute altAttr = xmlProp_.GetAttribute("alt");
            if (altAttr != null)
            {
                videoAudioAlt = altAttr.Value;
            }



            bool parentHasBlocks = parent is TableCell ||
                                   parent is Section ||
                                   parent is Floater ||
                                   parent is Figure ||
                                   parent is ListItem;

            var videoAudioPanel = new StackPanel();
            videoAudioPanel.Orientation = Orientation.Vertical;

            //videoPanel.LastChildFill = true;
            if (!string.IsNullOrEmpty(videoAudioAlt))
            {
                var tb = new TextBlock(new Run(videoAudioAlt))
                {
                    HorizontalAlignment = HorizontalAlignment.Center,
                    TextWrapping        = TextWrapping.Wrap
                };
                videoAudioPanel.Children.Add(tb);
            }
            //videoPanel.Children.Add(mediaElement);


            var slider = new Slider();
            slider.Focusable            = false;
            slider.TickPlacement        = TickPlacement.None;
            slider.IsMoveToPointEnabled = true;
            slider.Minimum    = 0;
            slider.Maximum    = 100;
            slider.Visibility = Visibility.Hidden;

            videoAudioPanel.Children.Add(slider);


            var timeLabel = new TextBlock();
            timeLabel.Focusable = false;
            //timeLabel.IsEnabled = false;
            timeLabel.TextWrapping = TextWrapping.NoWrap;
            //timeLabel.TextTrimming = TextTrimming.None;
            timeLabel.HorizontalAlignment = HorizontalAlignment.Stretch;
            timeLabel.TextAlignment       = TextAlignment.Center;
            timeLabel.Visibility          = Visibility.Hidden;

            videoAudioPanel.Children.Add(timeLabel);

            var playPause = new Button()
            {
                HorizontalAlignment = HorizontalAlignment.Center,
                FontWeight          = FontWeights.Heavy,
                Content             = new Run("Play / Pause")
            };
            //var border_ = new Border()
            //    {
            //        BorderThickness = new Thickness(2.0),
            //        BorderBrush = ColorBrushCache.Get(Settings.Default.Document_Color_Font_NoAudio),
            //        Padding = new Thickness(4),
            //        Child = playPause
            //    };
            videoAudioPanel.Children.Add(playPause);

            videoAudioPanel.HorizontalAlignment = HorizontalAlignment.Stretch;
            videoAudioPanel.VerticalAlignment   = VerticalAlignment.Top;

            var panelBorder = new Border();
            panelBorder.HorizontalAlignment = HorizontalAlignment.Stretch;
            panelBorder.VerticalAlignment   = VerticalAlignment.Top;
            panelBorder.Child           = videoAudioPanel;
            panelBorder.Padding         = new Thickness(4);
            panelBorder.BorderBrush     = ColorBrushCache.Get(Settings.Default.Document_Color_Font_Audio);
            panelBorder.BorderThickness = new Thickness(2.0);


            if (parentHasBlocks)
            {
                Block vidContainer = new BlockUIContainer(panelBorder);
                vidContainer.TextAlignment = TextAlignment.Center;

                setTag(vidContainer, node);

                addBlock(parent, vidContainer);
            }
            else
            {
                Inline vidContainer = new InlineUIContainer(panelBorder);

                setTag(vidContainer, node);

                addInline(parent, vidContainer);
            }


            MediaElement medElement_WINDOWS_MEDIA_PLAYER = null;
#if ENABLE_WPF_MEDIAKIT
            MediaUriElement medElement_MEDIAKIT_DIRECTSHOW = null;
#endif //ENABLE_WPF_MEDIAKIT

            var reh = (Action <object, RoutedEventArgs>)(
                (object obj, RoutedEventArgs rev) =>
            {
#if ENABLE_WPF_MEDIAKIT
                if (Common.Settings.Default.EnableMediaKit)
                {
                    medElement_MEDIAKIT_DIRECTSHOW = new MediaUriElement();
                }
                else
#endif //ENABLE_WPF_MEDIAKIT
                {
                    medElement_WINDOWS_MEDIA_PLAYER = new MediaElement();
                }



#if ENABLE_WPF_MEDIAKIT
                DebugFix.Assert((medElement_WINDOWS_MEDIA_PLAYER == null) == (medElement_MEDIAKIT_DIRECTSHOW != null));
#else  // DISABLE_WPF_MEDIAKIT
                DebugFix.Assert(medElement_WINDOWS_MEDIA_PLAYER != null);
#endif //ENABLE_WPF_MEDIAKIT



                if (medElement_WINDOWS_MEDIA_PLAYER != null)
                {
                    medElement_WINDOWS_MEDIA_PLAYER.Stretch          = Stretch.Uniform;
                    medElement_WINDOWS_MEDIA_PLAYER.StretchDirection = StretchDirection.DownOnly;
                }

#if ENABLE_WPF_MEDIAKIT
                if (medElement_MEDIAKIT_DIRECTSHOW != null)
                {
                    medElement_MEDIAKIT_DIRECTSHOW.Stretch          = Stretch.Uniform;
                    medElement_MEDIAKIT_DIRECTSHOW.StretchDirection = StretchDirection.DownOnly;
                }
#endif //ENABLE_WPF_MEDIAKIT



                FrameworkElement mediaElement = null;
                if (medElement_WINDOWS_MEDIA_PLAYER != null)
                {
                    mediaElement = medElement_WINDOWS_MEDIA_PLAYER;
                }
                else
                {
                    mediaElement = medElement_MEDIAKIT_DIRECTSHOW;
                }

                mediaElement.Focusable = false;

                XmlAttribute srcW = xmlProp_.GetAttribute("width");
                if (srcW != null)
                {
                    var d = parseWidthHeight(srcW.Value);
                    if (d > 0)
                    {
                        mediaElement.Width = d;
                    }
                }
                XmlAttribute srcH = xmlProp_.GetAttribute("height");
                if (srcH != null)
                {
                    var d = parseWidthHeight(srcH.Value);
                    if (d > 0)
                    {
                        mediaElement.Height = d;
                    }
                }

                mediaElement.HorizontalAlignment = HorizontalAlignment.Center;
                mediaElement.VerticalAlignment   = VerticalAlignment.Top;

                if (!string.IsNullOrEmpty(videoAudioAlt))
                {
                    mediaElement.ToolTip = videoAudioAlt;
                }

                videoAudioPanel.Children.Insert(0, mediaElement);

                var actionMediaFailed = new Action <string>(
                    (str) =>
                {
                    m_DocumentPaneView.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
                                                              (Action)(() =>
                    {
                        var label = new TextBlock(new Run(str));

                        label.TextWrapping = TextWrapping.Wrap;
                        //label.Height = 150;

                        var border = new Border();
                        border.Child = label;
                        border.BorderBrush = ColorBrushCache.Get(Colors.Red);
                        border.BorderThickness = new Thickness(2.0);

                        videoAudioPanel.Children.Insert(0, border);

                        slider.Visibility = Visibility.Hidden;
                        timeLabel.Visibility = Visibility.Hidden;
                    }
                                                                       ));
                }
                    );


                Action actionUpdateSliderFromVideoTime = null;
                DispatcherTimer _timer = new DispatcherTimer();
                _timer.Interval = new TimeSpan(0, 0, 0, 0, 500);
                _timer.Stop();
                _timer.Tick += (object oo, EventArgs ee) =>
                {
                    actionUpdateSliderFromVideoTime.Invoke();
                };



                if (medElement_WINDOWS_MEDIA_PLAYER != null)
                {
                    medElement_WINDOWS_MEDIA_PLAYER.ScrubbingEnabled = true;

                    medElement_WINDOWS_MEDIA_PLAYER.LoadedBehavior   = MediaState.Manual;
                    medElement_WINDOWS_MEDIA_PLAYER.UnloadedBehavior = MediaState.Stop;


                    bool doNotUpdateVideoTimeWhenSliderChanges = false;
                    actionUpdateSliderFromVideoTime = new Action(() =>
                    {
                        if (medElement_WINDOWS_MEDIA_PLAYER == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        TimeSpan?timeSpan = medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentTime;
                        double timeMS     = timeSpan != null ? timeSpan.Value.TotalMilliseconds : 0;

                        //Console.WriteLine("UPDATE: " + timeMS);

                        //if (medElement_WINDOWS_MEDIA_PLAYER.NaturalDuration.HasTimeSpan
                        //    && timeMS >= medElement_WINDOWS_MEDIA_PLAYER.NaturalDuration.TimeSpan.TotalMilliseconds - 50)
                        //{
                        //    medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Stop();
                        //}

                        doNotUpdateVideoTimeWhenSliderChanges = true;
                        slider.Value = timeMS;
                    });

                    medElement_WINDOWS_MEDIA_PLAYER.MediaFailed += new EventHandler <ExceptionRoutedEventArgs>(
                        (oo, ee) =>
                    {
                        //#if DEBUG
                        //                                Debugger.Break();
                        //#endif //DEBUG
                        //medElement_WINDOWS_MEDIA_PLAYER.Source
                        actionMediaFailed.Invoke(uri.ToString()
                                                 + " \n("
                                                 + (ee.ErrorException != null ? ee.ErrorException.Message : "ERROR!")
                                                 + ")");
                    }
                        );



                    medElement_WINDOWS_MEDIA_PLAYER.MediaOpened += new RoutedEventHandler(
                        (oo, ee) =>
                    {
                        if (medElement_WINDOWS_MEDIA_PLAYER == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        slider.Visibility    = Visibility.Visible;
                        timeLabel.Visibility = Visibility.Visible;

                        double durationMS = medElement_WINDOWS_MEDIA_PLAYER.NaturalDuration.TimeSpan.TotalMilliseconds;
                        timeLabel.Text    = Time.Format_Standard(medElement_WINDOWS_MEDIA_PLAYER.NaturalDuration.TimeSpan);

                        slider.Maximum = durationMS;


                        // freeze frame (poster)
                        if (medElement_WINDOWS_MEDIA_PLAYER.LoadedBehavior == MediaState.Manual)
                        {
                            medElement_WINDOWS_MEDIA_PLAYER.IsMuted = true;

                            medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Begin();
                            medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Pause();

                            medElement_WINDOWS_MEDIA_PLAYER.IsMuted = false;

                            slider.Value = 0.10;
                        }
                    }
                        );



                    medElement_WINDOWS_MEDIA_PLAYER.MediaEnded +=
                        new RoutedEventHandler(
                            (oo, ee) =>
                    {
                        if (medElement_WINDOWS_MEDIA_PLAYER == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        _timer.Stop();

                        medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Stop();

                        actionUpdateSliderFromVideoTime.Invoke();
                    }
                            );

                    var mouseButtonEventHandler_WINDOWS_MEDIA_PLAYER = new Action(
                        () =>
                    {
                        if (medElement_WINDOWS_MEDIA_PLAYER == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        if (medElement_WINDOWS_MEDIA_PLAYER.LoadedBehavior != MediaState.Manual)
                        {
                            return;
                        }

                        bool wasPlaying = false;
                        bool wasStopped = false;

                        //Is Active
                        if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentState == ClockState.Active)
                        {
                            //Is Paused
                            if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentGlobalSpeed == 0.0)
                            {
                            }
                            else             //Is Playing
                            {
                                wasPlaying = true;
                                medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Pause();
                            }
                        }
                        else if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentState == ClockState.Stopped)
                        {
                            wasStopped = true;
                            //medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Begin();
                            //medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Pause();
                        }

                        double durationMS = medElement_WINDOWS_MEDIA_PLAYER.NaturalDuration.TimeSpan.TotalMilliseconds;
                        double timeMS     =
                            medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentTime == null ||
                            !medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentTime.HasValue
                                        ? -1.0
                                        : medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentTime.Value.TotalMilliseconds;

                        if (timeMS == -1.0 || timeMS >= durationMS)
                        {
                            slider.Value = 0.100;
                        }

                        if (!wasPlaying)
                        {
                            _timer.Start();
                            if (wasStopped)
                            {
                                medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Begin();
                            }
                            else
                            {
                                medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Resume();
                            }
                        }
                        else
                        {
                            _timer.Stop();
                            medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Pause();
                            actionUpdateSliderFromVideoTime.Invoke();
                        }

                        //if (ee.ChangedButton == MouseButton.Left)
                        //{
                        //}
                        //else if (ee.ChangedButton == MouseButton.Right)
                        //{
                        //    _timer.Stop();

                        //    //Is Active
                        //    if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentState == ClockState.Active)
                        //    {
                        //        //Is Paused
                        //        if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentGlobalSpeed == 0.0)
                        //        {

                        //        }
                        //        else //Is Playing
                        //        {
                        //            medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Pause();
                        //        }
                        //    }
                        //    else if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentState == ClockState.Stopped)
                        //    {
                        //        medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Begin();
                        //        medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Pause();
                        //    }

                        //    //actionRefreshTime.Invoke();
                        //    slider.Value = 0;
                        //}
                    }
                        );
                    medElement_WINDOWS_MEDIA_PLAYER.MouseDown +=
                        new MouseButtonEventHandler((oo, ee) => mouseButtonEventHandler_WINDOWS_MEDIA_PLAYER());
                    playPause.Click += new RoutedEventHandler((object sender, RoutedEventArgs e) => mouseButtonEventHandler_WINDOWS_MEDIA_PLAYER());

                    slider.ValueChanged += new RoutedPropertyChangedEventHandler <double>(
                        (oo, ee) =>
                    {
                        if (medElement_WINDOWS_MEDIA_PLAYER == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        var timeSpan = new TimeSpan(0, 0, 0, 0, (int)Math.Round(slider.Value));

                        if (doNotUpdateVideoTimeWhenSliderChanges || !_timer.IsEnabled)
                        {
                            double durationMS = medElement_WINDOWS_MEDIA_PLAYER.NaturalDuration.TimeSpan.TotalMilliseconds;

                            timeLabel.Text = String.Format(
                                "{0} / {1}",
                                Time.Format_Standard(timeSpan),
                                Time.Format_Standard(medElement_WINDOWS_MEDIA_PLAYER.NaturalDuration.TimeSpan)
                                );
                        }

                        if (doNotUpdateVideoTimeWhenSliderChanges)
                        {
                            doNotUpdateVideoTimeWhenSliderChanges = false;
                            return;
                        }

                        bool wasPlaying = false;

                        //Is Active
                        if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentState == ClockState.Active)
                        {
                            //Is Paused
                            if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentGlobalSpeed == 0.0)
                            {
                            }
                            else         //Is Playing
                            {
                                wasPlaying = true;
                                medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Pause();
                            }
                        }
                        else if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentState == ClockState.Stopped)
                        {
                            medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Begin();
                            medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Pause();
                        }

                        medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Seek(timeSpan, TimeSeekOrigin.BeginTime);

                        if (wasPlaying)
                        {
                            medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Resume();
                        }
                    });

                    bool wasPlayingBeforeDrag = false;
                    slider.AddHandler(Thumb.DragStartedEvent,
                                      new DragStartedEventHandler(
                                          (Action <object, DragStartedEventArgs>)(
                                              (oo, ee) =>
                    {
                        if (medElement_WINDOWS_MEDIA_PLAYER == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        wasPlayingBeforeDrag = false;

                        //Is Active
                        if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentState == ClockState.Active)
                        {
                            //Is Paused
                            if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentGlobalSpeed == 0.0)
                            {
                            }
                            else         //Is Playing
                            {
                                wasPlayingBeforeDrag = true;
                                medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Pause();
                            }
                        }
                        else if (medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentState == ClockState.Stopped)
                        {
                            medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Begin();
                            medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Pause();
                        }
                    })));

                    slider.AddHandler(Thumb.DragCompletedEvent,
                                      new DragCompletedEventHandler(
                                          (Action <object, DragCompletedEventArgs>)(
                                              (oo, ee) =>
                    {
                        if (medElement_WINDOWS_MEDIA_PLAYER == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        if (wasPlayingBeforeDrag)
                        {
                            medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Resume();
                        }
                        wasPlayingBeforeDrag = false;
                    })));
                }



#if ENABLE_WPF_MEDIAKIT
                if (medElement_MEDIAKIT_DIRECTSHOW != null)
                {
                    bool doNotUpdateVideoTimeWhenSliderChanges = false;
                    actionUpdateSliderFromVideoTime = new Action(() =>
                    {
                        if (medElement_MEDIAKIT_DIRECTSHOW == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }
                        long timeVideo = medElement_MEDIAKIT_DIRECTSHOW.MediaPosition;

                        //if (timeMS >= medElement_MEDIAKIT_DIRECTSHOW.MediaDuration - 50 * 10000.0)
                        //{
                        //    medElement_MEDIAKIT_DIRECTSHOW.Stop();
                        //}


                        double timeMS = timeVideo / 10000.0;

                        //Console.WriteLine("UPDATE: " + timeMS);

                        doNotUpdateVideoTimeWhenSliderChanges = true;
                        slider.Value = timeMS;
                    });


                    medElement_MEDIAKIT_DIRECTSHOW.MediaFailed += new EventHandler <WPFMediaKit.DirectShow.MediaPlayers.MediaFailedEventArgs>(
                        (oo, ee) =>
                    {
                        //#if DEBUG
                        //                        Debugger.Break();
                        //#endif //DEBUG

                        //medElement_MEDIAKIT_DIRECTSHOW.Source
                        actionMediaFailed.Invoke(uri.ToString()
                                                 + " \n("
                                                 + (ee.Exception != null ? ee.Exception.Message : ee.Message)
                                                 + ")");
                    }
                        );



                    medElement_MEDIAKIT_DIRECTSHOW.MediaOpened += new RoutedEventHandler(
                        (oo, ee) =>
                    {
                        if (medElement_MEDIAKIT_DIRECTSHOW == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        long durationVideo = medElement_MEDIAKIT_DIRECTSHOW.MediaDuration;
                        if (durationVideo == 0)
                        {
                            return;
                        }

                        //MediaPositionFormat mpf = medElement.CurrentPositionFormat;
                        //MediaPositionFormat.MediaTime
                        double durationMS = durationVideo / 10000.0;


                        slider.Visibility    = Visibility.Visible;
                        timeLabel.Visibility = Visibility.Visible;

                        slider.Maximum = durationMS;

                        var durationTimeSpan = new TimeSpan(0, 0, 0, 0, (int)Math.Round(durationMS));
                        timeLabel.Text       = Time.Format_Standard(durationTimeSpan);


                        // freeze frame (poster)
                        if (medElement_MEDIAKIT_DIRECTSHOW.LoadedBehavior == WPFMediaKit.DirectShow.MediaPlayers.MediaState.Manual)
                        {
                            if (false)
                            {
                                double volume = medElement_MEDIAKIT_DIRECTSHOW.Volume;
                                medElement_MEDIAKIT_DIRECTSHOW.Volume = 0;

                                medElement_MEDIAKIT_DIRECTSHOW.Play();
                                slider.Value = 0.10;
                                medElement_MEDIAKIT_DIRECTSHOW.Pause();

                                medElement_MEDIAKIT_DIRECTSHOW.Volume = volume;
                            }
                            else
                            {
                                medElement_MEDIAKIT_DIRECTSHOW.Pause();
                                slider.Value = 0.10;
                            }
                        }
                    }
                        );



                    medElement_MEDIAKIT_DIRECTSHOW.MediaEnded +=
                        new RoutedEventHandler(
                            (oo, ee) =>
                    {
                        if (medElement_MEDIAKIT_DIRECTSHOW == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        _timer.Stop();
                        medElement_MEDIAKIT_DIRECTSHOW.Pause();
                        actionUpdateSliderFromVideoTime.Invoke();

                        // TODO: BaseClasses.cs in WPF Media Kit,
                        // MediaPlayerBase.OnMediaEvent
                        // ==> remove StopGraphPollTimer();
                        // in case EventCode.Complete.


                        //m_DocumentPaneView.Dispatcher.BeginInvoke(
                        //    DispatcherPriority.Background,
                        //    (Action)(() =>
                        //    {
                        //        //medElement_MEDIAKIT_DIRECTSHOW.BeginInit();
                        //        medElement_MEDIAKIT_DIRECTSHOW.Source = uri;
                        //        //medElement_MEDIAKIT_DIRECTSHOW.EndInit();
                        //    })
                        //    );
                    }
                            );


                    medElement_MEDIAKIT_DIRECTSHOW.MediaClosed +=
                        new RoutedEventHandler(
                            (oo, ee) =>
                    {
                        int debug = 1;
                    }
                            );

                    var mouseButtonEventHandler_MEDIAKIT_DIRECTSHOW = new Action(
                        () =>
                    {
                        if (medElement_MEDIAKIT_DIRECTSHOW == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        if (medElement_MEDIAKIT_DIRECTSHOW.LoadedBehavior != WPFMediaKit.DirectShow.MediaPlayers.MediaState.Manual)
                        {
                            return;
                        }

                        if (medElement_MEDIAKIT_DIRECTSHOW.IsPlaying)
                        {
                            _timer.Stop();
                            medElement_MEDIAKIT_DIRECTSHOW.Pause();
                            actionUpdateSliderFromVideoTime.Invoke();
                        }
                        else
                        {
                            _timer.Start();
                            medElement_MEDIAKIT_DIRECTSHOW.Play();
                        }


                        double durationMS = medElement_MEDIAKIT_DIRECTSHOW.MediaDuration / 10000.0;
                        double timeMS     = medElement_MEDIAKIT_DIRECTSHOW.MediaPosition / 10000.0;

                        if (timeMS >= durationMS)
                        {
                            slider.Value = 0.100;
                        }

                        //if (ee.ChangedButton == MouseButton.Left)
                        //{
                        //}
                        //else if (ee.ChangedButton == MouseButton.Right)
                        //{
                        //    _timer.Stop();
                        //    medElement_MEDIAKIT_DIRECTSHOW.Pause();
                        //    //actionRefreshTime.Invoke();
                        //    slider.Value = 0;
                        //}
                    }
                        );
                    medElement_MEDIAKIT_DIRECTSHOW.MouseDown +=
                        new MouseButtonEventHandler((oo, ee) => mouseButtonEventHandler_MEDIAKIT_DIRECTSHOW());
                    playPause.Click += new RoutedEventHandler((object sender, RoutedEventArgs e) => mouseButtonEventHandler_MEDIAKIT_DIRECTSHOW());

                    slider.ValueChanged += new RoutedPropertyChangedEventHandler <double>(
                        (oo, ee) =>
                    {
                        if (medElement_MEDIAKIT_DIRECTSHOW == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        double timeMs = slider.Value;

                        if (doNotUpdateVideoTimeWhenSliderChanges || !_timer.IsEnabled)
                        {
                            var timeSpan = new TimeSpan(0, 0, 0, 0, (int)Math.Round(timeMs));

                            double durationMS = medElement_MEDIAKIT_DIRECTSHOW.MediaDuration / 10000.0;

                            //MediaPositionFormat.MediaTime
                            //MediaPositionFormat mpf = medElement.CurrentPositionFormat;

                            timeLabel.Text = String.Format(
                                "{0} / {1}",
                                Time.Format_Standard(timeSpan),
                                Time.Format_Standard(new TimeSpan(0, 0, 0, 0, (int)Math.Round(durationMS)))
                                );
                        }

                        if (doNotUpdateVideoTimeWhenSliderChanges)
                        {
                            doNotUpdateVideoTimeWhenSliderChanges = false;
                            return;
                        }

                        bool wasPlaying = medElement_MEDIAKIT_DIRECTSHOW.IsPlaying;

                        if (wasPlaying)
                        {
                            medElement_MEDIAKIT_DIRECTSHOW.Pause();
                        }

                        long timeVideo = (long)Math.Round(timeMs * 10000.0);
                        medElement_MEDIAKIT_DIRECTSHOW.MediaPosition = timeVideo;

                        DebugFix.Assert(medElement_MEDIAKIT_DIRECTSHOW.MediaPosition == timeVideo);

                        if (wasPlaying)
                        {
                            medElement_MEDIAKIT_DIRECTSHOW.Play();
                        }
                    });

                    bool wasPlayingBeforeDrag = false;
                    slider.AddHandler(Thumb.DragStartedEvent,
                                      new DragStartedEventHandler(
                                          (Action <object, DragStartedEventArgs>)(
                                              (oo, ee) =>
                    {
                        if (medElement_MEDIAKIT_DIRECTSHOW == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        wasPlayingBeforeDrag = medElement_MEDIAKIT_DIRECTSHOW.IsPlaying;

                        if (wasPlayingBeforeDrag)
                        {
                            medElement_MEDIAKIT_DIRECTSHOW.Pause();
                        }
                    })));


                    slider.AddHandler(Thumb.DragCompletedEvent,
                                      new DragCompletedEventHandler(
                                          (Action <object, DragCompletedEventArgs>)(
                                              (oo, ee) =>
                    {
                        if (medElement_MEDIAKIT_DIRECTSHOW == null)
                        {
#if DEBUG
                            Debugger.Break();
#endif
                            return;
                        }

                        if (wasPlayingBeforeDrag)
                        {
                            medElement_MEDIAKIT_DIRECTSHOW.Play();
                        }
                        wasPlayingBeforeDrag = false;
                    })));

                    //DependencyPropertyDescriptor dpd = DependencyPropertyDescriptor.FromProperty(
                    //    MediaSeekingElement.MediaPositionProperty,
                    //    typeof(MediaSeekingElement));
                    //if (dpd != null)
                    //{
                    //    dpd.AddValueChanged(medElement_MEDIAKIT_DIRECTSHOW, new EventHandler((o, e) =>
                    //    {
                    //        //actionRefreshTime.Invoke();

                    //        //if (!_timer.IsEnabled)
                    //        //{
                    //        //    _timer.Start();
                    //        //}
                    //    }));
                    //}
                }
#endif //ENABLE_WPF_MEDIAKIT


                if (medElement_WINDOWS_MEDIA_PLAYER != null)
                {
                    var timeline = new MediaTimeline();
                    timeline.Source = uri;

                    medElement_WINDOWS_MEDIA_PLAYER.Clock = timeline.CreateClock(true) as MediaClock;

                    medElement_WINDOWS_MEDIA_PLAYER.Clock.Controller.Stop();

                    //medElement_WINDOWS_MEDIA_PLAYER.Clock.CurrentTimeInvalidated += new EventHandler(
                    //(o, e) =>
                    //{
                    //    //actionRefreshTime.Invoke();
                    //    //if (!_timer.IsEnabled)
                    //    //{
                    //    //    _timer.Start();
                    //    //}
                    //});
                }

#if ENABLE_WPF_MEDIAKIT
                if (medElement_MEDIAKIT_DIRECTSHOW != null)
                {
                    medElement_MEDIAKIT_DIRECTSHOW.BeginInit();

                    medElement_MEDIAKIT_DIRECTSHOW.Loop          = false;
                    medElement_MEDIAKIT_DIRECTSHOW.VideoRenderer = VideoRendererType.VideoMixingRenderer9;

                    // seems to be a multiplicator of 10,000 to get milliseconds
                    medElement_MEDIAKIT_DIRECTSHOW.PreferedPositionFormat = MediaPositionFormat.MediaTime;


                    medElement_MEDIAKIT_DIRECTSHOW.LoadedBehavior   = WPFMediaKit.DirectShow.MediaPlayers.MediaState.Manual;
                    medElement_MEDIAKIT_DIRECTSHOW.UnloadedBehavior = WPFMediaKit.DirectShow.MediaPlayers.MediaState.Stop;

                    try
                    {
                        medElement_MEDIAKIT_DIRECTSHOW.Source = uri;

                        medElement_MEDIAKIT_DIRECTSHOW.EndInit();
                    }
                    catch (Exception ex)
                    {
#if DEBUG
                        Debugger.Break();
#endif //DEBUG
                        ;     // swallow (reported in MediaFailed)
                    }
                }
#endif //ENABLE_WPF_MEDIAKIT
            });

            FlowDocumentLoadedEvents.Add(reh);
            m_FlowDoc.Loaded += new RoutedEventHandler(reh);



            var reh2 = (Action <object, RoutedEventArgs>)(
                (object o, RoutedEventArgs e) =>
            {
                bool thereWasOne = false;
                if (medElement_WINDOWS_MEDIA_PLAYER != null)
                {
                    thereWasOne = true;
                    medElement_WINDOWS_MEDIA_PLAYER.Close();
                    medElement_WINDOWS_MEDIA_PLAYER = null;
                }

#if ENABLE_WPF_MEDIAKIT
                if (medElement_MEDIAKIT_DIRECTSHOW != null)
                {
                    thereWasOne = true;
                    medElement_MEDIAKIT_DIRECTSHOW.Close();
                    medElement_MEDIAKIT_DIRECTSHOW = null;
                }
#endif //ENABLE_WPF_MEDIAKIT

                if (thereWasOne)
                {
                    videoAudioPanel.Children.RemoveAt(0);
                }
            });

            FlowDocumentUnLoadedEvents.Add(reh2);
            m_FlowDoc.Unloaded += new RoutedEventHandler(reh2);


            return(parent);
        }
Esempio n. 18
0
        void IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                mediaPlayer = (MediaElement)target;
                break;

            case 2:
                img_animation = (Image)target;
                break;

            case 3:
                HeaderDP = (DockPanel)target;
                break;

            case 4:
                btnClose = (Image)target;
                break;

            case 5:
                btnSync = (Image)target;
                break;

            case 6:
                cbBooks = (System.Windows.Controls.ComboBox)target;
                break;

            case 7:
                btnLight = (Image)target;
                break;

            case 8:
                FooterDP = (DockPanel)target;
                break;

            case 9:
                btnFunction = (Image)target;
                break;

            case 10:
                txtCurrentTime = (TextBlock)target;
                break;

            case 11:
                txtEndTime = (TextBlock)target;
                break;

            case 12:
                pb = (System.Windows.Controls.ProgressBar)target;
                break;

            case 13:
                SeekBar = (Slider)target;
                SeekBar.AddHandler(Thumb.DragStartedEvent, new DragStartedEventHandler(SeekBar_DragStarted));
                SeekBar.AddHandler(Thumb.DragCompletedEvent, new DragCompletedEventHandler(SeekBar_DragCompleted));
                break;

            default:
                _contentLoaded = true;
                break;
            }
        }
Esempio n. 19
0
        public MainWindow()
        {
            InitializeComponent();

            //this.Title += string.Format(" v{0}.{1}.{2}", System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Major, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Minor, System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.Build);

            if (System.Deployment.Application.ApplicationDeployment.IsNetworkDeployed)
            {
                this.Title += "ver " +
                              System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.Major.ToString() + "." +
                              System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVersion.Revision.ToString();
            }

            handle = this.DataContext as XenaxStageGUIControlVM;
            DebounceTimer.Interval = TimeSpan.FromMilliseconds(50);
            crosshairWindow.handle = handle;

            handle.xenaxDeviceConnectionsVM = xenax1.xenaxDeviceConnections;
            this.dgConnections.DataContext  = xenax1.xenaxDeviceConnections;

            //Add additional handler to sliders
            object wantedNode = this.FindName("slManualRotation");

            if (wantedNode is Slider)
            {
                // Following executed if Text element was found.
                Slider wantedChild = wantedNode as Slider;

                wantedChild.AddHandler(PreviewMouseUpEvent,
                                       new RoutedEventHandler(SlManualRotation_MouseUp),
                                       true);

                wantedChild.AddHandler(PreviewMouseDownEvent,
                                       new RoutedEventHandler(SlManualRotation_MouseDown),
                                       true);

                wantedChild.AddHandler(MouseLeaveEvent,
                                       new RoutedEventHandler(SlManualRotation_MouseLeave),
                                       true);

                wantedChild.AddHandler(Slider.ValueChangedEvent,
                                       new RoutedEventHandler(SlManualRotation_ValueChanged),
                                       true);

                wantedChild.AddHandler(Slider.DragLeaveEvent,
                                       new DragEventHandler(SlManualRotation_DragLeave),
                                       true);
            }

            object wantedNode2 = this.FindName("slPositionLin");

            if (wantedNode is Slider)
            {
                // Following executed if Text element was found.
                Slider wantedChild = wantedNode2 as Slider;

                wantedChild.AddHandler(PreviewMouseDownEvent,
                                       new RoutedEventHandler(SlPositionLin_MouseDown),
                                       true);
            }

            xenax1.ConnectionUpdate        += Xenax_ConnectionUpdate;
            xenax1.MotorStatusUpdate       += Xenax1_MotorStatusUpdate;
            xenax1.PositionVelocityUpdated += Xenax_PositionSpeedAccUpdated;
            xenax1.PositionReached         += Xenax_PositionReached;

            xenax1.DataReceived += Xenax1_DataReceived;
            xenax1.DataSent     += Xenax1_DataSent;

            currentPositionTimer.Tick    += CurrentPositionTimer_Tick;
            currentPositionTimer.Interval = TimeSpan.FromMilliseconds(250);
        }
Esempio n. 20
0
        void IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                l = (Grid)target;
                break;

            case 2:
                m                    = (MediaElement)target;
                m.MediaOpened       += new RoutedEventHandler(d);
                m.MouseLeftButtonUp += new MouseButtonEventHandler(a);
                break;

            case 3:
                n = (StackPanel)target;
                break;

            case 4:
                o = (StackPanel)target;
                break;

            case 5:
                p = (Slider)target;
                p.AddHandler(Thumb.DragStartedEvent, new DragStartedEventHandler(a));
                p.AddHandler(Thumb.DragCompletedEvent, new DragCompletedEventHandler(a));
                break;

            case 6:
                q        = (ToggleButton)target;
                q.Click += new RoutedEventHandler(b);
                break;

            case 7:
                r        = (ToggleButton)target;
                r.Click += new RoutedEventHandler(a);
                break;

            case 8:
                s        = (System.Windows.Controls.Button)target;
                s.Click += new RoutedEventHandler(j);
                break;

            case 9:
                t = (Image)target;
                break;

            case 10:
                u        = (System.Windows.Controls.Button)target;
                u.Click += new RoutedEventHandler(i);
                break;

            case 11:
                v        = (System.Windows.Controls.Button)target;
                v.Click += new RoutedEventHandler(g);
                break;

            case 12:
                w        = (System.Windows.Controls.Button)target;
                w.Click += new RoutedEventHandler(h);
                break;

            case 13:
                x = (Slider)target;
                break;

            default:
                y = true;
                break;
            }
        }
Esempio n. 21
0
 public MainPage()
 {
     InitializeComponent();
     Slider.AddHandler(PointerPressedEvent, new PointerEventHandler(Slider_OnPointerPressed), true);
     Slider.AddHandler(PointerReleasedEvent, new PointerEventHandler(Slider_OnPointerReleased), true);
 }
Esempio n. 22
0
        void IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                LayoutRoot = (Grid)target;
                break;

            case 2:
                MediaEL                    = (MediaElement)target;
                MediaEL.MediaOpened       += new RoutedEventHandler(MediaEL_MediaOpened);
                MediaEL.MouseLeftButtonUp += new MouseButtonEventHandler(MediaEL_MouseLeftButtonUp);
                break;

            case 3:
                controlPanel = (StackPanel)target;
                break;

            case 4:
                SPSeekBar = (StackPanel)target;
                break;

            case 5:
                seekBar = (Slider)target;
                seekBar.AddHandler(Thumb.DragStartedEvent, new DragStartedEventHandler(seekBar_DragStarted));
                seekBar.AddHandler(Thumb.DragCompletedEvent, new DragCompletedEventHandler(seekBar_DragCompleted));
                break;

            case 6:
                btnPlay        = (Button)target;
                btnPlay.Click += new RoutedEventHandler(btnPlay_Click);
                break;

            case 7:
                pause = (Image)target;
                break;

            case 8:
                btnStop        = (Button)target;
                btnStop.Click += new RoutedEventHandler(btnStop_Click);
                break;

            case 9:
                btnMoveBackward        = (Button)target;
                btnMoveBackward.Click += new RoutedEventHandler(btnMoveBackward_Click);
                break;

            case 10:
                btnMoveForward        = (Button)target;
                btnMoveForward.Click += new RoutedEventHandler(btnMoveForward_Click);
                break;

            case 11:
                volumeSlider = (Slider)target;
                break;

            default:
                _contentLoaded = true;
                break;
            }
        }
Esempio n. 23
0
        void IComponentConnector.Connect(int connectionId, object target)
        {
            switch (connectionId)
            {
            case 1:
                this.g = (Grid)target;
                break;

            case 2:
                h                    = (MediaElement)target;
                h.MediaOpened       += new RoutedEventHandler(a);
                h.MouseLeftButtonUp += new MouseButtonEventHandler(a);
                break;

            case 3:
                i = (StackPanel)target;
                break;

            case 4:
                j = (StackPanel)target;
                break;

            case 5:
                k = (Slider)target;
                k.AddHandler(Thumb.DragStartedEvent, new DragStartedEventHandler(a));
                k.AddHandler(Thumb.DragCompletedEvent, new DragCompletedEventHandler(a));
                break;

            case 6:
                l        = (System.Windows.Controls.Button)target;
                l.Click += new RoutedEventHandler(g);
                break;

            case 7:
                m = (Image)target;
                break;

            case 8:
                n        = (System.Windows.Controls.Button)target;
                n.Click += new RoutedEventHandler(f);
                break;

            case 9:
                o        = (System.Windows.Controls.Button)target;
                o.Click += new RoutedEventHandler(d);
                break;

            case 10:
                p        = (System.Windows.Controls.Button)target;
                p.Click += new RoutedEventHandler(e);
                break;

            case 11:
                q = (Slider)target;
                break;

            default:
                r = true;
                break;
            }
        }