Essentially I'm trying to find a way to implement a Custom Video player in a SwiftUI iPad application that has all controls hidden except the Fullscreen button.
As far as I understand just hiding specific controls is not possible but I'm wondering if I can build a custom button that puts the video players in full screen. This is the code I have:
//My Custom Video Player class
import SwiftUI
import AVKit
struct CustomVideoPlayer : UIViewControllerRepresentable {
var player : AVPlayer
func makeUIViewController(context: Context) -> AVPlayerViewController {
let controller = AVPlayerViewController()
controller.player = player
controller.showsPlaybackControls = false //Important to not show any native videoplayer controls
controller.videoGravity = .resizeAspectFill
loopVideo(player: player)
return controller
}
func updateUIViewController(_ uiViewController: AVPlayerViewController, context: Context) {
}
func loopVideo(player p: AVPlayer) {
NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: p.currentItem, queue: nil) { notification in
p.seek(to: .zero)
p.play()
}
}
}
import SwiftUI
import AVKit
struct ContentView: View {
var player1 = AVPlayer(url: URL(string: "urlPlaceholder")!)
var body: some View {
CustomVideoPlayer(player: player1)
.onAppear {
player1.play()
}
}