tvOS 17.2 won't play certain videos

132 Views Asked by At

Loading a video that played on tvOS 17, won't now play in tvOS 17.2. It isn't true for all videos or even all videos of a certain type.

This code works fine on tvOS 17, but not on 17.2

import SwiftUI
import AVKit
struct ContentView: View {
    var body: some View {
        let player = AVPlayer(url: URL(string: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")!)
        VideoPlayer(player: player)
            .onAppear {
                player.play()
            }
    }
}

I have tried reloading the metadata. I tried making the player from an AVAsset rather than a URL. I can't seem to see what is making it work with some videos and not all and what is different from tvOS 17 to 17.2.

2

There are 2 best solutions below

1
Mayur Rathod On BEST ANSWER

I believe there might be a problem specifically with the tvOS 17.2 simulator. In my experience, everything functioned as expected when testing on an actual device running tvOS 17.2.

1
Andrew Conlan On

There may be another issue with the simulator but also the player in the code above will get recreated every time the body refreshes. AVPlayer should be held in an @State variable try this:

struct ContentView: View {

    @State private var player = AVPlayer(url: URL(string: "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4")!)

    var body: some View {
        VideoPlayer(player: player)
            .onAppear {
                player.play()
            }
    }
}

Also it's a http url if you change it to https it'll play (since it does not conform to ATS policy)