0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

AVPlayerViewControllerは継承しちゃダメ🙅 直で使うべし

Last updated at Posted at 2022-09-28

issue

AVPlayerViewController を継承して作ったVCから動画プレイヤーで動画を再生させていたんですが

iOS16になってから、 動画プレイヤーのコントローラー(再生とか10秒先送りのボタン)が表示されたまま消えなくなるバグが発生した
今まではタップすると表示/非表示が切り替わったが、それもなくなった

こんな感じ

コードはこんな感じ

@implementation MyAVPlayerViewController


- (id)initWithVideoUrl:(NSString *)url {
    
    if (self) {
        AVPlayer *avp = [[[AVPlayer alloc] initWithURL:[NSURL URLWithString:url]] autorelease];
        self.player = avp;
        self.showsPlaybackControls = FALSE;
        self.allowsPictureInPicturePlayback = YES;
    }
    
    return self;
}

- (void)viewDidLoad {
    [super viewDidLoad];
以下略

直した

AVPlayerViewController の注意書きを読むと、 どうやらAVPlayerViewControllerは生のママ使えとのこと
試しにこんな感じで呼び出すようにしてみた

AVPlayer *avp = [[AVPlayer alloc] initWithURL:[NSURL URLWithString:urlPath]];
AVPlayerViewController *avpVC = [[[AVPlayerViewController alloc] init] autorelease];
avpVC.player = avp;
[self presentViewController:avpVC animated:YES completion:^{
    LOG(@"modal ok");
}];

すると、、

image.png

無事コントローラーが表示され、さらにタップで表示/非表示きりかえもされるようになった

AVPlayerViewControllerは生のママ使いましょう

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?