Пример #1
0
 protected override void OnElementChanged(ElementChangedEventArgs <Slider> e)
 {
     base.OnElementChanged(e);
     element = (BufferSlider)this.Element;
     if (Control == null || element == null)
     {
         return;
     }
     SetSliderColorAndThumb();
 }
Пример #2
0
 protected override void OnElementChanged(ElementChangedEventArgs <Slider> e)
 {
     base.OnElementChanged(e);
     element = (BufferSlider)this.Element;
     if (Control == null || element == null)
     {
         return;
     }
     Control.Continuous     = false;
     Control.TouchUpInside += Control_TouchUpInside;
     SetSliderColorAndThumb();
 }
Пример #3
0
        private void InitlializeTimelineControls()
        {
            timelineBar = new BufferSlider()
            {
                Minimum = 0, Value = 0, Maximum = 100,
            };
            timelineBar.ValueChanged  += OnVideoTimelineSliderValueChanged;
            timelineBar.StopedDraging += (sender, e) => {
                var tt = e;
            };
            bufferingSlider = new BufferSlider()
            {
                Minimum = 0,
                Value   = 0,
                Maximum = 100,
                IsSliderThumbVisible = false,
            };

            var btnPlay = new Button
            {
                WidthRequest    = 40,
                BackgroundColor = Color.Transparent,
                FontSize        = 20,
                TextColor       = Color.White,
                FontFamily      = "FontAwesome",
                Text            = FontAwesome.FAPlay
            };

            btnPlay.SetBinding(Button.TextProperty, "IsPlaying", converter: new BoolToTextConverter(FontAwesome.FAPause, FontAwesome.FAPlay));
            btnPlay.Clicked += delegate { Play(); };

            var btnSound = new Button
            {
                WidthRequest    = 40,
                FontSize        = 20,
                TextColor       = Color.White,
                FontFamily      = "FontAwesome",
                Text            = FontAwesome.FAVolumeUp,
                BackgroundColor = Color.Transparent,
            };

            btnSound.Clicked += OnButtonSoundClicked;
            btnSound.SetBinding(Button.TextProperty, "IsMute", converter: new BoolToTextConverter(FontAwesome.FAVolumeOff, FontAwesome.FAVolumeUp));

            var lblCurrentPosition = new Label()
            {
                Text              = "00:00",
                Margin            = new Thickness(10, 0, 0, 0),
                TextColor         = Color.White,
                HorizontalOptions = LayoutOptions.StartAndExpand
            };
            string format = model.Duration > TimeSpan.FromHours(1) ? "{0:hh\\:mm\\:ss}" : "{0:mm\\:ss}";

            lblCurrentPosition.SetBinding(Label.TextProperty, "CurrentPosition", stringFormat: format);

            var lblDuration = new Label()
            {
                Text              = "00:00",
                Margin            = new Thickness(0, 0, 10, 0),
                TextColor         = Color.White,
                HorizontalOptions = LayoutOptions.EndAndExpand
            };

            lblDuration.SetBinding(Label.TextProperty, "Duration", stringFormat: format);

            var btnFullScreen = new Button()
            {
                WidthRequest    = 40,
                FontSize        = 20,
                TextColor       = Color.White,
                FontFamily      = "FontAwesome",
                Text            = FontAwesome.FAExpand,
                BackgroundColor = Color.Transparent,
            };

            btnFullScreen.SetBinding(Button.TextProperty, "IsFullScreen", converter: new BoolToTextConverter(FontAwesome.FAExpand, FontAwesome.FACompress));
            btnFullScreen.Clicked += OnButtonFullScreenClicked;

            var btnStepForward = new Button()
            {
                WidthRequest    = 40,
                FontSize        = 20,
                TextColor       = Color.White,
                FontFamily      = "FontAwesome",
                Text            = FontAwesome.FAStepForward,
                BackgroundColor = Color.Transparent,
            };

            btnStepForward.SetBinding(Button.IsEnabledProperty, "HasNext");
            btnStepForward.Clicked += OnButtonStepForwardClicked;

            var btnStepBackward = new Button()
            {
                WidthRequest    = 40,
                FontSize        = 20,
                TextColor       = Color.White,
                FontFamily      = "FontAwesome",
                Text            = FontAwesome.FAStepBackward,
                BackgroundColor = Color.Transparent,
            };

            btnStepBackward.SetBinding(Button.IsEnabledProperty, "HasPrev");
            btnStepBackward.Clicked += OnButtonStepBackwardClicked;


            var gridTimeline = new Grid
            {
                RowSpacing      = 0,
                BackgroundColor = Color.FromHex("75000000"),
                VerticalOptions = LayoutOptions.EndAndExpand,
                RowDefinitions  = new RowDefinitionCollection()
                {
                    // Seekbar
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    // Duration
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                    // Media Controls
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                }
            };

            gridTimeline.SetBinding(IsVisibleProperty, "DisplaySeekbar");

            // Seekbar
            gridTimeline.Children.Add(bufferingSlider, 0, 5, 0, 1);
            gridTimeline.Children.Add(timelineBar, 0, 5, 0, 1);
            // Duration
            gridTimeline.Children.Add(lblCurrentPosition, 0, 2, 1, 2);
            gridTimeline.Children.Add(lblDuration, 3, 5, 1, 2);
            // Media Controls
            gridTimeline.Children.Add(btnSound, 0, 1, 2, 3);
            gridTimeline.Children.Add(btnStepBackward, 1, 2, 2, 3);
            //  gridTimeline.Children.Add(loader, 2, 3, 2, 3);
            gridTimeline.Children.Add(btnPlay, 2, 3, 2, 3);
            gridTimeline.Children.Add(btnStepForward, 3, 4, 2, 3);
            gridTimeline.Children.Add(btnFullScreen, 4, 5, 2, 3);

            Children.Add(gridTimeline, 0, 0);
        }
