AVPlayer crash when resizing window during fullscreen while hotspotting

戏子无情 提交于 2019-12-03 11:32:02

I have fixed it by this code:

@interface YourAVPlayerViewController : AVPlayerViewController
@end

@implementation YourAVPlayerViewController

 - (BOOL)prefersStatusBarHidden {
        return YES;
 }

@end

As a workaround you can push on navigationControlelr stack or when presenting modally use this one:

@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

--

Then just use 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];
}];

I wrote a small extension for AVPlayerViewController that fixes the issue app-wide:

// 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
  }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!