Post

Replies

Boosts

Views

Activity

Reply to AVPlayerViewController not displaying playback controls in iOS 18
@DTS Engineer the palyback controls are not showing if adding the AVPlayerViewController or SwiftUI VideoPlayer inside a TabView with .tabViewStyle(.page(indexDisplayMode: .never)) style TabView(selection: $currentIndex) { ForEach(0..<localFiles.count, id:\.self) { index in let url = localFiles[index] SOVideoPlayer(url: url) .clipped() } } .tabViewStyle(.page(indexDisplayMode: .never)) struct SOVideoPlayer: View { let url: URL @State private var play = false var body: some View { CustomVideoPlayer(play: $play, url: url) .overlay { Image(systemName: "play.fill") .foregroundStyle(.white) .background { Color.black.opacity(0.5) .frame(width: 54, height: 54) .clipShape(.circle) } .simultaneousGesture( TapGesture() .onEnded { play.toggle() } ) .opacity(play ? 0 : 1) } .onDisappear { play = false } } } extension SOVideoPlayer { fileprivate struct CustomVideoPlayer: UIViewControllerRepresentable { @Binding var play: Bool let url: URL func makeUIViewController(context: Context) -> AVPlayerViewController { let controller = AVPlayerViewController() let player = AVPlayer(url: url) controller.player = player controller.showsPlaybackControls = true return controller } func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) { if play { uiViewController.player?.play() } else { uiViewController.player?.pause() } } } }
Oct ’24