Unable to simultaneously satisfy constraints Warnings with AVPlayerViewController embedded in storyboard

后端 未结 6 697
长情又很酷
长情又很酷 2020-12-05 22:50

I\'m trying to set up an AVPlayerViewController completely through storyboards by embedding in a separate View Controller.

Steps:

  1. Create Single View Ap
6条回答
  •  佛祖请我去吃肉
    2020-12-05 23:48

    Unfortunately this bug is still present in ios 10.1. Anyway, I have observed that if I present the view controller with the seekTime set to 0, the bug is not present. So, my solution was to pause the player, retain the currentTime, seek the player to 0, present the controller and on the completion do the following: seek to the retained time and play again.

    AVPlayer *player;
    AVPlayerViewController *avPlayerController;
    CMTime currentTime;
    
    - (void)viewDidLoad {
        [super viewDidLoad];
    
        NSURL *videoURL = [NSURL URLWithString:@"https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4"];
        player = [AVPlayer playerWithURL:videoURL];
        AVPlayerLayer *playerLayer = [AVPlayerLayer playerLayerWithPlayer:player];
        [self.playerView.layer addSublayer:playerLayer];
        playerLayer.frame = self.playerView.bounds;
        avPlayerController = [[AVPlayerViewController alloc] init];
        avPlayerController.player = player;
    
    }
    
    - (IBAction)fullScreen:(id)sender {
        [player pause];
        currentTime = player.currentTime;
        [player seekToTime:CMTimeMake(0, 1)];
    
        [self presentViewController:avPlayerController animated:YES completion:^{
            [avPlayerController.player seekToTime:currentTime];
            [avPlayerController.player play];
        }];
    }
    

提交回复
热议问题