Exemplo n.º 1
0
        void OnVideoViewPrepared(object sender, EventArgs args)
        {
            if (sender is MediaPlayer mediaPlayer)
            {
                if (Element.IsMuted)
                {
                    mediaPlayer.SetVolume(0f, 0f);
                }
            }

            // remove the initial app background
            videoView.SetBackgroundColor(Android.Graphics.Color.Transparent);
        }
        protected override void OnElementChanged(ElementChangedEventArgs <VideoPlayer> args)
        {
            base.OnElementChanged(args);

            if (args.NewElement != null)
            {
                if (Control == null)
                {
                    // Save the VideoView for future reference
                    videoView = new VideoView(Context);
                    videoView.SetBackgroundColor(Color.Transparent);
                    videoView.Info       += VideoView_Info;
                    videoView.Completion += VideoView_Completion;
                    videoView.Error      += VideoView_Error;

                    // Put the VideoView in a RelativeLayout
                    ARelativeLayout relativeLayout = new ARelativeLayout(Context);
                    relativeLayout.AddView(videoView);

                    // Center the VideoView in the RelativeLayout
                    ARelativeLayout.LayoutParams layoutParams =
                        new ARelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent);
                    layoutParams.AddRule(LayoutRules.CenterInParent);
                    videoView.LayoutParameters = layoutParams;

                    // Handle a VideoView event
                    videoView.Prepared += OnVideoViewPrepared;

                    SetNativeControl(relativeLayout);
                }

                SetAreTransportControlsEnabled();
                SetSource();

                args.NewElement.UpdateStatus   += OnUpdateStatus;
                args.NewElement.PlayRequested  += OnPlayRequested;
                args.NewElement.PauseRequested += OnPauseRequested;
                args.NewElement.StopRequested  += OnStopRequested;
                args.NewElement.ShowTransportControlsRequested += OnShowTransportControls;
                args.NewElement.HideTransportControlsRequested += OnHideTransportControls;
            }

            if (args.OldElement != null)
            {
                args.OldElement.UpdateStatus   -= OnUpdateStatus;
                args.OldElement.PlayRequested  -= OnPlayRequested;
                args.OldElement.PauseRequested -= OnPauseRequested;
                args.OldElement.StopRequested  -= OnStopRequested;
                args.OldElement.ShowTransportControlsRequested -= OnShowTransportControls;
                args.OldElement.HideTransportControlsRequested -= OnHideTransportControls;
            }
        }
        void OnVideoIsPrepared()
        {
            seekVideo.Progress = 0;
            seekVideo.Max      = videoView.Duration;


            videoView.SetBackgroundColor(Color.Transparent);
            videoView.Start();
            videoView.SetZOrderOnTop(true);
            videoView.SetZOrderMediaOverlay(true);

            StartThread();
        }