Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to play video with AVPlayerViewController (AVKit) in xamarin iOS

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();
like image 657
Ansal Antony Avatar asked Oct 27 '25 10:10

Ansal Antony


1 Answers

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.

like image 83
Ansal Antony Avatar answered Oct 29 '25 01:10

Ansal Antony