After stumbling upon this video from WWDC '19, I have been trying to get transparent HEVC (H.265) videos to play in SwiftUI. Unfortunately I have been unable to get it working. Is this truly supported in iOS and tvOS 13+?
Here is my code:
import AVKit
import SceneKit
import SpriteKit
struct VideoView: View {
@State var videoPlayer = AVPlayer(url: Bundle.main.url(forResource: "fl", withExtension: "mov")!)
@State var mainScene = SKScene(size: CGSize(width: 500, height: 500))
var body: some View {
HStack {
Spacer()
VStack {
Spacer()
SpriteView(scene: mainScene)
Spacer()
}.onAppear {
guard let scene = SKScene(fileNamed: "backgroundScene") else {
print ("Could not create a background scene")
return
}
scene.scaleMode = .aspectFill
scene.backgroundColor = .blue
scene.view?.allowsTransparency = true
guard let alphaMovieURL = Bundle.main.url(forResource: "output", withExtension: "mov") else {
print("Failed to overlay alpha movie on the background")
return
}
videoPlayer = AVPlayer(url: alphaMovieURL)
let video = SKVideoNode(avPlayer: videoPlayer)
video.size = CGSize(width: 500, height: 500)
scene.addChild(video)
videoPlayer.play()
mainScene = scene
}
Spacer()
}.background(Color.red)
}
}
The file I have been using can be found here:
https://firebasestorage.googleapis.com/v0/b/leaderboard-d5992.appspot.com/o/fl.mov?alt=media&token=c939cdfc-5047-4c86-a38d-89d5a0f3c459
It very well could be that the encoding is wrong, although I have checked it many times and it definitely contains an alpha layer.
Any direction or pointers would be greatly appreciated!