I'm trying to see if I can get audio playback work...
# kotlin-native
a
I'm trying to see if I can get audio playback working on iOS with
AVAudioPlayer
, and no matter what I do, just instantiating it gives me a null pointer exception. Based on some other threads here in this Slack, the latest thing I'm trying is:
Copy code
lateinit var player: AVAudioPlayer
    memScoped {
        val errorPtr: ObjCObjectVar<NSError?> = alloc<ObjCObjectVar<NSError?>>()
        player = AVAudioPlayer(mp3Url!!, errorPtr.ptr)
        //println(errorPtr.ptr) //Will be null if the call succeeds.
    }
My theory is that I'm not passing the right thing for the second argument of the constructor; it's the weird objc error pointer thingy. That said, the argument says it is nullable, so it wold seem passing null should work there. I tried that but have the same NPE. Has anyone else gotten
AVAudioPlayer
to work? Gotten the objs error pointers to work?
j
Havent tested audio variant, but you can play audio in av player as well, easier API. Example: https://github.com/ayodelekehinde/Kicks/blob/master/shared%2Fsrc%2FiosMain%2Fkotlin%2Fio%2Fgithub%2Fkicks%2Faudioplayer%2FAudioPlayer.kt
https://developer.apple.com/documentation/avfaudio/avaudioplayer From docs I cant see any variant of support error pointer. Anything in particular want to achieve?
a
Thanks. So the kicker with all this is that I need to do some things with the "now playing" functionality on-device which appears to have issues with AVPlayer
So I want to try out AVAudioPlayer if I can
m
Use AVPlayer and just don’t provide a view for it. Then you can easily expand functionality to video without much hassle