Add audio focus handling to voice note playback.

This commit is contained in:
Alex Hart
2022-08-26 11:03:34 -03:00
parent 5f6b073cb6
commit cba1caa5be
4 changed files with 8 additions and 5 deletions

View File

@@ -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

View File

@@ -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();

View File

@@ -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) {