Hi all, i have a class that wraps AVPlayer and rig...
# kotlin-native
m
Hi all, i have a class that wraps AVPlayer and right now i am a bit stuck. I need to create a listener to when a track is completed. I figured i would use something like this:
Copy code
NSNotificationCenter.defaultCenter.addObserver(
    observer = avPlayer,
    selector = NSSelectorFromString(TrackCompletedListener::playerDidFinishPlaying.name + ":"),
        name = AVPlayerItemDidPlayToEndTimeNotification,
    `object` = null,
)
Problem is i get this exception when the track is completed:
Copy code
*** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[AVPlayer playerDidFinishPlaying:]: unrecognized selector sent to instance 0x600000014660'
And i have no clue on how to fix it. EDIT on how i fixed it in thread ->
Copy code
NSNotificationCenter.defaultCenter.addObserverForName(
            name = AVPlayerItemDidPlayToEndTimeNotification,
            `object` = avPlayer.currentItem,
            queue = null,
        ) {
            println("Track completed")
        }
Use addObserverForName instead.
a
Hey @Mats-Hjalmar I'm actually trying some things with media playback myself right now; are you using AVPlayer for video or audio playback?
m
@Andrew Watson Yea, when i implemented playlists i noticed there was an AVPlayerQueue but problem with that is that exoplayer has more functionality so i decided to let my wrapper deal with the playlist logic and stick to AVPlayer