Skip to content

Commit

Permalink
Add platform capabilities to play sound
Browse files Browse the repository at this point in the history
  • Loading branch information
ILIYANGERMANOV committed May 31, 2024
1 parent 818c15b commit a811e08
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions shared/src/androidMain/kotlin/Platform.android.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class AndroidPlatform : Platform {
config(this)
}

override fun playSound(soundUrl: String) {
// TODO: Implement
}
}

actual fun platform(): Platform = AndroidPlatform()
1 change: 1 addition & 0 deletions shared/src/commonMain/kotlin/Platform.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
5 changes: 5 additions & 0 deletions shared/src/iosMain/kotlin/Platform.ios.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ class IOSPlatform : Platform {
): HttpClient = HttpClient(Darwin) {
config(this)
}

override fun playSound(soundUrl: String) {
// TODO: Implement
}
}


actual fun platform(): Platform = IOSPlatform()
6 changes: 6 additions & 0 deletions shared/src/jsMain/kotlin/Platform.js.kt
Original file line number Diff line number Diff line change
@@ -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"
Expand All @@ -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()
4 changes: 4 additions & 0 deletions shared/src/jvmMain/kotlin/Platform.jvm.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@ class JVMPlatform: Platform {
): HttpClient = HttpClient(Java) {
config(this)
}

override fun playSound(soundUrl: String) {
// TODO: Implement
}
}

actual fun platform(): Platform = JVMPlatform()

0 comments on commit a811e08

Please sign in to comment.