new: add Android audio player
This commit is contained in:
@@ -6,6 +6,7 @@ androidTargetSdk = "36"
|
|||||||
androidxActivity = "1.13.0"
|
androidxActivity = "1.13.0"
|
||||||
androidxCore = "1.19.0"
|
androidxCore = "1.19.0"
|
||||||
androidxLifecycle = "2.11.0-beta01"
|
androidxLifecycle = "2.11.0-beta01"
|
||||||
|
media3 = "1.10.1"
|
||||||
navigation3 = "1.1.1"
|
navigation3 = "1.1.1"
|
||||||
composeMultiplatform = "1.11.1"
|
composeMultiplatform = "1.11.1"
|
||||||
kotlin = "2.4.0"
|
kotlin = "2.4.0"
|
||||||
@@ -34,6 +35,8 @@ kotlinx-coroutinesSwing = { module = "org.jetbrains.kotlinx:kotlinx-coroutines-s
|
|||||||
lifecycle-runtimeCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidxLifecycle" }
|
lifecycle-runtimeCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-runtime-compose", version.ref = "androidxLifecycle" }
|
||||||
lifecycle-viewmodelCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" }
|
lifecycle-viewmodelCompose = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-compose", version.ref = "androidxLifecycle" }
|
||||||
lifecycle-viewmodelNavigation3 = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-navigation3", version.ref = "androidxLifecycle" }
|
lifecycle-viewmodelNavigation3 = { module = "org.jetbrains.androidx.lifecycle:lifecycle-viewmodel-navigation3", version.ref = "androidxLifecycle" }
|
||||||
|
media3-exoplayer = { module = "androidx.media3:media3-exoplayer", version.ref = "media3" }
|
||||||
|
media3-common = { module = "androidx.media3:media3-common", version.ref = "media3" }
|
||||||
navigation3 = { module = "org.jetbrains.androidx.navigation3:navigation3-ui", version.ref = "navigation3" }
|
navigation3 = { module = "org.jetbrains.androidx.navigation3:navigation3-ui", version.ref = "navigation3" }
|
||||||
wrappers-browser = { module = "org.jetbrains.kotlin-wrappers:kotlin-browser", version.ref = "kotlinWrappers" }
|
wrappers-browser = { module = "org.jetbrains.kotlin-wrappers:kotlin-browser", version.ref = "kotlinWrappers" }
|
||||||
|
|
||||||
|
|||||||
@@ -56,6 +56,10 @@ kotlin {
|
|||||||
sourceSets {
|
sourceSets {
|
||||||
androidMain.dependencies {
|
androidMain.dependencies {
|
||||||
implementation(libs.compose.uiToolingPreview)
|
implementation(libs.compose.uiToolingPreview)
|
||||||
|
|
||||||
|
// Player audio
|
||||||
|
implementation(libs.media3.exoplayer)
|
||||||
|
implementation(libs.media3.common)
|
||||||
}
|
}
|
||||||
commonMain.dependencies {
|
commonMain.dependencies {
|
||||||
implementation(libs.compose.runtime)
|
implementation(libs.compose.runtime)
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
package fr.ajaury.gwenedeg.di
|
||||||
|
|
||||||
|
import fr.ajaury.gwenedeg.player.AndroidAudioPlayer
|
||||||
|
import fr.ajaury.gwenedeg.player.AudioPlayer
|
||||||
|
import org.koin.core.module.Module
|
||||||
|
import org.koin.dsl.module
|
||||||
|
|
||||||
|
actual val platformModule: Module = module {
|
||||||
|
single<AudioPlayer> { AndroidAudioPlayer(context = get()) }
|
||||||
|
}
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
package fr.ajaury.gwenedeg.player
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import androidx.media3.common.MediaItem
|
||||||
|
import androidx.media3.exoplayer.ExoPlayer
|
||||||
|
import gwenedeg.shared.generated.resources.Res
|
||||||
|
|
||||||
|
class AndroidAudioPlayer(
|
||||||
|
context: Context,
|
||||||
|
) : AudioPlayer {
|
||||||
|
private val player = ExoPlayer.Builder(context).build()
|
||||||
|
|
||||||
|
override fun load(filePath: String) {
|
||||||
|
val mediaItem = MediaItem.fromUri(Res.getUri(filePath))
|
||||||
|
player.setMediaItem(mediaItem)
|
||||||
|
player.prepare()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun play() {
|
||||||
|
player.play()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pause() {
|
||||||
|
player.pause()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun stop() {
|
||||||
|
player.stop()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun release() {
|
||||||
|
player.release()
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,7 +7,8 @@ import androidx.compose.ui.tooling.preview.Preview
|
|||||||
import androidx.navigation3.runtime.NavEntry
|
import androidx.navigation3.runtime.NavEntry
|
||||||
import androidx.navigation3.ui.NavDisplay
|
import androidx.navigation3.ui.NavDisplay
|
||||||
import androidx.savedstate.compose.serialization.serializers.SnapshotStateListSerializer
|
import androidx.savedstate.compose.serialization.serializers.SnapshotStateListSerializer
|
||||||
import fr.ajaury.gwenedeg.di.appModule
|
import fr.ajaury.gwenedeg.di.platformModule
|
||||||
|
import fr.ajaury.gwenedeg.di.sharedModule
|
||||||
import fr.ajaury.gwenedeg.navigation.Route
|
import fr.ajaury.gwenedeg.navigation.Route
|
||||||
import fr.ajaury.gwenedeg.player.ui.PlayerScreen
|
import fr.ajaury.gwenedeg.player.ui.PlayerScreen
|
||||||
import fr.ajaury.gwenedeg.records.ui.RecordsScreen
|
import fr.ajaury.gwenedeg.records.ui.RecordsScreen
|
||||||
@@ -20,7 +21,10 @@ import org.koin.dsl.koinConfiguration
|
|||||||
fun App() {
|
fun App() {
|
||||||
KoinApplication(
|
KoinApplication(
|
||||||
configuration = koinConfiguration {
|
configuration = koinConfiguration {
|
||||||
modules(appModule)
|
modules(
|
||||||
|
sharedModule,
|
||||||
|
platformModule,
|
||||||
|
)
|
||||||
},
|
},
|
||||||
) {
|
) {
|
||||||
val serializer = SnapshotStateListSerializer<Route>()
|
val serializer = SnapshotStateListSerializer<Route>()
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
package fr.ajaury.gwenedeg.di
|
package fr.ajaury.gwenedeg.di
|
||||||
|
|
||||||
|
import fr.ajaury.gwenedeg.player.ui.viewmodel.PlayerViewModel
|
||||||
import fr.ajaury.gwenedeg.records.data.InMemoryRecordRepository
|
import fr.ajaury.gwenedeg.records.data.InMemoryRecordRepository
|
||||||
import fr.ajaury.gwenedeg.records.domain.RecordRepository
|
import fr.ajaury.gwenedeg.records.domain.RecordRepository
|
||||||
import fr.ajaury.gwenedeg.records.ui.viewmodel.RecordsViewModel
|
import fr.ajaury.gwenedeg.records.ui.viewmodel.RecordsViewModel
|
||||||
|
import org.koin.core.module.Module
|
||||||
import org.koin.core.module.dsl.bind
|
import org.koin.core.module.dsl.bind
|
||||||
import org.koin.core.module.dsl.factoryOf
|
import org.koin.core.module.dsl.factoryOf
|
||||||
import org.koin.core.module.dsl.viewModelOf
|
import org.koin.core.module.dsl.viewModelOf
|
||||||
import org.koin.dsl.module
|
import org.koin.dsl.module
|
||||||
|
|
||||||
val appModule = module {
|
val sharedModule = module {
|
||||||
factoryOf(::InMemoryRecordRepository) { bind<RecordRepository>() }
|
factoryOf(::InMemoryRecordRepository) { bind<RecordRepository>() }
|
||||||
viewModelOf(::RecordsViewModel)
|
viewModelOf(::RecordsViewModel)
|
||||||
|
viewModelOf(::PlayerViewModel)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
expect val platformModule: Module
|
||||||
|
|||||||
@@ -0,0 +1,13 @@
|
|||||||
|
package fr.ajaury.gwenedeg.player
|
||||||
|
|
||||||
|
interface AudioPlayer {
|
||||||
|
fun play()
|
||||||
|
|
||||||
|
fun pause()
|
||||||
|
|
||||||
|
fun stop()
|
||||||
|
|
||||||
|
fun release()
|
||||||
|
|
||||||
|
fun load(filePath: String)
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package fr.ajaury.gwenedeg.di
|
||||||
|
|
||||||
|
import org.koin.core.module.Module
|
||||||
|
|
||||||
|
actual val platformModule: Module
|
||||||
|
get() = TODO("Not yet implemented")
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package fr.ajaury.gwenedeg.player
|
||||||
|
|
||||||
|
class IosAudioPlayer : AudioPlayer {
|
||||||
|
override fun play(file: String) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pause() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun stop() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun release() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun load(file: String) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package fr.ajaury.gwenedeg.player
|
||||||
|
|
||||||
|
class JsAudioPlayer : AudioPlayer {
|
||||||
|
override fun play(file: String) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pause() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun stop() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun release() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun load(filePath: String) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
package fr.ajaury.gwenedeg.di
|
||||||
|
|
||||||
|
import org.koin.core.module.Module
|
||||||
|
|
||||||
|
actual val platformModule: Module
|
||||||
|
get() = TODO("Not yet implemented")
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package fr.ajaury.gwenedeg.player
|
||||||
|
|
||||||
|
class JvmAudioPlayer : AudioPlayer {
|
||||||
|
override fun play(file: String) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pause() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun stop() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun release() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun load(filePath: String) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package fr.ajaury.gwenedeg.player
|
||||||
|
|
||||||
|
class WasmAudioPlayer : AudioPlayer {
|
||||||
|
override fun play(file: String) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun pause() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun stop() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun release() {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun load(filePath: String) {
|
||||||
|
TODO("Not yet implemented")
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package fr.ajaury.gwenedeg.di
|
||||||
|
|
||||||
|
actual val platformModule: org.koin.core.module.Module
|
||||||
|
get() = TODO("Not yet implemented")
|
||||||
Reference in New Issue
Block a user