Improve audio focus management (#4707)
* Extract Audio focus management to its own modules. * Request Audio focus when playing a voice message. * Add missing dependency. (and remove a duplicated one) * Request Audio focus when playing a video/audio in the media viewer. * Pause audio when audio focus is lost. * Rename class * Fix tests * Fix detekt issue. * Audio focus: let the system handle automatic ducking when playing media. * Document and update API * Remove useless space.
This commit is contained in:
parent
3cf8b04a07
commit
93499910ba
24 changed files with 341 additions and 49 deletions
19
libraries/audio/test/build.gradle.kts
Normal file
19
libraries/audio/test/build.gradle.kts
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
plugins {
|
||||
id("io.element.android-library")
|
||||
}
|
||||
|
||||
android {
|
||||
namespace = "io.element.android.libraries.audio.test"
|
||||
}
|
||||
|
||||
dependencies {
|
||||
api(projects.libraries.audio.api)
|
||||
implementation(projects.tests.testutils)
|
||||
}
|
||||
|
|
@ -0,0 +1,28 @@
|
|||
/*
|
||||
* Copyright 2025 New Vector Ltd.
|
||||
*
|
||||
* SPDX-License-Identifier: AGPL-3.0-only OR LicenseRef-Element-Commercial
|
||||
* Please see LICENSE files in the repository root for full details.
|
||||
*/
|
||||
|
||||
package io.element.android.libraries.mediaplayer.test
|
||||
|
||||
import io.element.android.libraries.audio.api.AudioFocus
|
||||
import io.element.android.libraries.audio.api.AudioFocusRequester
|
||||
import io.element.android.tests.testutils.lambda.lambdaError
|
||||
|
||||
class FakeAudioFocus(
|
||||
private val requestAudioFocusResult: (AudioFocusRequester, () -> Unit) -> Unit = { _, _ -> lambdaError() },
|
||||
private val releaseAudioFocusResult: () -> Unit = { lambdaError() },
|
||||
) : AudioFocus {
|
||||
override fun requestAudioFocus(
|
||||
requester: AudioFocusRequester,
|
||||
onFocusLost: () -> Unit,
|
||||
) {
|
||||
requestAudioFocusResult(requester, onFocusLost)
|
||||
}
|
||||
|
||||
override fun releaseAudioFocus() {
|
||||
releaseAudioFocusResult()
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue