Search in sources :

Example 1 with ShadowAudioManager

use of org.robolectric.shadows.ShadowAudioManager in project ExoPlayer by google.

the class ExoPlayerTest method audioFocusDenied.

@Test
public void audioFocusDenied() throws Exception {
    ShadowAudioManager shadowAudioManager = shadowOf(context.getSystemService(AudioManager.class));
    shadowAudioManager.setNextFocusRequestResponse(AudioManager.AUDIOFOCUS_REQUEST_FAILED);
    PlayerStateGrabber playerStateGrabber = new PlayerStateGrabber();
    ActionSchedule actionSchedule = new ActionSchedule.Builder(TAG).setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */
    true).play().waitForPlaybackState(Player.STATE_READY).executeRunnable(playerStateGrabber).build();
    AtomicBoolean seenPlaybackSuppression = new AtomicBoolean();
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onPlaybackSuppressionReasonChanged(@Player.PlaybackSuppressionReason int playbackSuppressionReason) {
            seenPlaybackSuppression.set(true);
        }
    };
    new ExoPlayerTestRunner.Builder(context).setActionSchedule(actionSchedule).setPlayerListener(listener).build().start().blockUntilActionScheduleFinished(TIMEOUT_MS);
    assertThat(playerStateGrabber.playWhenReady).isFalse();
    assertThat(seenPlaybackSuppression.get()).isFalse();
}
Also used : AudioManager(android.media.AudioManager) ShadowAudioManager(org.robolectric.shadows.ShadowAudioManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Listener(com.google.android.exoplayer2.Player.Listener) TransferListener(com.google.android.exoplayer2.upstream.TransferListener) Listener(com.google.android.exoplayer2.Player.Listener) MediaSourceEventListener(com.google.android.exoplayer2.source.MediaSourceEventListener) AnalyticsListener(com.google.android.exoplayer2.analytics.AnalyticsListener) DrmSessionEventListener(com.google.android.exoplayer2.drm.DrmSessionEventListener) ShadowAudioManager(org.robolectric.shadows.ShadowAudioManager) ActionSchedule(com.google.android.exoplayer2.testutil.ActionSchedule) ExoPlayerTestRunner(com.google.android.exoplayer2.testutil.ExoPlayerTestRunner) Test(org.junit.Test)

Aggregations

AudioManager (android.media.AudioManager)1 Listener (com.google.android.exoplayer2.Player.Listener)1 AnalyticsListener (com.google.android.exoplayer2.analytics.AnalyticsListener)1 DrmSessionEventListener (com.google.android.exoplayer2.drm.DrmSessionEventListener)1 MediaSourceEventListener (com.google.android.exoplayer2.source.MediaSourceEventListener)1 ActionSchedule (com.google.android.exoplayer2.testutil.ActionSchedule)1 ExoPlayerTestRunner (com.google.android.exoplayer2.testutil.ExoPlayerTestRunner)1 TransferListener (com.google.android.exoplayer2.upstream.TransferListener)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 ShadowAudioManager (org.robolectric.shadows.ShadowAudioManager)1