SwiftUI - VideoPlayer bug

Viewed 601

I encounter a problem with VideoPlayer on SwiftUI (Xcode 12.0.1), it doesn't play online or offline videos. I tried on real device (iPad iOS 14.0.1) and simulators and I got the same result. It's like it starts to play the first frame and the it stops, the play button is disabled.

I followed this tutorial : here

I found someone who got the same bug (here) but it was on Xcode beta and iOS beta, it would be really strange that this bug still occurs in release versions.

Could you please just test on your side and tell me if you get the same result? Thanks you.

Here's my console when I try to use VideoPlayer :

  • 2020-09-30 09:05:15.364332+0200 MrChickenApp[870:214157] <CATransformLayer: 0x2822d2e80> - changing property masksToBounds in transform-only layer, will have no effect
  • 2020-09-30 09:05:15.364734+0200 MrChickenApp[870:214157] <CATransformLayer: 0x2822d3ee0> - changing property masksToBounds in transform-only layer, will have no effect
  • 2020-09-30 09:05:15.366618+0200 MrChickenApp[870:214157] <CATransformLayer: 0x2822e8680> - changing property masksToBounds in transform-only layer, will have no effect
  • 2020-09-30 09:05:15.370750+0200 MrChickenApp[870:214157] <CATransformLayer: 0x2822ef600> - changing property masksToBounds in transform-only layer, will have no effect
  • 2020-09-30 09:05:15.372214+0200 MrChickenApp[870:214157] <CATransformLayer: 0x2822ef8c0> - changing property masksToBounds in transform-only layer, will have no effect 2020-09-30 09:05:15.403266+0200 MrChickenApp[870:214157] <CATransformLayer: 0x2822e8680> - changing property allowsGroupBlending in transform-only layer, will have no effect
  • 2020-09-30 09:05:15.403441+0200 MrChickenApp[870:214157] <CATransformLayer: 0x2822ef600> - changing property allowsGroupBlending in transform-only layer, will have no effect
1 Answers

I also have those messages on the console but the player is working fine.

Are you sure you started the player with the play command? If you don't start the player only the first frame will be displayed. You can do it for example inside onAppear.

Try the following code:

import SwiftUI
import AVKit

struct TestVideo: View {
    private let player = AVPlayer(url:  Bundle.main.url(forResource: "Video", withExtension: "mp4")!)
    
    var body: some View {
        VideoPlayer(player: player)
            .onAppear() {
                player.play()
            }
    }
}
Related