private void InitComponent() { try { var media = new MediaController(this); media.Show(5000); ProgressBar = FindViewById <ProgressBar>(Resource.Id.progress_bar); ProgressBar.Visibility = ViewStates.Visible; PostVideoView = FindViewById <VideoView>(Resource.Id.videoView); PostVideoView.Completion += PostVideoViewOnCompletion; PostVideoView.SetMediaController(media); PostVideoView.Prepared += PostVideoViewOnPrepared; PostVideoView.CanSeekBackward(); PostVideoView.CanSeekForward(); PostVideoView.SetAudioAttributes(new AudioAttributes.Builder().SetUsage(AudioUsageKind.Media).SetContentType(AudioContentType.Movie).Build()); if (VideoUrl.Contains("http")) { PostVideoView.SetVideoURI(Uri.Parse(VideoUrl)); } else { var file = Uri.FromFile(new File(VideoUrl)); PostVideoView.SetVideoPath(file.Path); } TabbedMainActivity.GetInstance()?.SetOnWakeLock(); } catch (Exception e) { Console.WriteLine(e); } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs args) { base.OnElementPropertyChanged(sender, args); if (args.PropertyName == VideoPlayer.AreTransportControlsEnabledProperty.PropertyName) { SetAreTransportControlsEnabled(); } else if (args.PropertyName == VideoPlayer.SourceProperty.PropertyName) { SetSource(); } else if (args.PropertyName == VideoPlayer.PositionProperty.PropertyName) { if (videoView.CurrentPosition < Element.Position.TotalMilliseconds) { if (!videoView.CanSeekForward()) { return; } } if (videoView.CurrentPosition > Element.Position.TotalMilliseconds) { if (!videoView.CanSeekBackward()) { return; } } if (Math.Abs(videoView.CurrentPosition - Element.Position.TotalMilliseconds) > 1000) { if (Element.AreTransportControlsEnabled) { //mediaController.Show(1000); mediaController.Show(); Device.StartTimer(TimeSpan.FromSeconds(2), () => { mediaController.Hide(); return(false); }); } videoView.SeekTo((int)Element.Position.TotalMilliseconds); } } }
private void InitComponent() { try { MediaC = new MediaController(this); MediaC.Show(5000); ProgressBar = FindViewById <ProgressBar>(Resource.Id.progress_bar); ProgressBar.Visibility = ViewStates.Visible; PostVideoView = FindViewById <VideoView>(Resource.Id.videoView); MediaC.SetAnchorView(PostVideoView); PostVideoView.Completion += PostVideoViewOnCompletion; PostVideoView.SetMediaController(MediaC); PostVideoView.Prepared += PostVideoViewOnPrepared; PostVideoView.CanSeekBackward(); PostVideoView.CanSeekForward(); //PostVideoView.KeepScreenOn = true; //PostVideoView.BringToFront(); //PostVideoView.Activated = true; PostVideoView.SetAudioAttributes(new AudioAttributes.Builder().SetUsage(AudioUsageKind.Media).SetContentType(AudioContentType.Movie).Build()); if (VideoUrl.Contains("http")) { PostVideoView.SetVideoURI(Uri.Parse(VideoUrl)); } else { var file = Uri.FromFile(new File(VideoUrl)); PostVideoView.SetVideoPath(file.Path); } } catch (Exception e) { Console.WriteLine(e); } }