use of androidx.media3.common.AudioAttributes in project media by androidx.
the class MediaSessionCallbackWithMediaControllerCompatTest method adjustVolumeWithLocalVolume.
@Test
public void adjustVolumeWithLocalVolume() throws Exception {
if (Util.SDK_INT >= 21 && audioManager.isVolumeFixed()) {
// This test is not eligible for this device.
return;
}
session = new MediaSession.Builder(context, player).setId("adjustVolumeWithLocalVolume").setSessionCallback(new TestSessionCallback()).build();
controller = new RemoteMediaControllerCompat(context, session.getSessionCompat().getSessionToken(), /* waitForConnection= */
true);
// Here, we intentionally choose STREAM_ALARM in order not to consider
// 'Do Not Disturb' or 'Volume limit'.
int stream = AudioManager.STREAM_ALARM;
int maxVolume = AudioManagerCompat.getStreamMaxVolume(audioManager, stream);
int minVolume = AudioManagerCompat.getStreamMinVolume(audioManager, stream);
Log.d(TAG, "maxVolume=" + maxVolume + ", minVolume=" + minVolume);
if (maxVolume <= minVolume) {
return;
}
handler.postAndSync(() -> {
// Set stream of the session.
AudioAttributes attrs = MediaUtils.convertToAudioAttributes(new AudioAttributesCompat.Builder().setLegacyStreamType(stream).build());
player.audioAttributes = attrs;
player.notifyAudioAttributesChanged(attrs);
});
int originalVolume = audioManager.getStreamVolume(stream);
int direction = originalVolume == minVolume ? AudioManager.ADJUST_RAISE : AudioManager.ADJUST_LOWER;
int targetVolume = originalVolume + direction;
Log.d(TAG, "originalVolume=" + originalVolume + ", targetVolume=" + targetVolume);
controller.adjustVolume(direction, AudioManager.FLAG_SHOW_UI);
PollingCheck.waitFor(VOLUME_CHANGE_TIMEOUT_MS, () -> targetVolume == audioManager.getStreamVolume(stream));
// Set back to original volume.
audioManager.setStreamVolume(stream, originalVolume, /* flags= */
0);
}
use of androidx.media3.common.AudioAttributes in project media by androidx.
the class MediaUtilsTest method convertToAudioAttributes.
@Test
public void convertToAudioAttributes() {
assertThat(MediaUtils.convertToAudioAttributes((AudioAttributesCompat) null)).isSameInstanceAs(AudioAttributes.DEFAULT);
assertThat(MediaUtils.convertToAudioAttributes((MediaControllerCompat.PlaybackInfo) null)).isSameInstanceAs(AudioAttributes.DEFAULT);
int contentType = AudioAttributesCompat.CONTENT_TYPE_MUSIC;
int flags = AudioAttributesCompat.FLAG_AUDIBILITY_ENFORCED;
int usage = AudioAttributesCompat.USAGE_MEDIA;
AudioAttributesCompat aaCompat = new AudioAttributesCompat.Builder().setContentType(contentType).setFlags(flags).setUsage(usage).build();
AudioAttributes aa = new AudioAttributes.Builder().setContentType(contentType).setFlags(flags).setUsage(usage).build();
assertThat(MediaUtils.convertToAudioAttributes(aaCompat)).isEqualTo(aa);
assertThat(MediaUtils.convertToAudioAttributesCompat(aa)).isEqualTo(aaCompat);
}
use of androidx.media3.common.AudioAttributes in project media by androidx.
the class MediaControllerTest method getAudioAttributes_returnsAudioAttributesOfPlayerInSession.
@Test
public void getAudioAttributes_returnsAudioAttributesOfPlayerInSession() throws Exception {
AudioAttributes testAttributes = new AudioAttributes.Builder().setContentType(C.CONTENT_TYPE_MUSIC).build();
Bundle playerConfig = new RemoteMediaSession.MockPlayerConfigBuilder().setAudioAttributes(testAttributes).build();
remoteSession.setPlayer(playerConfig);
MediaController controller = controllerTestRule.createController(remoteSession.getToken());
AudioAttributes attributes = threadTestRule.getHandler().postAndSync(controller::getAudioAttributes);
assertThat(attributes).isEqualTo(testAttributes);
}
use of androidx.media3.common.AudioAttributes in project media by androidx.
the class DefaultAnalyticsCollector method onAudioAttributesChanged.
@Override
public final void onAudioAttributesChanged(AudioAttributes audioAttributes) {
EventTime eventTime = generateReadingMediaPeriodEventTime();
sendEvent(eventTime, AnalyticsListener.EVENT_AUDIO_ATTRIBUTES_CHANGED, listener -> listener.onAudioAttributesChanged(eventTime, audioAttributes));
}
use of androidx.media3.common.AudioAttributes in project media by androidx.
the class DecoderAudioRenderer method handleMessage.
@Override
public void handleMessage(@MessageType int messageType, @Nullable Object message) throws ExoPlaybackException {
switch(messageType) {
case MSG_SET_VOLUME:
audioSink.setVolume((Float) message);
break;
case MSG_SET_AUDIO_ATTRIBUTES:
AudioAttributes audioAttributes = (AudioAttributes) message;
audioSink.setAudioAttributes(audioAttributes);
break;
case MSG_SET_AUX_EFFECT_INFO:
AuxEffectInfo auxEffectInfo = (AuxEffectInfo) message;
audioSink.setAuxEffectInfo(auxEffectInfo);
break;
case MSG_SET_SKIP_SILENCE_ENABLED:
audioSink.setSkipSilenceEnabled((Boolean) message);
break;
case MSG_SET_AUDIO_SESSION_ID:
audioSink.setAudioSessionId((Integer) message);
break;
case MSG_SET_CAMERA_MOTION_LISTENER:
case MSG_SET_CHANGE_FRAME_RATE_STRATEGY:
case MSG_SET_SCALING_MODE:
case MSG_SET_VIDEO_FRAME_METADATA_LISTENER:
case MSG_SET_VIDEO_OUTPUT:
case MSG_SET_WAKEUP_LISTENER:
default:
super.handleMessage(messageType, message);
break;
}
}
Aggregations