@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()
}
}
}
}
Post
Replies
Boosts
Views
Activity
Facing the same issue. Did you find any solution @fandrade ?
@dyyi Did you find out how we can refresh every second? I want to show a digital clock in widget.
Did you find any solution for this?
Did you get any solution?