Skip to content

Commit

Permalink
Add factory register
Browse files Browse the repository at this point in the history
  • Loading branch information
Him188 committed Dec 30, 2024
1 parent c5e8d79 commit 9104192
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mediamp-api/src/jvmMain/kotlin/MediampPlayerFactory.jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,14 @@ public actual fun MediampPlayer(
.create(context, parentCoroutineContext)

public object MediampPlayerFactoryLoader {
private val factories = ServiceLoader.load(MediampPlayerFactory::class.java).toList()
private var factories = ServiceLoader.load(MediampPlayerFactory::class.java).toList()

/**
* Register a [MediampPlayerFactory] implementation.
*/
public fun register(factory: MediampPlayerFactory<*>) {
factories = (factories + factory).distinctBy { it.forClass }
}

public fun first(): MediampPlayerFactory<*> = factories.firstOrNull()
?: throw IllegalStateException("No MediampPlayerFactory implementation found on the classpath.")
Expand Down

0 comments on commit 9104192

Please sign in to comment.