private void ResetVideo() { var source = Element.Source; if (source == null) { videoView.SetVideoURI(null); return; } var filePath = source.FilePath; if (filePath != null) { videoView.SetVideoPath(filePath); videoView.SeekTo(1); return; } var fileUri = source.Url; if (fileUri != null) { videoView.SetVideoURI(Android.Net.Uri.Parse(fileUri)); videoView.SeekTo(1); return; } }
void UpdateSource(bool forceSeek = false) { bool hasSetSource = false; if (Element.Source is UriVideoSource) { string uri = (Element.Source as UriVideoSource).Uri; if (!String.IsNullOrWhiteSpace(uri)) { Android.Net.Uri parsedUri = Android.Net.Uri.Parse(uri); videoView.SetVideoURI(parsedUri); hasSetSource = true; } } else if (Element.Source is FileVideoSource) { string filename = (Element.Source as FileVideoSource).File; if (!String.IsNullOrWhiteSpace(filename)) { videoView.SetVideoPath(filename); hasSetSource = true; } } else if (Element.Source is ResourceVideoSource) { string package = Context.PackageName; string path = (Element.Source as ResourceVideoSource).Path; if (!String.IsNullOrWhiteSpace(path)) { string filename = Path.GetFileNameWithoutExtension(path).ToLowerInvariant(); string uri = "android.resource://" + package + "/raw/" + filename; videoView.SetVideoURI(Android.Net.Uri.Parse(uri)); hasSetSource = true; } } if (hasSetSource) { if (Element.StartTime > 0) { videoView.SeekTo(Element.StartTime * 1000); } else if (forceSeek) { videoView.SeekTo(1); // SeekTo(0) does not do anything, so using 1 } } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs args) { base.OnElementPropertyChanged(sender, args); if (args.PropertyName == Global.VideoPlayer.VideoPlayer.NativeControlsProperty.PropertyName) { SetAreTransportControlsEnabled(); } else if (args.PropertyName == Global.VideoPlayer.VideoPlayer.MuteProperty.PropertyName) { SetMute(); } else if (args.PropertyName == Global.VideoPlayer.VideoPlayer.AudioFocusProperty.PropertyName) { SetAudioFocus(); } else if (args.PropertyName == Global.VideoPlayer.VideoPlayer.SourceProperty.PropertyName) { SetSource(); } else if (args.PropertyName == Global.VideoPlayer.VideoPlayer.PositionProperty.PropertyName) { if (Math.Abs(_videoView.CurrentPosition - Element.Position.TotalMilliseconds) > 1000) { _videoView.SeekTo((int)Element.Position.TotalMilliseconds); } } }
public bool OnTouch(View v, MotionEvent e) { ProgressBar pb = (ProgressBar)v; int newPosition = (int)(100 * e.GetX() / pb.Width); if (newPosition > pb.SecondaryProgress) { newPosition = pb.SecondaryProgress; } var pos = (int)newPosition * vv.Duration / 100; switch (e.Action) { case MotionEventActions.Down: case MotionEventActions.Move: case MotionEventActions.Up: pb.Progress = newPosition; vv.SeekTo(pos); Toast.MakeText(this, "Seek to " + pos + "%", ToastLength.Short).Show(); break; } return(true); }
public void Seek(int seconds) { if (!_prepared) { return; } _videoView.SeekTo(seconds * 1000); }
public bool Seek(int seconds) { if (!_prepared) { return(false); } _videoView.SeekTo(seconds * 1000); return(true); }
public void OnPrepared(MediaPlayer mp) { VideoView.RequestLayout(); if (CurrentPosition != 0) { VideoView.SeekTo(CurrentPosition); CurrentPosition = 0; } else { Play(); } }
void OnVideoViewPrepared(object sender, EventArgs args) { isPrepared = true; ((IVideoPlayerController)Element).Duration = TimeSpan.FromMilliseconds(videoView.Duration); //mediaPlayer = sender as MediaPlayer; //int videoWidth = mediaPlayer.VideoWidth; //int videoHeight = mediaPlayer.VideoHeight; //DisplayMetrics displayMetrics = new DisplayMetrics(); //IWindowManager windowManager = Context.GetSystemService(Context.WindowService).JavaCast<IWindowManager>(); //windowManager.DefaultDisplay.GetMetrics(displayMetrics); //int screenWidth = displayMetrics.WidthPixels; //int screenHeight = displayMetrics.HeightPixels; //float scaleY = 1.0f; //float scaleX = (videoWidth * screenHeight / videoHeight) / screenWidth; //int pivotPointX = (int)(screenWidth / 2); //int pivotPointY = (int)(screenHeight / 2); //surfaceView.setScaleX(scaleX); //surfaceView.setScaleY(scaleY); //surfaceView.setPivotX(pivotPointX); //surfaceView.setPivotY(pivotPointY); if (Element.AutoPlay && hasSetSource) { if (videoView.IsPlaying) { videoView.StopPlayback(); } videoView.RequestFocus(); videoView.Start(); videoView.SeekTo(0); } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs args) { base.OnElementPropertyChanged(sender, args); if (args.PropertyName == VideoPlayer.AreTransportControlsEnabledProperty.PropertyName) { SetAreTransportControlsEnabled(); SetSource(); } else if (args.PropertyName == VideoPlayer.PositionProperty.PropertyName) { if (Math.Abs(videoView.CurrentPosition - Element.Position.TotalMilliseconds) > 1000) { videoView.SeekTo((int)Element.Position.TotalMilliseconds); } } }
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); } } }
protected override void OnElementPropertyChanged(object sender, PropertyChangedEventArgs e) { base.OnElementPropertyChanged(sender, e); if (e.PropertyName == VideoPlayer.SourceProperty.PropertyName) { if (!string.IsNullOrEmpty(Element.Source)) { videoView.SetVideoPath(Element.Source); } } else if (e.PropertyName == VideoPlayer.PositionProperty.PropertyName) { if (Math.Abs(videoView.CurrentPosition - Element.Position.TotalMilliseconds) > 1000) { videoView.SeekTo((int)Element.Position.TotalMilliseconds); } } }
//protected override void OnResume() //{ // base.OnResume(); // //VideoView video = FindViewById<VideoView>(Resource.Id.myVideo); // //video.SystemUiVisibility = StatusBarVisibility.Hidden; // //if (!video.IsPlaying) // //{ // // socket.Emit("START"); // // video.Start(); // //} //} //protected override void OnStop() //{ // base.OnStop(); // //var intent = new Intent(this, typeof(MainActivity)); // //intent.AddFlags(ActivityFlags.NewTask); // //this.StartActivity(intent); //} protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); //adminComponentName = new ComponentName(this.BaseContext, "AdminReceiver"); //devicePM = (DevicePolicyManager)GetSystemService(Context.DevicePolicyService); ////devicePM.SetLockTaskPackages(adminComponentName, new String[] { "./.AdminReceiver" }); //devicePM.LockNow(); Window.AddFlags(WindowManagerFlags.Fullscreen);// | WindowManagerFlags.TurnScreenOn); Window.AddFlags(WindowManagerFlags.KeepScreenOn); Window.AddFlags(WindowManagerFlags.DismissKeyguard); Window.AddFlags(WindowManagerFlags.NotFocusable); Window.AddFlags(WindowManagerFlags.TranslucentStatus); IntentFilter filter = new IntentFilter(Intent.ActionScreenOff); RequestWindowFeature(WindowFeatures.NoTitle); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); var sp = PreferenceManager.GetDefaultSharedPreferences(this); var edit = sp.Edit(); edit.PutBoolean(PrefKioskMode, true); edit.Commit(); // Get our button from the layout resource, // and attach an event to it VideoView video = FindViewById <VideoView>(Resource.Id.myVideo); video.SystemUiVisibility = StatusBarVisibility.Hidden; if (!video.IsPlaying) { socket.Emit("START"); video.Start(); } //Window.ClearFlags(WindowManagerFlags.TurnScreenOn); //var metrics = Resources.DisplayMetrics; //var widthInDp = ConvertPixelsToDp(metrics.WidthPixels); //var heightInDp = ConvertPixelsToDp(metrics.HeightPixels); //var uri = Android.Net.Uri.Parse("http://192.168.30.193:3000/videos/a.mp4"); //video.SetVideoURI(uri); //string path = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyVideos); //string filename = System.IO.Path.Combine(path, "a.mp4"); //var directories = Directory.EnumerateDirectories("./sdcard/Movies"); video.SetVideoPath("./sdcard/Movies/a.mp4"); video.Touch += delegate { socket.Emit("START"); video.Start(); count++; //if (count > 50) // this.Finish(); }; mediaController = new MediaController(this, true); video.SetMediaController(mediaController); video.Completion += (object sender, EventArgs e) => { video.Start(); //socket.Emit("START"); //socket.Emit("RESTART", video.CurrentPosition); }; socket.On("UPDATE", () => { socket.Emit("POS", video.CurrentPosition); }); socket.On("START", () => { video.Start(); //video.SeekTo((int)data); //socket.Emit("RESTART", video.CurrentPosition); }); //socket.On("primeiro", (data) => //{ // primeiro = true; //}); //Console.WriteLine(primeiro); socket.On("POS", (data) => { if (video.IsPlaying) { string[] x = data.ToString().Replace("{", "").Replace("}", "").Replace("\n", "").Replace("\"", "").Split(':'); video.SeekTo(int.Parse(x[1])); } }); //socket.On("RESTART", (data) => //{ // Console.WriteLine(data); // video.Start(); // video.SeekTo((int)data); //}); //try //{ // socket.On(Socket.EVENT_CONNECT, () => // { // socket.Emit("connection"); // }); // socket.On(Socket.EVENT_DISCONNECT, () => // { // socket.Connect(); // }); //} //catch (Exception ex) //{ // Console.Write(ex); //} //DevicePolicyManager devicePolicyManager = (DevicePolicyManager)GetSystemService(Context.DevicePolicyService); //ComponentName demoDeviceAdmin = new ComponentName(this, Java.Lang.Class.FromType(typeof(DeviceAdmin))); //Intent intent = new Intent(DevicePolicyManager.ActionAddDeviceAdmin); //intent.PutExtra(DevicePolicyManager.ExtraDeviceAdmin, demoDeviceAdmin); //intent.PutExtra(DevicePolicyManager.ExtraAddExplanation, "Device administrator"); //StartActivity(intent); StartLockTask(); SendBroadcast(new Intent(Intent.ActionCloseSystemDialogs)); }
public void SeekTo(int positionMs) { _videoView.SeekTo(positionMs); }
protected override void OnCreate ( Bundle bundle ) { base.OnCreate(bundle); _audioPath = Intent.GetStringExtra(AudioPathExtra); if (_audioPath == null) { throw new InvalidOperationException(string.Format("'{0}' extra string missing.", AudioPathExtra)); } _orientationListener = new AndroidCameraActivity.DeviceOrientationEventListener ( this, SensorDelay.Normal, OrientationChanged ); _orientationListener.Enable(); SetContentView(Resource.Layout.PlayVideoLayout); _videoView = FindViewById <VideoView>(Resource.Id.PlayedVideo); _mediaController = new MediaController(this, useFastForward: false); _mediaController.SetAnchorView(_videoView); _videoView.SetMediaController(_mediaController); _videoView.SetOnPreparedListener ( new VideoPreparedListener ( () => { _videoView.SeekTo(1); _mediaController.Show(); } ) ); _videoView.SetOnCompletionListener ( new VideoCompletionListener ( () => _mediaController.Show() ) ); _videoView.SetOnErrorListener ( new VideoErrorListener ( this, _audioPath, getString: (resource) => { return(GetString(resource)); } ) ); //_imageView.Touch -= TouchImage; //_imageView.Touch += TouchImage; /*_videoView.Post // wait with image loading until view fully initialised * ( * () => PlayVideoAsync() * );*/ _videoView.SetVideoPath(_audioPath); }
private void UpdateVideoPosition(int newPosition) { videoView.SeekTo(Convert.ToInt32((this.videoDuration / 1000) * PositionPercentage(newPosition))); }
private void VideoyaBaslaButton_Click(object sender, EventArgs e) { PostVideoView.SeekTo(0); PostVideoView.Start(); VideoyaBaslaButton.Visibility = ViewStates.Gone; }
public async Task Seek(TimeSpan position) { VideoViewCanvas.SeekTo(Convert.ToInt32(position.TotalMilliseconds)); }
private void OnCompletion_vView(object sender, EventArgs e) { vView.SeekTo(0); playButton.SetText(Resource.String.playButtonText_play); }