Search code examples
swiftuitvosavkit

Where are the controls in SwiftUI VideoPlayer() when running on tvOS?


In iOS, this code plays a video perfectly, using default controls, but running the same code in tvOS only allows the video to be played, but there are no default controls and the player is not shown on the screen. I'm using Xcode 14.

import SwiftUI
import AVKit
    
struct ContentView: View {    
   var body: some View {
        
      VideoPlayer(player: AVPlayer(url: URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")!))
        
   }
}

Is there another video player for tvOS? Or do I need to modify this somehow to trigger the regular controls? Any clues here would be helpful. Thanks!


Solution

  • If you want to use VideoPlayer with all player controls, you need to present the VideoPlayer with .ignoresSafeArea() likewise:

    struct ContentView: View {
        @State var player = AVPlayer(url:URL(string: "https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8")!)
        var body: some View {
            VStack {
                VideoPlayer(player: player).ignoresSafeArea()
            }
        }
    }