简体   繁体   中英

AVPlayerViewController stuck on first frame of local video

In one of my ViewControllers, I have an AVPlayerViewController . In my viewDidLoad I have

self.videoPlayerController = [AVPlayerViewController new];

Then, I play a video using the following method

- (void)playVideo:(NSURL*)videoURL {
    [self presentViewController:self.videoPlayerController animated:YES completion:^(){
        AVPlayer *player = [[AVPlayer alloc] initWithURL:videoURL];
        [self.videoPlayerController setVideoGravity:AVLayerVideoGravityResizeAspect];
        [self.videoPlayerController setPlayer:player];
        [self.videoPlayerController.player play];
    }];
}

When playing a video for the first time, the AVPlayerViewController appears, but the video is stuck on the first frame, and will not play. No audio plays either.

In iOS 10.0, the seekbar in the on screen controls show that the video is playing (it will progress to the end). In iOS 10.2 however, the seekbar is stuck at 0:00 as well.

I am experiencing this problem on iPads with iOS versions 10.0 and 10.2, however, it works in the XCode simulator (both 10.0 and 10.2).

My problem is similar in nature to this.

Also, the video plays correctly if you close the ViewController containing the AVPlayerViewController , reopen it, and attempt to play the video again.

I guess that the problem is in your video file. Try to download another video mp4 video sample . Add it to your project and try.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM