Search in sources :

Example 6 with AudioAttributes

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);
}
Also used : AudioAttributesCompat(androidx.media.AudioAttributesCompat) AudioAttributes(androidx.media3.common.AudioAttributes) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 7 with AudioAttributes

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);
}
Also used : AudioAttributesCompat(androidx.media.AudioAttributesCompat) AudioAttributes(androidx.media3.common.AudioAttributes) MediaControllerCompat(android.support.v4.media.session.MediaControllerCompat) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Example 8 with AudioAttributes

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);
}
Also used : Bundle(android.os.Bundle) AudioAttributes(androidx.media3.common.AudioAttributes) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 9 with AudioAttributes

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));
}
Also used : EventTime(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)

Example 10 with 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;
    }
}
Also used : AuxEffectInfo(androidx.media3.common.AuxEffectInfo) AudioAttributes(androidx.media3.common.AudioAttributes)

Aggregations

AudioAttributes (androidx.media3.common.AudioAttributes)15 Test (org.junit.Test)11 LargeTest (androidx.test.filters.LargeTest)7 AudioAttributesCompat (androidx.media.AudioAttributesCompat)6 Bundle (android.os.Bundle)5 DeviceInfo (androidx.media3.common.DeviceInfo)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 MediaControllerCompat (android.support.v4.media.session.MediaControllerCompat)3 Nullable (androidx.annotation.Nullable)3 MediaMetadata (androidx.media3.common.MediaMetadata)3 PositionInfo (androidx.media3.common.Player.PositionInfo)3 State (androidx.media3.common.Player.State)3 AuxEffectInfo (androidx.media3.common.AuxEffectInfo)2 MediaItem (androidx.media3.common.MediaItem)2 PlaybackException (androidx.media3.common.PlaybackException)2 PlaybackParameters (androidx.media3.common.PlaybackParameters)2 RepeatMode (androidx.media3.common.Player.RepeatMode)2 Timeline (androidx.media3.common.Timeline)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 SuppressLint (android.annotation.SuppressLint)1