AVPlayer Video Blank but Hear Sound

前端 未结 3 548
小蘑菇
小蘑菇 2021-01-17 10:33

I\'m switching from MPMoviePlayerController to AVPlayer as I need finer grained control over video swapping. The .mov file I was playi

相关标签:
3条回答
  • 2021-01-17 10:44

    Found out it was a result of using AutoLayout. In the viewDidLoad the self.playerContainer.bounds is a CGRectZero.

    I had to assign the playerLayer frame in the viewDidAppear to match the playerContainer.

    0 讨论(0)
  • 2021-01-17 11:00

    Since we use AVPlayerLayer (a subclass of CALayer), we need to set the frame

    - (void)viewDidLayoutSubviews {
        [super viewDidLayoutSubviews];
    
        self.avPlayerLayer.frame = self.movieContainerView.bounds;
    }
    
    0 讨论(0)
  • 2021-01-17 11:01

    Make sure you the statement that plays the video:

    [self.player play]
    

    is invoked from main dispatch queue like this (Swift 3):

    DispatchQueue.main.async {
        self.player.play()
    }
    
    0 讨论(0)
提交回复
热议问题