protected override void Dispose(bool disposing) { if (Control != null) { Control.RemoveAllViews(); } if (_view != null) { _view.SetOnPreparedListener(null); _view.SetOnCompletionListener(null); _view.Dispose(); _view = null; } if (_controller != null) { _controller.Dispose(); _controller = null; } if (_mediaPlayer != null) { _mediaPlayer.Dispose(); _mediaPlayer = null; } base.Dispose(disposing); }
protected override void OnElementChanged(ElementChangedEventArgs <MediaElement> e) { base.OnElementChanged(e); if (e.OldElement != null) { e.OldElement.SetRenderer(null); if (_view != null) { _view.SetOnPreparedListener(null); _view.SetOnCompletionListener(null); _view.Dispose(); _view = null; } if (_controller != null) { _controller.Dispose(); _controller = null; } if (_mediaPlayer != null) { _mediaPlayer.Dispose(); _mediaPlayer = null; } } if (e.NewElement != null) { if (!DesignMode.DesignModeEnabled) { try { e.NewElement.SetRenderer(this); _view = new VideoViewEx(Context); SetNativeControl(new FrameLayout(Context));// new VideoViewEx(Context)); //Control.LayoutParameters = new LayoutParams(LayoutParams.MatchParent, LayoutParams.MatchParent); _view.SetZOrderMediaOverlay(true); _view.SetOnCompletionListener(this); _view.SetOnPreparedListener(this); _view.KeepScreenOn = Element.KeepScreenOn; Control.AddView(_view); _controller = new MediaController(Context); _controller.SetAnchorView(this); _controller.Visibility = Element.AreTransportControlsEnabled ? ViewStates.Visible : ViewStates.Gone; _view.SetMediaController(_controller); UpdateSource(); } catch { } } } }
protected override void OnElementChanged(ElementChangedEventArgs <MediaElement> e) { base.OnElementChanged(e); if (e.OldElement != null) { e.OldElement.SetRenderer(null); if (_view != null) { _view.Prepared -= Control_Prepared; _view.SetOnCompletionListener(null); _view.Dispose(); } if (_controller != null) { _controller.Dispose(); _controller = null; } } if (e.NewElement != null) { if (!DesignMode.DesignModeEnabled) { try { SetNativeControl(new FrameLayout(Context));// new VideoViewEx(Context)); _view = new VideoViewEx(Context); Control.AddView(_view); e.NewElement.SetRenderer(this); _view.Prepared += Control_Prepared; _view.SetOnCompletionListener(this); _view.KeepScreenOn = Element.KeepScreenOn; _controller = new MediaController(Context); _controller.Visibility = Element.AreTransportControlsEnabled ? ViewStates.Visible : ViewStates.Gone; _view.SetMediaController(_controller); UpdateSource(); } catch { } } } }