I was sent a video (made in after effects) with an alpha channel (has transparency). I need to add that video to an iOS app, like adding a transparent GIF.
There is this tutorial https://medium.com/@quentinfasquel/ios-transparent-video-in-swiftui-92a9a1cce94e online on how to do just that, however he is using a single mp4 that displays alpha info on the bottom and the colour info on the top, I am using Quicktime 444 which is already transparent by nature. Is there anyway I can play a transparent video on Swift for iOS? I am using SwiftUI.
Hello,
SwiftUI does have the VideoPlayer view, but it appears that this view does not have a transparent background, so although AVPlayer should respect the alpha channel of your asset, it won't actually have an effect in VideoPlayer because of the opaque background of the view itself.
First, I recommend that you file an enhancement request for the issue I just mentioned using Feedback Assistant.
Then, I recommend that you take a look at this sample code: https://developer.apple.com/documentation/avfoundation/media_playback/using_hevc_video_with_alpha
It demonstrates how you can create a "player view" with a clear background to support video that has an alpha channel using SpriteKit. For this to also work for you in SwiftUI, you would also need to implement a representable container of your custom "player view" using UIViewRepresentable.