Add audio focus handling to voice note playback.

fork-5.53.8
Alex Hart 2022-08-26 11:03:34 -03:00
rodzic 5f6b073cb6
commit cba1caa5be
4 zmienionych plików z 8 dodań i 5 usunięć

Wyświetl plik

@ -41,7 +41,7 @@ class VoiceNotePlaybackController(
}
player.playWhenReady = false
player.setAudioAttributes(attributes, false)
player.setAudioAttributes(attributes, true)
if (newStreamType == AudioManager.STREAM_VOICE_CALL) {
player.playWhenReady = true

Wyświetl plik

@ -39,7 +39,7 @@ import java.util.stream.Collectors;
/**
* ExoPlayer Preparer for Voice Notes. This only supports ACTION_PLAY_FROM_URI
*/
final class VoiceNotePlaybackPreparer implements MediaSessionConnector.PlaybackPreparer {
final class VoiceNotePlaybackPreparer implements MediaSessionConnector.PlaybackPreparer {
private static final String TAG = Log.tag(VoiceNotePlaybackPreparer.class);
private static final Executor EXECUTOR = Executors.newSingleThreadExecutor();

Wyświetl plik

@ -5,6 +5,7 @@ import com.google.android.exoplayer2.C
import com.google.android.exoplayer2.DefaultLoadControl
import com.google.android.exoplayer2.ForwardingPlayer
import com.google.android.exoplayer2.SimpleExoPlayer
import com.google.android.exoplayer2.audio.AudioAttributes
import org.thoughtcrime.securesms.video.exo.SignalMediaSourceFactory
class VoiceNotePlayer @JvmOverloads constructor(
@ -15,7 +16,9 @@ class VoiceNotePlayer @JvmOverloads constructor(
DefaultLoadControl.Builder()
.setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)
.build()
).build()
).build().apply {
setAudioAttributes(AudioAttributes.Builder().setContentType(C.AUDIO_CONTENT_TYPE_MUSIC).setUsage(C.USAGE_MEDIA).build(), true)
}
) : ForwardingPlayer(internalPlayer) {
override fun seekTo(windowIndex: Int, positionMs: Long) {

Wyświetl plik

@ -43,7 +43,7 @@ class VoiceNotePlaybackControllerTest {
// THEN
verify(player).playWhenReady = false
verify(player).setAudioAttributes(expected, false)
verify(player).setAudioAttributes(expected, true)
verify(player).playWhenReady = true
}
@ -61,7 +61,7 @@ class VoiceNotePlaybackControllerTest {
// THEN
verify(player).playWhenReady = false
verify(player).setAudioAttributes(expected, false)
verify(player).setAudioAttributes(expected, true)
verify(player, Mockito.never()).playWhenReady = true
}