【问题标题】:AVPlayer Controls not working properlyAVPlayer 控件无法正常工作
【发布时间】:2016-01-15 02:34:17
【问题描述】:

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

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

此代码位于 AVPlayerViewController 的子类中,我将其框架设置为父框架。除了控制部分,它似乎工作正常

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

有人见过吗?

【问题讨论】:

    标签: ios xamarin avplayer avplayerlayer avplayerviewcontroller


    【解决方案1】:

    这对我有用,如果你是 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();
            }
        }
    }
    

    让我知道这是否适合你。

    【讨论】:

    • 知道如何全屏播放视频吗?
    • 当我运行上面的代码时,它会全屏播放。我能想到的唯一可能阻止它的是这一行“playerLayer.Frame = View.Bounds;”你能检查 View.Bounds 返回的内容吗?
    • 你好兄弟@IainSmith,你能帮我找出这个解决方案吗? stackoverflow.com/questions/42973856/…
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-26
    相关资源
    最近更新 更多