ios – SwiftUI: Expending video player in sheet to full screen


Is there a way to expand the video completely to the top of the safe area? Seems like whatever I try isn’t expanding it fully to the top, or moving it to the very top.

https://i.stack.imgur.com/NVSvs.jpg

var body: some View {
    ZStack {
        if isLoadingVideo || !isVideoAvailable {
            VideoPlaceholderView(isLoading: $isLoadingVideo, onRefresh: refreshButtonTapped)
                .frame(width: 220, height: 220 * (16/9))
                .edgesIgnoringSafeArea(.top)
        } else if let player = videoPlayer {
            VideoPlayer(player: player)
                .frame(width: UIScreen.main.bounds.width, height: UIScreen.main.bounds.width * (16/9)) // Adjusted to full width with aspect ratio
                .onAppear {
                    player.play()
                }
                .onDisappear {
                    player.pause()
                    NotificationCenter.default.removeObserver(self, name: .AVPlayerItemDidPlayToEndTime, object: player.currentItem)
                }
                .edgesIgnoringSafeArea(.top) // Extend to the top edge of the safe area
        } else {
            Color.black.edgesIgnoringSafeArea(.all) // Placeholder for no video
        }
    }
    .onAppear {
        if let url = currentVideoURL {
            videoPlayer = AVPlayer(url: url)
            videoPlayer?.play()
            NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: videoPlayer?.currentItem, queue: .main) { _ in
                videoPlayer?.seek(to: CMTime.zero)
                videoPlayer?.play()
            }
        }
    }
    .onChange(of: currentVideoURL) { newURL in
        if let url = newURL {
            videoPlayer = AVPlayer(url: url)
            videoPlayer?.play()
        }
    }
}

Latest articles

spot_imgspot_img

Related articles

Leave a reply

Please enter your comment!
Please enter your name here

spot_imgspot_img