Initially I had a swiftui view:
MediaPlayerView : View {
SwiftUIPlayer()
}
struct SwiftUIPlayer: UIViewControllerRepresentable {
func makeUIViewController(context: Context) -> MediaPlayerViewController {
this worked well. when orientation changes the UIViewControllerRepresentable remains unchanged and keeps playing the video.
i then created a landscape view and potrait view
eg.
LandscapeMediaPlayerView : View {
SwiftUIPlayer()
}
PotraitMediaPlayerView : View {
SwiftUIPlayer()
}
if isLandscape {
LandscapeMediaPlayer()
} else {
PotraitMediaPlayer()
}
this now recreates the SwiftUIPlayer and the underlying ViewController and AVPlayerViewcontrollers reset the video.
what is the best/easiest approach here? it will be a pain to have 1 Mediaplayer view that changes based on a passed in "isLandscape" bool.
having a singleton AVPlayer instance? this caused issues but should I just persevere with that?
Have you considered creating an object outside of a SwiftUI view and pass it in?
ParentView.swiftChildView.swift