'TVOS avplayer resets/seeks to 0 after app reload

I'm trying to play a video at a certain time on an AppleTV app. It works fine, but when I close the app and open it again, the video seeks to 0.

How can I prevent this or observe when the app is loaded again?

This is my code:

@State var player = AVPlayer()

var body: some View {
    VideoPlayer(player: player)
        .onAppear() {
            loadVideo()
            seek()
        }
}

func loadVideo() {
    player = AVPlayer(url: URL(string: "https://some.url/video.m3u8"))
    player.play()
}

func seek() {
    let date = Date()
    let minutes = Calendar.current.component(.minute, from: date)
    let seconds = Calendar.current.component(.second, from: date)

    player.seek(to: CMTimeMake(value: Int64(minutes * 60 + seconds), timescale: 1))
}


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source