12

我正在编写一个应用程序,用户可以在其中观看各种视频。我在按钮点击时全屏打开视频,用户可以使用播放控件来调整窗口大小。我遇到的问题是,当用户通过热点共享他的互联网时,应用程序顶部有一个蓝色条。此时调整窗口大小会导致 AVKit 框架崩溃(我相信)。使用 Swift 2.3、Xcode 7.3.1。我的手机 iPhone 6s 使用 iOS 10,我也在 iOS 9 iPhone 6 Plus 上尝试过,同样的问题。

迷恋;撞车;崩溃:

Terminating app due to uncaught exception 'UIViewControllerHierarchyInconsistency', reason: 'child view controller:<AVFullScreenPlaybackControlsViewController: 0x102933000> should have parent view controller:<AVPlayerViewController: 0x10212d800> but actual parent is:<AVFullScreenViewController: 0x10884d900>'

我的代码:

private let playerController = AVPlayerViewController()
private var player: AVPlayer!

private func playVideo(media: Media) {

        player = AVPlayer(URL: NSURL(string: media.url)!)
        playerController.player = player

        presentViewController(playerController, animated: true, completion: {
            self.playerController.player?.play()
            self.playerController.delegate = self
        })

    }

如果我不在手机上共享我的互联网(因此没有蓝条),那么它可以正常工作,没有任何问题。有人设法隐藏了这个蓝条,或者遇到过类似的问题吗?

4

3 回答 3

4

我已经通过以下代码修复了它:

@interface YourAVPlayerViewController : AVPlayerViewController
@end

@implementation YourAVPlayerViewController

 - (BOOL)prefersStatusBarHidden {
        return YES;
 }

@end
于 2017-06-17T09:00:24.347 回答
1

作为一种解决方法,您可以推送 navigationControlelr 堆栈或在模态显示时使用此堆栈:

@interface AVPlayerViewController ()
- (void)fullScreenButtonTapped:(id)arg1;
@end

@interface RCKPlayerViewController ()

@end

@implementation RCKPlayerViewController

- (void)fullScreenButtonTapped:(id)arg1 {
    if ([[UIApplication sharedApplication] statusBarFrame].size.height >= 40) {
        // Show alert that cannot enter full screen when in-call
    } else {
        [super fullScreenButtonTapped:arg1];
    }
}

@end

--

然后只需使用RCKPlayerViewController

AVPlayerViewController *playerViewController = [[RCKPlayerViewController alloc] init];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithURL:[NSURL URLWithString:videoStringURL]];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];
playerViewController.player = player;

[self presentViewController:playerViewController animated:YES completion:^{
    [player play];
}];
于 2017-05-09T08:11:50.410 回答
0

我写了一个小扩展来AVPlayerViewController解决应用程序范围内的问题:

// AVPlayerViewController.swift

import AVKit

extension AVPlayerViewController {

  // fixes app crash while using personal hotspot + watching a full screen video
  override open var prefersStatusBarHidden: Bool {
    return true
  }

}
于 2018-01-02T17:19:01.583 回答