1

I've been trying to implement AVPlayer but I found some issues. First, on the demo (https://developer.xamarin.com/recipes/ios/media/video_and_photos/play_a_video_using_avplayer/) there's no controls...is this normal? Controls should be enable by default(apple documentation)

On my app I override AVPlayerViewController class and the controls are visible on landscape but behind the video. So most of the slider is not visible. This is weird. Also, while playing, the button pause is actually the button play and is disabled. Tapping fullscreen shows the fullscreen view, I can hear the video playing but there's only a black screen. Here's how I'm creating the video player:

this code is in a subclass of AVPlayerViewController and I set it's frame with the parent's frame. It seems to work fine except the controls part

playerItem = new AVPlayerItem (new NSUrl(url));
player = new AVPlayer (playerItem);
playerLayer = AVPlayerLayer.FromPlayer (player);
playerLayer.Frame = View.Bounds;
View.Layer.AddSublayer (playerLayer);

Has anyone seen this before?

4

1 回答 1

2

这对我有用,如果您是 AVPlayerViewController 的子类,它将已经具有 Player 属性,因此您无需创建另一个。

using System;
using AVFoundation;
using AVKit;
using Foundation;

namespace SOText
{
    public partial class ViewController : AVPlayerViewController
    {
        public ViewController (IntPtr handle) : base (handle)
        {
        }

        public override void ViewDidLoad ()
        {
            base.ViewDidLoad ();
            Player = new AVPlayer (NSUrl.FromFilename ("SampleVideo_320x240_1mb.3gp"));
            AVPlayerLayer playerLayer = AVPlayerLayer.FromPlayer (Player);
            playerLayer.Frame = View.Bounds;
            Player.Play();
        }
    }
}

让我知道这是否适合你。

于 2015-10-19T10:21:51.887 回答