androidx / media

Jetpack Media3 support libraries for media use cases, including ExoPlayer, an extensible media player for Android
https://developer.android.com/media/media3
Apache License 2.0
1.72k stars 412 forks source link

Sound disappears when custom equalizer is enabled #1410

Open redectoo opened 5 months ago

redectoo commented 5 months ago

Version

Media3 main branch

More version details

Good afternoon!

On a number of devices with HyperOS,

1) when a custom equalizer is installed, the sound disappears when listening to tracks/switching tracks. If you adjust the volume on the device, the sound is restored.

2) If I add exoplayer::release and create a new ExoPlayer object for each new track, then, judging by messages from users, the sound does not disappear (there is no bug).

3) If the custom equalizer is turned off, the sound does not disappear (there is no bug)

The logs for all three cases contain the same errors.

Sample errors

"W libc : Access denied finding property "ro.vendor.df.effect.conflict" sample_logs.txt "

I give errors for the device in attachment

OS: Android 14

Xiaomi HyperOS 1.0.1.0 Poco x5 5g 22111317 Resolution: 2176x1080 DensityDpi:440

i give dependencies

implementation("androidx.media3:media3-exoplayer:1.3.1") implementation("androidx.media3:media3-ui:1.3.1")

I give code:

private fun createExoplayer() {
    player = ExoPlayer.Builder(applicationContext).build()
    val audioSessionId = player.audioSessionId
    initEqualizer(audioSessionId)
}

@Synchronized
private fun initEqualizer(audioSessionId: Int?) {
    if (audioSessionId == null) {
        stopEqualizer()
        return
    }

    equalizer = Equalizer(150, audioSessionId)

    val shorts = listOf<Short>(0, 0, 0, 0, 0)

    applyBandLevels4AudioSession(shorts)
}

private fun applyBandLevels4AudioSession(bandLevels: List<Short>) {
    val eq = equalizer ?: return
    val minLevel = eq.bandLevelRange[0]
    val maxLevel = eq.bandLevelRange[1]
    val numberOfBands = eq.numberOfBands.toInt()

    if (numberOfBands == 0 || numberOfBands != bandLevels.size) return
    try {
        bandLevels.forEachIndexed { band, level ->
            if (level in (minLevel)..maxLevel) {
                eq.setBandLevel(band.toShort(), level)
            }
        }
        eq.enabled = true
    } catch (e: RuntimeException) {
    }
}

@Synchronized
private fun stopEqualizer() {
    equalizer?.enabled = false
    equalizer?.release()
    equalizer = null
}

//method for playing Track
private fun play(uri: Uri) {

    /*  If you uncomment this the error will go away. But the same errors are written to the logs*/

    // exoplayerRelease()
    // createExoplayer()

    player.setMediaItem(MediaItem.fromUri(uri))
    player.prepare()
    player.playWhenReady = true
}

private fun exoplayerRelease() {
    player.release()
    initEqualizer(null)

}

Devices that reproduce the issue

Poco x5 5g 22111317 Android 14 Xiaomi HyperOS 1.0.1.0

Devices that do not reproduce the issue

No response

Reproducible in the demo app?

Not tested

Reproduction steps

1) Install a custom equalizer

2) Launch tracks 3) Switch tracks

Expected result

Sound is heard

Actual result

No sound is heard

Media

In All mp3 files

Bug Report

bychkovdmitry commented 1 month ago

Any updates on this?

zzmgoing commented 2 weeks ago

Any updates on this?

tujh2 commented 1 week ago

Any updates on this?