Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Weird borders around AVPlayerViewController

I'm designing Login screen for my app where I want to have animated logo. I've created small video file (around 1 Mb) and created AVPlayerViewController instance using this code:

let videoURL = URL(fileURLWithPath: Bundle.main.path(forResource: "logo_cc", ofType: "mp4")!)
let player = AVPlayerViewController()
player.player = AVPlayer(url: videoURL)
player.videoGravity = AVLayerVideoGravity.resizeAspectFill.rawValue
player.view.frame = playerView.bounds
playerView.addSubview(player.view)
player.player!.play()

where playerView is an actual UIView, created in StoryBoard, which has to hold the video.

So as a result, everything is working, video is playing and etc, but the only issue I have are those tiny borders around the video (can be seen only on actual device, but when I do a screenshot or screen mirroring using QuickTime on my Mac, those borders disappear).

Here's the demonstration: https://imgur.com/a/zarVwac As you can see those borders can be seen only on an actual device (screenshot on the left is taken from that device as well, but borders are not there).

Any ideas on how to fix this?

like image 704
Maxim Skryabin Avatar asked Jun 19 '18 11:06

Maxim Skryabin


1 Answers

After testing this code on multiple devices (actual physical devices, not simulators), this bug appears to happen only on Plus devices (I tested it on i8 on iOS 11, i8+ on iOS 11, iX on iOS 11 and i6+ on iOS 10).

To fix this I first switched from AVPlayerViewController to AVPlayerLayer and added those 2 lines of code:

playerLayer.shouldRasterize = true
playerLayer.rasterizationScale = UIScreen.main.scale

First line seems to remove those weird lines, but makes the quality of the video awful. Second line of code fixes the quality.

Hope this helps someone!

like image 91
Maxim Skryabin Avatar answered Oct 05 '22 06:10

Maxim Skryabin