A Kotlin Multiplatform library for emitting a system media session.
Windows implementation adapted from JavaMediaTransportControls by Selemba1000.
mediasession-kt currently supports the following Kotlin platforms:
- JVM (tested on x86_64 but may work on other architectures)
- Linux
- Windows
- Native
- Linux x86_64
- Linux ARM64
- Windows x86_64
- Add the Maven Central repository to your dependency resolution configuration
repositories {
mavenCentral()
}
- Add the following line to your dependencies (replace
<version>
with the desired mediasession-kt version)
implementation("dev.toastbits:mediasession:<version>")
var time = TimeSource.Monotonic.markNow()
// Initialise the media session
val session: MediaSession =
MediaSession.create(
getPositionMs = { time.elapsedNow().inWholeMilliseconds }
)!!
// Set callbacks
session.onPlay = {
println("onPlay called")
}
session.onSeek = { by_ms: Long ->
println("onSeek called")
}
// Set properties
session.setIdentity("mediasession.sample")
session.setPlaybackStatus(MediaSessionPlaybackStatus.PAUSED)
session.setMetadata(
MediaSessionMetadata(
title = "Title",
)
)
// Enable session (asynchronous)
session.setEnabled(true)