Video played with AVPlayer has grey line to top and sides on iPhone 6S Plus

后端 未结 6 723
攒了一身酷
攒了一身酷 2021-01-04 05:02

This seems to be a device specific bug on only iPhone 6S Plus.

Steps:

  1. Download AVPlayer demo sample code
  2. Adjust AVPlaye
相关标签:
6条回答
  • 2021-01-04 05:41

    Setting the AVPlayerLayer's shouldRasterize property to true makes the borders disappear.

    0 讨论(0)
  • 2021-01-04 05:41

    Here's my take on this: The for me easiest way to solve this is to just position a 1px/2px high view on top of your video layer and give it the color you want it to be - this way you can "hide" the grey border by simply putting something on top of it. Needless to say this is super hacky, but it works. You might have to do some calculation on the actual positioning based on your videoGravity property.

    0 讨论(0)
  • 2021-01-04 05:47

    Not only shouldRasterize, you need to set rasterizationScale as well.

    playerLayer.shouldRasterize = true
    playerLayer.rasterizationScale = UIScreen.main.scale
    
    0 讨论(0)
  • 2021-01-04 05:56

    That grey line to top is nothing but a navigation bar. You can hide it in viewdidload of the controller. you are all set to go.

    0 讨论(0)
  • 2021-01-04 05:58

    My suggestion would be that since your use case is an animated loop to ditch the AVPlayer and use a UIImageView.

    UIImage has animatedImage(with:duration:) where you can input an array of images and animate them how you like.

    I think this would solve your problem. In my experience AVPlayer has been a little wonky with iOS 10. I think that since you are only seeing this problem on the 6s+ and 7s+ is proof that it has some issues.

    If you are absolutely committed to figuring out the AVPlayer, first submit a bug report to Apple. Then maybe try adding a UIImageView behind your AVPlayer that has the image set to a blank frame from your video. This is kind of a hacky solution, but it might work. Additionally, check out this stack overflow post. It might shed some light on the issues you are having with the AVPlayer.

    Best of luck.

    0 讨论(0)
  • 2021-01-04 05:58

    I tried Nate4436271's answer and it worked for me, I mean, had the same issue and got rid of the gray lines, but setting the shouldRasterize property to true, made my video lose image quality. So, I set the videoGravity of my playerLayer to AVLayerVideoGravityResizeAspectFill and I got rid of the lines, while maintaining image quality :)

    Here is what I did:

    playerLayer.videoGravity = AVLayerVideoGravityResizeAspectFill
    

    AspectFill was within my needs and solved the problem. You may wish to evaluate whether other options are better for what you need, like AspectFit or Resize.

    Hope this helps :)

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