Has anyone written a Audio Player wrapper around `...
# compose-ios
m
Has anyone written a Audio Player wrapper around
AVPlayer
but more specifically not using interoperability with Swift/Objective-C using
expect/actual
Rather has anyone built an interface
PlatformMediaPlayer
which then has an implementation on each platform and is injected into the common code via DI (specifically Koin). ?
Copy code
enum class PlaybackState {
    PLAYING, PAUSED, STOPPED
}

interface PlatformMediaPlayer {
    fun play()
    fun pause()
    val isPlaying: Boolean
    val playbackState: StateFlow<PlaybackState>
}
Copy code
fun initKoin(nativeModule: PlatformMediaPlayer) {
    // Start Koin
    val koinApp = startKoin {
        modules(appModule, module {
            single { nativeModule }
        })
    }.koin
}
Then in my iOS app:
Copy code
@main
struct iOSApp: App {
    init() {
        HelperKtKt.doInitKoin(
            nativeModule: MediaPlayer()
        )
    }
perhaps I wonder what best approach is for the playback state. it would be nice if I could provide a published state
c
Is there an issue or what? I don’t really understand your question.
m
no an issue. curious to know if anyone has any advice/implementation of a AVPlayer wrapper written natively on iOS - injected to a KMP Compose app
c
I think which ever way works, that’s the beauty of KMP