I want to create a SharePlay Application that plays a video without using AVPlayer. From what I have found in the documentation I think I should use the AVDelegatingPlaybackCoordinator. But I can't get it to work. I have created an AVPlaybackCoordinatorPlaybackControlDelegate that looks like this:
class CustomControlDelegate: NSObject, AVPlaybackCoordinatorPlaybackControlDelegate {
let player: SomePlayer
init(player: SomePlayer) {
self.player = player
}
func playbackCoordinator(_ coordinator: AVDelegatingPlaybackCoordinator, didIssue playCommand: AVDelegatingPlaybackCoordinatorPlayCommand, completionHandler: @escaping () -> Void) {
print("playing")
player.play()
}
func playbackCoordinator(_ coordinator: AVDelegatingPlaybackCoordinator, didIssue pauseCommand: AVDelegatingPlaybackCoordinatorPauseCommand, completionHandler: @escaping () -> Void) {
print("pausing")
player.pause()
}
func playbackCoordinator(_ coordinator: AVDelegatingPlaybackCoordinator, didIssue seekCommand: AVDelegatingPlaybackCoordinatorSeekCommand, completionHandler: @escaping () -> Void) {
print("seek")
}
func playbackCoordinator(_ coordinator: AVDelegatingPlaybackCoordinator, didIssue bufferingCommand: AVDelegatingPlaybackCoordinatorBufferingCommand, completionHandler: @escaping () -> Void) {
print("buffer")
}
}
The player.play()
and player.pause()
methods work when I call them myself, so this is not the issue.
I Create the coordinator like this:
delegate = SomePlayerControlDelegate(player: somePlayer)
coordinator = AVDelegatingPlaybackCoordinator(playbackControlDelegate: delegate)
When I want to start the player I use this code:
coordinator.coordinateRateChange(to: 1)
And to pause I use:
coordinator.coordinateRateChange(to: 0)
But nothing happens. The playbackCoordinator
functions do not get called at all.
Am I using the wrong functions?