How to play a video using AVPlayerLayer, and AVPlayerViewControler in xamarin iOS?
playerItem = new AVPlayerItem(new NSUrl("https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"));
player = new AVPlayer(playerItem);
AVcontroller.Player = player;
AVcontroller.View.Layer.Frame = this.View.Bounds;
this.View.AddSubview(AVcontroller.View);
//AVcontroller.SetFullscreen(true, true);
AVcontroller.Player.Play();
AVPlayer avp;
AVPlayerViewController avpvc;
var url = NSUrl.FromString(yourURL);
avp = new AVPlayer(url);
avpvc = new AVPlayerViewController();
avpvc.Player = avp;
AddChildViewController(avpvc);
View.AddSubview(avpvc.View);
avpvc.View.Frame = View.Frame;
avpvc.ShowsPlaybackControls = true;
avp.Play();
This is all done in viewDidLoad and its working fine now.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With