Пример #4
0
        private void SetAudioPlayerView()
        {
            audioView = new Grid
            {
                BackgroundColor = Color.FromHex("#bcbaba"),
                RowDefinitions  = new RowDefinitionCollection()
                {
                    new RowDefinition {
                        Height = new GridLength(1, GridUnitType.Star)
                    },
                    new RowDefinition {
                        Height = 100
                    }
                }
            };

            lblFileName = new Label()
            {
                Margin                  = new Thickness(15, 0),
                LineBreakMode           = LineBreakMode.MiddleTruncation,
                TextColor               = Color.FromHex("605e5e"),
                HorizontalOptions       = LayoutOptions.FillAndExpand,
                HorizontalTextAlignment = TextAlignment.Center
            };


            audioPlayer = DependencyService.Get <IAudioPlayer>(DependencyFetchTarget.NewInstance);
            audioPlayer.SeekPositionChanged     += AudioPlayer_SeekPositionChanged;
            audioPlayer.Completed               += AudioPlayer_Completed;
            audioPlayer.BuffringPositionChanged += AudioPlayer_BuffringPositionChanged;
            audioPlayer.SetDuration             += AudioPlayer_SetDuration;

            loader = new ActivityIndicator();

            btnPlay = new Button
            {
                WidthRequest    = 40,
                BackgroundColor = Color.Transparent,
                FontSize        = 20,
                TextColor       = Color.FromHex("#424242"),
                FontFamily      = "FontAwesome",
                Text            = FontAwesome.FAPlay,
                VerticalOptions = LayoutOptions.StartAndExpand,
            };
            btnPlay.Clicked += BtnPlay_Clicked;

            audioSlider = new BufferSlider()
            {
                Minimum = 0,
                Value   = 0,
                Maximum = 100,
            };
            audioSlider.ValueChanged += AudioSlider_ValueChanged;

            bufferingSlider = new BufferSlider()
            {
                Minimum = 0,
                Value   = 0,
                Maximum = 100,
                IsSliderThumbVisible = false,
            };

            lblCurrentPosition = new Label()
            {
                Text = "00:00", Margin = new Thickness(10, 0, 0, 0), TextColor = Color.FromHex("605e5e"), HorizontalOptions = LayoutOptions.StartAndExpand
            };
            lblDuration = new Label()
            {
                Text = "00:00", Margin = new Thickness(0, 0, 10, 0), TextColor = Color.FromHex("605e5e"), HorizontalOptions = LayoutOptions.EndAndExpand
            };

            btnStepForward = new Button()
            {
                WidthRequest    = 40,
                FontSize        = 20,
                TextColor       = Color.FromHex("#424242"),
                FontFamily      = "FontAwesome",
                Text            = FontAwesome.FAStepForward,
                BackgroundColor = Color.Transparent,
            };
            btnStepForward.Clicked += BtnStepForward_Clicked;

            btnStepBackward = new Button()
            {
                WidthRequest    = 40,
                FontSize        = 20,
                TextColor       = Color.FromHex("#424242"),
                FontFamily      = "FontAwesome",
                Text            = FontAwesome.FAStepBackward,
                BackgroundColor = Color.Transparent,
                IsEnabled       = false,
            };
            btnStepBackward.Clicked += BtnStepBackward_Clicked;

            audioControl = new Grid
            {
                Padding         = 10,
                HeightRequest   = 110,
                RowSpacing      = 0,
                BackgroundColor = PlayerBackgroundColor,
                RowDefinitions  = new RowDefinitionCollection()
                {
                    new RowDefinition {
                        Height = 30
                    },
                    new RowDefinition {
                        Height = 20
                    },
                    new RowDefinition {
                        Height = 40
                    },
                },

                ColumnDefinitions = new ColumnDefinitionCollection
                {
                    new ColumnDefinition {
                        Width = 80
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = new GridLength(1, GridUnitType.Star)
                    },
                    new ColumnDefinition {
                        Width = 80
                    },
                }
            };
            audioControl.Children.Add(lblFileName, 0, 5, 0, 1);
            audioControl.Children.Add(bufferingSlider, 0, 5, 1, 2);
            audioControl.Children.Add(audioSlider, 0, 5, 1, 2);
            audioControl.Children.Add(lblCurrentPosition, 0, 1, 2, 3);
            audioControl.Children.Add(btnStepBackward, 1, 2, 2, 3);
            audioControl.Children.Add(loader, 2, 3, 2, 3);
            audioControl.Children.Add(btnPlay, 2, 3, 2, 3);
            audioControl.Children.Add(btnStepForward, 3, 4, 2, 3);
            audioControl.Children.Add(lblDuration, 4, 5, 2, 3);

            audioView.Children.Add(audioControl, 0, 1, 1, 2);
            Children.Add(audioView);
        }