How to add an overlay UIImage
in PNG format (such as a logo) with alpha channel on top of video playback, especially in case of external playback mode of AVPlayer
when video is casted on Apple TV
via AirPlay
?
I would like add an overlay UIImage
in PNG format with alpha channel (such as a logo) on top of video playback. This can be easily done on the phone by using contentOverlayView of AVPlayerViewController
. However, when the video is casted and played on Apple TV via AirPlay, the contentOverlayView does not display.
I also tried to apply customised UIImageView
on external screen when UIScreen
has detected the external screen. However, the image still does not show. Instead, only the video playback is shown on the external screen. Here you can see my code for this approach:
if UIScreen.screens.count > 1 {
let externalScreen = UIScreen.screens[1]
print("Playing: externalScreen.bounds: \(externalScreen.bounds)")
let secondWindow = UIWindow(frame: externalScreen.bounds)
secondWindow.screen = externalScreen
let overlayImage = UIImage(named: "rain.png")
let overlayImageView = UIImageView(frame: externalScreen.bounds)
overlayImageView.image = overlayImage
secondWindow.addSubview(overlayImageView)
secondWindow.isHidden = false
secondWindow.makeKeyAndVisible()
}
It does not sound like a difficult problem as adding overlay views like subtitle or image logo seems to be very common operations. Can somebody help?
Thanks.
AVPlayerLayer
as a layer of the external screen and then put anotherCALayer
with my PNG image on top of theAVPlayerLayer
. However, this approach only works if the propertyusesExternalPlaybackWhileExternalScreenIsActive
of theAVPlayer
is set tofalse
. If the property istrue
(which is the case I need for FairPlay streaming), theAVPlayer
seems to render the content automatically on external screen. Do you have any clue how to get theUIView
of theAVPlayer
when external playback mode is on?@MoDJ – fkeufss Apr 29 at 13:48