From a811e08f13ceb0fe99f01ecec70a9ead63084dc5 Mon Sep 17 00:00:00 2001 From: iliyangermanov Date: Fri, 31 May 2024 15:33:21 +0300 Subject: [PATCH] Add platform capabilities to play sound --- shared/src/androidMain/kotlin/Platform.android.kt | 3 +++ shared/src/commonMain/kotlin/Platform.kt | 1 + shared/src/iosMain/kotlin/Platform.ios.kt | 5 +++++ shared/src/jsMain/kotlin/Platform.js.kt | 6 ++++++ shared/src/jvmMain/kotlin/Platform.jvm.kt | 4 ++++ 5 files changed, 19 insertions(+) diff --git a/shared/src/androidMain/kotlin/Platform.android.kt b/shared/src/androidMain/kotlin/Platform.android.kt index 6a131d59..55891e35 100644 --- a/shared/src/androidMain/kotlin/Platform.android.kt +++ b/shared/src/androidMain/kotlin/Platform.android.kt @@ -22,6 +22,9 @@ class AndroidPlatform : Platform { config(this) } + override fun playSound(soundUrl: String) { + // TODO: Implement + } } actual fun platform(): Platform = AndroidPlatform() \ No newline at end of file diff --git a/shared/src/commonMain/kotlin/Platform.kt b/shared/src/commonMain/kotlin/Platform.kt index 5ac477e1..22829c54 100644 --- a/shared/src/commonMain/kotlin/Platform.kt +++ b/shared/src/commonMain/kotlin/Platform.kt @@ -4,6 +4,7 @@ interface Platform { val name: String fun log(level: LogLevel, msg: String) fun httpClient(config: HttpClientConfig<*>.() -> Unit = {}): HttpClient + fun playSound(soundUrl: String) } enum class LogLevel { diff --git a/shared/src/iosMain/kotlin/Platform.ios.kt b/shared/src/iosMain/kotlin/Platform.ios.kt index 6230cd66..432fc062 100644 --- a/shared/src/iosMain/kotlin/Platform.ios.kt +++ b/shared/src/iosMain/kotlin/Platform.ios.kt @@ -14,6 +14,11 @@ class IOSPlatform : Platform { ): HttpClient = HttpClient(Darwin) { config(this) } + + override fun playSound(soundUrl: String) { + // TODO: Implement + } } + actual fun platform(): Platform = IOSPlatform() \ No newline at end of file diff --git a/shared/src/jsMain/kotlin/Platform.js.kt b/shared/src/jsMain/kotlin/Platform.js.kt index e85b826b..da69aa20 100644 --- a/shared/src/jsMain/kotlin/Platform.js.kt +++ b/shared/src/jsMain/kotlin/Platform.js.kt @@ -1,5 +1,6 @@ import io.ktor.client.* import io.ktor.client.engine.js.* +import org.w3c.dom.Audio class JsPlatform : Platform { override val name: String = "Web with Kotlin/JS" @@ -13,6 +14,11 @@ class JsPlatform : Platform { ): HttpClient = HttpClient(Js) { config(this) } + + override fun playSound(soundUrl: String) { + val audio = Audio(soundUrl) + audio.play() + } } actual fun platform(): Platform = JsPlatform() \ No newline at end of file diff --git a/shared/src/jvmMain/kotlin/Platform.jvm.kt b/shared/src/jvmMain/kotlin/Platform.jvm.kt index ac36d27d..96a35c7e 100644 --- a/shared/src/jvmMain/kotlin/Platform.jvm.kt +++ b/shared/src/jvmMain/kotlin/Platform.jvm.kt @@ -13,6 +13,10 @@ class JVMPlatform: Platform { ): HttpClient = HttpClient(Java) { config(this) } + + override fun playSound(soundUrl: String) { + // TODO: Implement + } } actual fun platform(): Platform = JVMPlatform() \ No newline at end of file