XamarinMediaManager
XamarinMediaManager copied to clipboard
How to attach VideoView in Xamarin.Forms to CrossMediaManager.Current.MediaPlayer.VideoView
First of all thanks for the hard work and this library. I have multiple VideoView s in Xamarin.Forms project in Tabbed Page , I want to attach current tab's VideoView to MediaPlayer , unfortunately its only Xamarin.Forms View not IVideoView .
I also have the same question. How could we attach VideoView in Xamarin.Forms
For Android, change VideoViewRenderer (MediaManager.Forms/Platforms/Android/VideoViewRenderer.cs)
protected override void Dispose(bool disposing)
{
base.Dispose(disposing);
//base.Element?.Dispose(); // -- remove this line
_videoView?.Dispose();
_videoView = null;
}
I would really like to know.
I have multiple players in 1 page and right now they sync up with each other. Attaching to the same source.
Apparently you can do this.
public class CustomVideoViewRendererAndroid : VideoViewRenderer
{
private MediaManager.Platforms.Android.Video.VideoView _videoView;
public CustomVideoViewRendererAndroid(Context context) : base(context)
{
}
protected override void OnElementChanged(ElementChangedEventArgs<VideoView> args)
{
if (args.OldElement != null)
{
((CustomVideoView)args.OldElement).NativeVideoView = null;
args.OldElement.Dispose();
}
if (args.NewElement != null)
{
if (Control == null)
{
_videoView = new MediaManager.Platforms.Android.Video.VideoView(Context);
CrossMediaManager.Current.MediaPlayer.VideoView = _videoView;
SetNativeControl(_videoView);
UpdateBackgroundColor();
UpdateLayout();
}
((CustomVideoView)args.NewElement).NativeVideoView = _videoView;
}
base.OnElementChanged(args);
}
protected override void UpdateBackgroundColor()
{
base.UpdateBackgroundColor();
Control?.SetShutterBackgroundColor(Element.BackgroundColor.ToAndroid());
}
}
As far as I know you can't attach it in any other place than OnElementChanged()
Trying to set the VideoView to anything outside of this method will not work in Xamarin.Forms.
@LittleBoxOfChicken, assuming ElementChangedEventArgs<VideoView>
gets VideoView from the MediaManager.Forms namespace, where does CustomVideoView exist?
Thank you.