Quantcast
Channel: Xamarin.Forms — Xamarin Community Forums
Viewing all articles
Browse latest Browse all 91519

AVPlayerViewController controls not working

$
0
0

I'm trying to create a custom renderer that will display videos on iOS using native controls. The code below plays the video, but the player controls aren't working right. The controls quickly disappear after the video starts playing and don't come back if I click on the video.

using System;
using AVFoundation;
using AVKit;
using Foundation;
using HelloWorld.iOS.CustomRenderers;
using Xamarin.Forms;
using Xamarin.Forms.Platform.iOS;

[assembly: ExportRenderer(typeof(HelloWorld.VideoView), typeof(VideoPageRenderer))]

namespace HelloWorld.iOS.CustomRenderers
{
    public class VideoPageRenderer: ViewRenderer
    {
        protected override void OnElementChanged(ElementChangedEventArgs<View> e)
        {
            base.OnElementChanged(e);
            this.BackgroundColor = UIKit.UIColor.Blue;
            Console.WriteLine("video view renderer");
            NSUrl videoURL = NSUrl.FromString("https://ia800201.us.archive.org/12/items/BigBuckBunny_328/BigBuckBunny_512kb.mp4");
            var player = AVPlayer.FromUrl(videoURL);
            var playerViewController = new AVPlayerViewController();
            playerViewController.Player = player;
            this.AddSubview(playerViewController.View);
            playerViewController.View.Frame = this.Bounds;
            playerViewController.ShowsPlaybackControls = true;
            player.Play();
        }
    }
}

Viewing all articles
Browse latest Browse all 91519

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>