AVPlayerLayer shows black screen but sound is working

前端 未结 3 1471
离开以前
离开以前 2021-01-21 03:52

Im trying to display a local recorded video in a AVPlayerLayer which works sometimes. I can hear the audio from the recorded video but can\'t see the v

相关标签:
3条回答
  • 2021-01-21 04:36

    i have the same issues as you did. the reason is in iOS 10.xx , if you export video with animationTool . You will meet the trouble like that . try to fix them by remove this code .

    something like that

     mainComposition.animationTool =  AVVideoCompositionCoreAnimationTool(postProcessingAsVideoLayer: videoLayer, in: parentlayer)
    

    Hope to help you

    0 讨论(0)
  • 2021-01-21 04:39

    Here's how I set a AVPlayerLayer with the video working (I think what you're missing is the videoGravity parameter).

    let bundle = Bundle.main
    let moviePath = bundle.path(forResource: "myVideo", ofType: "mp4")
    let moviePlayer = AVPlayer(url: URL(fileURLWithPath: moviePath!))
    
    playerLayer = AVPlayerLayer(player: moviePlayer)
    playerLayer.frame = movieView.bounds
    playerLayer.videoGravity = AVLayerVideoGravityResizeAspect
    movieView.layer.addSublayer(playerLayer)
    playerLayer.player?.play()
    
    0 讨论(0)
  • 2021-01-21 04:47

    It's the frame height or width is equal to zero

    0 讨论(0)
提交回复
热议问题