我一直在尝试实现 AVPlayer,但我发现了一些问题。首先,在演示 ( https://developer.xamarin.com/recipes/ios/media/video_and_photos/play_a_video_using_avplayer/ ) 上没有控件……这正常吗?默认情况下应启用控件(苹果文档)
在我的应用程序中,我覆盖了 AVPlayerViewController 类,控件在横向上可见但在视频后面。所以大部分 slider 是不可见的。这很奇怪。此外,在播放时,按钮暂停实际上是按钮播放并且被禁用。点击全屏显示全屏 View ,我可以听到视频播放但只有黑屏。以下是我创建视频播放器的方式:
此代码位于 AVPlayerViewController 的子类中,我将其框架设置为父框架。除了控制部分,它似乎工作正常
playerItem = new AVPlayerItem (new NSUrl(url));
player = new AVPlayer (playerItem);
playerLayer = AVPlayerLayer.FromPlayer (player);
playerLayer.Frame = View.Bounds;
View.Layer.AddSublayer (playerLayer);
有人见过这个吗?
最佳答案
这对我有用,如果你是 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();
}
}
}
让我知道这是否适合您。
关于ios - AVPlayer 控件无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33168794/