protected override void Dispose(bool disposing) { _videoview?.StopPlayback(); _videoview?.Dispose(); _videoview = null; _controller?.Dispose(); _controller = null; _view = null; }
public AudioView(Context context, Audio audio, string path, ViewerScreen docView) : base(context) { _audio = audio; _basePath = path; _docView = docView; _audioView = new Android.Widget.VideoView(context); ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(1, 1); _audioView.LayoutParameters = param; if (!File.Exists(System.IO.Path.Combine(_basePath, _audio.Link))) { return; } _audioView.SetVideoPath(System.IO.Path.Combine(_basePath, _audio.Link)); var time = _audioView.CurrentPosition; this.AddView(_audioView); _audioView.RequestFocus(); //playstopclick if (_audio.PlayStopClick) { this.Click += (sender, e) => { this.PlayStop(); }; } //autoplay if (this._audio.Autoplay) { //_audioView.Prepared -= Autoplay; //_audioView.Prepared += Autoplay; _audioView.Prepared += (sender, e) => { _isReady = true; }; } //loop if (_audio.Loop) { _audioView.Completion += (sender, e) => { _audioView.Start(); }; } }
public void DisposeMedia() { _videoView.Pause(); //_player.Release(); _videoView.Dispose(); _videoView = null; /*_docView.RunOnUiThread(() => * { * _player.Pause(); * //_player.Release(); * //_player.Dispose(); * //_player = null; * });*/ }
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 Android.Widget.VideoView(Context); // 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.RefreshRequested += OnRefreshRequested; } if (args.OldElement != null) { args.OldElement.UpdateStatus -= OnUpdateStatus; args.OldElement.PlayRequested -= OnPlayRequested; args.OldElement.PauseRequested -= OnPauseRequested; args.OldElement.StopRequested -= OnStopRequested; args.OldElement.RefreshRequested -= OnRefreshRequested; } }
protected override void OnElementChanged(ElementChangedEventArgs <View> e) { base.OnElementChanged(e); if (Control != null) { Android.Widget.VideoView videoView = new Android.Widget.VideoView(Context); SetNativeControl(videoView); } if (e.OldElement != null) { } if (e.NewElement != null) { } }
protected override void OnElementChanged(ElementChangedEventArgs <Xamarin.Forms.View> e) { base.OnElementChanged(e); //Get LayoutInflater and inflate from axml //Important note, this project utilizes a layout-land folder in the Resources folder //Android will use this folder with layout files for Landscape Orientations //This is why we don't have to worry about the layout of the play button, it doesn't exist in landscape layout file!!! var activity = Context as Activity; var viewHolder = activity.LayoutInflater.Inflate(Resource.Layout.Main, this, false); view = viewHolder; AddView(view); //Get and set Views videoView = FindViewById <Android.Widget.VideoView> (Resource.Id.SampleVideoView); playButton = FindViewById <Android.Widget.Button> (Resource.Id.PlayVideoButton); //Give some color to the play button, but not important playButton.SetBackgroundColor(Android.Graphics.Color.Aqua); if (playFromAssets) { //relative path to video in Assets folder var filePath = "SampleVideo.mp4"; ISurfaceHolder holder = videoView.Holder; holder.AddCallback(this); player = new Android.Media.MediaPlayer(); AssetFileDescriptor afd = Context.Assets.OpenFd(filePath); player.SetDataSource(afd.FileDescriptor, afd.StartOffset, afd.Length); } else { //uri for a free video //var uri = Android.Net.Uri.Parse ("https://www.dropbox.com/s/hi45psyy0wq9560/PigsInAPolka1943.mp4?dl=1"); var uri = Android.Net.Uri.Parse("android.resource://" + Forms.Context.PackageName + "/" + Resource.Raw.SampleVideo); //Set the videoView with our uri, this could also be a local video on device videoView.SetVideoURI(uri); } //Assign click event on our play button to play the video playButton.Click += PlayVideo; }
// ---------------------------------------------- #region Overrides protected override void OnElementChanged(ElementChangedEventArgs <ManneVideoView> e) { base.OnElementChanged(e); if (e.NewElement == null) { return; } // Get the Forms control _view = e.NewElement; // Init Sizes SetVideoDimensions(new Size(710, 400)); // Create the container var layout = new Android.Widget.RelativeLayout(Forms.Context); var layoutParams = new Android.Widget.RelativeLayout.LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); layout.LayoutParameters = layoutParams; // Create the VideoView _videoview = new Android.Widget.VideoView(Forms.Context); var videoLayoutParams = new Android.Widget.RelativeLayout.LayoutParams(0, 0); videoLayoutParams.AddRule(LayoutRules.CenterInParent); _videoview.LayoutParameters = videoLayoutParams; // Set the View View as the native control for this renderer layout.AddView(_videoview); SetNativeControl(layout); // Try to play LoadAndPlay(); }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); this.Window.AddFlags(WindowManagerFlags.Fullscreen); _video = JsonConvert.DeserializeObject <Video>(Intent.GetStringExtra("video")); _basePath = Intent.GetStringExtra("path"); Android.Widget.VideoView videoView = new Android.Widget.VideoView(this); ViewGroup.LayoutParams param = new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MatchParent, ViewGroup.LayoutParams.MatchParent); videoView.LayoutParameters = param; //var uri = Android.Net.Uri.Parse(System.IO.Path.Combine(path, _video.Link)); if (_video.Link.StartsWith("http:")) { videoView.SetVideoURI(Android.Net.Uri.Parse(_video.Link)); //_videoView.SetBackgroundColor(Color.Fuchsia); } else { videoView.SetVideoPath(System.IO.Path.Combine(_basePath, _video.Link)); } //videoView.SetBackgroundColor(Color.Black); _contentView.SetBackgroundColor(Color.Black); MediaController mc = new MediaController(this); videoView.SetMediaController(mc); mc.RequestFocus(); _contentView.AddView(videoView); videoView.Start(); }
public VideoView(Context context, Video video, string path, ViewerScreen docView) : base(context) { _video = video; _basePath = path; _docView = docView; //this.SetBackgroundColor(Color.Aqua); View.Inflate(this.Context, Resource.Layout.VideoView, this); try { _videoView = FindViewById <Android.Widget.VideoView>(Resource.Id.videoView); _btnFull = FindViewById <ImageButton>(Resource.Id.btnFull); if (video.Link != "") { if (!File.Exists(System.IO.Path.Combine(_basePath, _video.Link))) { return; } _videoView.SetVideoPath(System.IO.Path.Combine(_basePath, _video.Link)); } else if (_video.UrlStream != "") { _videoView.SetVideoURI(Android.Net.Uri.Parse(_video.UrlStream)); } /*MediaController mc = new MediaController(context); * mc.SetMediaPlayer(_videoView); * mc.SetAnchorView(_videoView); * * _videoView.SetMediaController(mc);*/ _videoView.RequestFocus(); } catch (Exception ex) { Utils.WriteLog("Errore video", ex.Message); return; } _videoView.Error += (sender, e) => { return; }; //playstopclick if (this._video.PlayStopClick) { this.Click += (sender, e) => { this.PlayStop(); }; } if (_video.Fullscreen) { _btnFull.Click += (sender, e) => { Intent i = new Intent(); i.SetClass(this.Context, typeof(VideoViewScreen)); i.PutExtra("path", _basePath); i.PutExtra("video", JsonConvert.SerializeObject(_video)); //ActivitiesBringe.SetObject(zoom); this.Stop(); docView.StartActivity(i); }; } else { _btnFull.Visibility = ViewStates.Invisible; } //autoplay if (this._video.Autoplay) { //_videoView.Prepared -= Autoplay; //_videoView.Prepared += Autoplay; _videoView.Prepared += (sender, e) => { _isReady = true; }; if (_video.Delay > 0) { this.Hide(); _isReady = true; } } else { this.Hide(); } //loop if (_video.Loop) { _videoView.Completion += (sender, e) => { _videoView.Start(); }; } //finish _videoView.Completion += (sender, e) => { if (OnFinish != null) { OnFinish(); } }; }
public VideoLoop(bool repeat, Activity activity, Android.Widget.VideoView videoView) { this.repeat = repeat; this.activity = activity; this.videoView = videoView; }