Add MIDI playback (#6770)
* Add MIDI playback * Implement PR suggestions
This commit is contained in:
parent
a89d37297f
commit
e6c3a8ff1d
6 changed files with 19 additions and 4 deletions
|
|
@ -111,6 +111,7 @@ androidx_media3_ui = { module = "androidx.media3:media3-ui", version.ref = "medi
|
|||
androidx_media3_transformer = { module = "androidx.media3:media3-transformer", version.ref = "media3" }
|
||||
androidx_media3_effect = { module = "androidx.media3:media3-effect", version.ref = "media3" }
|
||||
androidx_media3_common = { module = "androidx.media3:media3-common", version.ref = "media3" }
|
||||
androidx_media3_exoplayer_midi = { module = "androidx.media3:media3-exoplayer-midi", version.ref = "media3" }
|
||||
androidx_biometric = "androidx.biometric:biometric-ktx:1.4.0-alpha02"
|
||||
|
||||
androidx_activity_activity = { module = "androidx.activity:activity", version.ref = "activity" }
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@ dependencies {
|
|||
implementation(libs.coroutines.core)
|
||||
implementation(libs.coil.compose)
|
||||
implementation(libs.androidx.media3.exoplayer)
|
||||
implementation(libs.androidx.media3.exoplayer.midi)
|
||||
implementation(libs.androidx.media3.ui)
|
||||
implementation(libs.telephoto.zoomableimage)
|
||||
implementation(libs.vanniktech.blurhash)
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ fun MediaAudioView(
|
|||
modifier: Modifier = Modifier,
|
||||
isDisplayed: Boolean = true,
|
||||
) {
|
||||
val exoPlayer = rememberExoPlayer()
|
||||
val exoPlayer = rememberExoPlayer(forAudioOnly = true)
|
||||
ExoPlayerMediaAudioView(
|
||||
isDisplayed = isDisplayed,
|
||||
localMediaViewState = localMediaViewState,
|
||||
|
|
|
|||
|
|
@ -8,14 +8,18 @@
|
|||
|
||||
package io.element.android.libraries.mediaviewer.impl.local.player
|
||||
|
||||
import androidx.annotation.OptIn
|
||||
import androidx.compose.runtime.Composable
|
||||
import androidx.compose.runtime.remember
|
||||
import androidx.compose.ui.platform.LocalContext
|
||||
import androidx.compose.ui.platform.LocalInspectionMode
|
||||
import androidx.media3.common.util.UnstableApi
|
||||
import androidx.media3.exoplayer.DefaultRenderersFactory
|
||||
import androidx.media3.exoplayer.ExoPlayer
|
||||
|
||||
@OptIn(UnstableApi::class)
|
||||
@Composable
|
||||
fun rememberExoPlayer(): ExoPlayer {
|
||||
fun rememberExoPlayer(forAudioOnly: Boolean): ExoPlayer {
|
||||
return if (LocalInspectionMode.current) {
|
||||
remember {
|
||||
ExoPlayerForPreview()
|
||||
|
|
@ -23,7 +27,14 @@ fun rememberExoPlayer(): ExoPlayer {
|
|||
} else {
|
||||
val context = LocalContext.current
|
||||
remember {
|
||||
ExoPlayer.Builder(context).build()
|
||||
if (forAudioOnly) {
|
||||
// Required for media3-exoplayer-midi to decode MIDI samples produced by DefaultExtractorsFactory.
|
||||
val renderersFactory = DefaultRenderersFactory(context)
|
||||
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON)
|
||||
ExoPlayer.Builder(context, renderersFactory).build()
|
||||
} else {
|
||||
ExoPlayer.Builder(context).build()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ fun MediaVideoView(
|
|||
audioFocus: AudioFocus?,
|
||||
modifier: Modifier = Modifier,
|
||||
) {
|
||||
val exoPlayer = rememberExoPlayer()
|
||||
val exoPlayer = rememberExoPlayer(forAudioOnly = false)
|
||||
ExoPlayerMediaVideoView(
|
||||
isDisplayed = isDisplayed,
|
||||
localMediaViewState = localMediaViewState,
|
||||
|
|
|
|||
|
|
@ -21,6 +21,8 @@ dependencyResolutionManagement {
|
|||
url = uri("https://www.jitpack.io")
|
||||
content {
|
||||
includeModule("com.github.matrix-org", "matrix-analytics-events")
|
||||
// Required transitively by androidx.media3:media3-exoplayer-midi for MIDI playback.
|
||||
includeModule("com.github.philburk", "jsyn")
|
||||
}
|
||||
}
|
||||
google()
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue