AVPlayer控件不能正常工作



我一直在尝试实现AVPlayer,但我发现了一些问题。首先,在演示版(https://developer.xamarin.com/recipes/ios/media/video_and_photos/play_a_video_using_avplayer/)中没有控制……这正常吗?控件应该默认启用(apple文档)

在我的应用程序中,我重写了AVPlayerViewController类,控件在横向上可见,但在视频后面。滑动条的大部分是不可见的。这太奇怪了。此外,在播放时,按钮暂停实际上是按钮播放,并被禁用。点击全屏显示全屏视图,我可以听到视频播放,但只有黑屏。下面是我创建视频播放器的方法:

这段代码是在AVPlayerViewController的子类和我设置它的框架与父的框架。除了控件部分

之外,它似乎工作得很好
playerItem = new AVPlayerItem (new NSUrl(url));
player = new AVPlayer (playerItem);
playerLayer = AVPlayerLayer.FromPlayer (player);
playerLayer.Frame = View.Bounds;
View.Layer.AddSublayer (playerLayer);

有人见过这个吗?

这适用于我,如果你是子类化AVPlayerViewController它已经有播放器属性,所以你不需要创建另一个。

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();
        }
    }
}

最新更新