Full example and typo fix, sorry:
import SwiftUI
import AVKit
struct ContentView: View {
@State var player = AVQueuePlayer()
@State private var trackOnEnd = 0
let videoEnded = NotificationCenter.default.publisher(for: NSNotification.Name.AVPlayerItemDidPlayToEndTime)
var body: some View {
AVPlayerControllerRepresented(player: player)
.onReceive(videoEnded){ _in
trackOnEnd = trackOnEnd + 1
}
.task(id: trackOnEnd){
await insertAVPlayerItemStartPlaybackEtc()
}
}
}
🙏