Update volume output stream when audioAttributes change.
This commit is contained in:
parent
4b23e60dd6
commit
eae6a971e6
2 changed files with 14 additions and 1 deletions
|
@ -109,7 +109,6 @@ public class VoiceNoteMediaController implements DefaultLifecycleObserver {
|
|||
public void onResume(@NonNull LifecycleOwner owner) {
|
||||
mediaBrowser.disconnect();
|
||||
mediaBrowser.connect();
|
||||
activity.setVolumeControlStream(AudioManager.STREAM_MUSIC);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.google.android.exoplayer2.MediaItem;
|
|||
import com.google.android.exoplayer2.PlaybackException;
|
||||
import com.google.android.exoplayer2.PlaybackParameters;
|
||||
import com.google.android.exoplayer2.Player;
|
||||
import com.google.android.exoplayer2.audio.AudioAttributes;
|
||||
import com.google.android.exoplayer2.ext.mediasession.MediaSessionConnector;
|
||||
import com.google.android.exoplayer2.ui.PlayerNotificationManager;
|
||||
|
||||
|
@ -204,6 +205,19 @@ public class VoiceNotePlaybackService extends MediaBrowserServiceCompat {
|
|||
public void onPlayerError(@NonNull PlaybackException error) {
|
||||
Log.w(TAG, "ExoPlayer error occurred:", error);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAudioAttributesChanged(AudioAttributes audioAttributes) {
|
||||
final int stream;
|
||||
if (audioAttributes.usage == C.USAGE_VOICE_COMMUNICATION) {
|
||||
stream = AudioManager.STREAM_VOICE_CALL;
|
||||
} else {
|
||||
stream = AudioManager.STREAM_MUSIC;
|
||||
}
|
||||
|
||||
Log.i(TAG, "onAudioAttributesChanged: Setting audio stream to " + stream);
|
||||
mediaSession.setPlaybackToLocal(stream);
|
||||
}
|
||||
}
|
||||
|
||||
private @Nullable PlaybackParameters getPlaybackParametersForWindowPosition(int currentWindowIndex) {
|
||||
|
|
Loading…
Add table
Reference in a new issue