kopia lustrzana https://github.com/ryukoposting/Signal-Android
Add audio focus handling to voice note playback.
rodzic
5f6b073cb6
commit
cba1caa5be
|
@ -41,7 +41,7 @@ class VoiceNotePlaybackController(
|
||||||
}
|
}
|
||||||
|
|
||||||
player.playWhenReady = false
|
player.playWhenReady = false
|
||||||
player.setAudioAttributes(attributes, false)
|
player.setAudioAttributes(attributes, true)
|
||||||
|
|
||||||
if (newStreamType == AudioManager.STREAM_VOICE_CALL) {
|
if (newStreamType == AudioManager.STREAM_VOICE_CALL) {
|
||||||
player.playWhenReady = true
|
player.playWhenReady = true
|
||||||
|
|
|
@ -39,7 +39,7 @@ import java.util.stream.Collectors;
|
||||||
/**
|
/**
|
||||||
* ExoPlayer Preparer for Voice Notes. This only supports ACTION_PLAY_FROM_URI
|
* 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 String TAG = Log.tag(VoiceNotePlaybackPreparer.class);
|
||||||
private static final Executor EXECUTOR = Executors.newSingleThreadExecutor();
|
private static final Executor EXECUTOR = Executors.newSingleThreadExecutor();
|
||||||
|
|
|
@ -5,6 +5,7 @@ import com.google.android.exoplayer2.C
|
||||||
import com.google.android.exoplayer2.DefaultLoadControl
|
import com.google.android.exoplayer2.DefaultLoadControl
|
||||||
import com.google.android.exoplayer2.ForwardingPlayer
|
import com.google.android.exoplayer2.ForwardingPlayer
|
||||||
import com.google.android.exoplayer2.SimpleExoPlayer
|
import com.google.android.exoplayer2.SimpleExoPlayer
|
||||||
|
import com.google.android.exoplayer2.audio.AudioAttributes
|
||||||
import org.thoughtcrime.securesms.video.exo.SignalMediaSourceFactory
|
import org.thoughtcrime.securesms.video.exo.SignalMediaSourceFactory
|
||||||
|
|
||||||
class VoiceNotePlayer @JvmOverloads constructor(
|
class VoiceNotePlayer @JvmOverloads constructor(
|
||||||
|
@ -15,7 +16,9 @@ class VoiceNotePlayer @JvmOverloads constructor(
|
||||||
DefaultLoadControl.Builder()
|
DefaultLoadControl.Builder()
|
||||||
.setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)
|
.setBufferDurationsMs(Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE, Integer.MAX_VALUE)
|
||||||
.build()
|
.build()
|
||||||
).build()
|
).build().apply {
|
||||||
|
setAudioAttributes(AudioAttributes.Builder().setContentType(C.AUDIO_CONTENT_TYPE_MUSIC).setUsage(C.USAGE_MEDIA).build(), true)
|
||||||
|
}
|
||||||
) : ForwardingPlayer(internalPlayer) {
|
) : ForwardingPlayer(internalPlayer) {
|
||||||
|
|
||||||
override fun seekTo(windowIndex: Int, positionMs: Long) {
|
override fun seekTo(windowIndex: Int, positionMs: Long) {
|
||||||
|
|
|
@ -43,7 +43,7 @@ class VoiceNotePlaybackControllerTest {
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
verify(player).playWhenReady = false
|
verify(player).playWhenReady = false
|
||||||
verify(player).setAudioAttributes(expected, false)
|
verify(player).setAudioAttributes(expected, true)
|
||||||
verify(player).playWhenReady = true
|
verify(player).playWhenReady = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,7 +61,7 @@ class VoiceNotePlaybackControllerTest {
|
||||||
|
|
||||||
// THEN
|
// THEN
|
||||||
verify(player).playWhenReady = false
|
verify(player).playWhenReady = false
|
||||||
verify(player).setAudioAttributes(expected, false)
|
verify(player).setAudioAttributes(expected, true)
|
||||||
verify(player, Mockito.never()).playWhenReady = true
|
verify(player, Mockito.never()).playWhenReady = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Ładowanie…
Reference in New Issue