Search in sources :

Example 1 with AudioPlaybackConfiguration

use of android.media.AudioPlaybackConfiguration in project robolectric by robolectric.

the class ShadowAudioManager method setActivePlaybackConfigurationsFor.

/**
 * Same as {@link #setActivePlaybackConfigurationsFor(List)}, but also notifies callbacks if
 * notifyCallbackListeners is true.
 */
@TargetApi(VERSION_CODES.O)
public void setActivePlaybackConfigurationsFor(List<AudioAttributes> audioAttributes, boolean notifyCallbackListeners) {
    if (RuntimeEnvironment.getApiLevel() < O) {
        throw new UnsupportedOperationException("setActivePlaybackConfigurationsFor is not supported on API " + RuntimeEnvironment.getApiLevel());
    }
    activePlaybackConfigurations = new ArrayList<>(audioAttributes.size());
    for (AudioAttributes audioAttribute : audioAttributes) {
        AudioPlaybackConfiguration configuration = createAudioPlaybackConfiguration(audioAttribute);
        activePlaybackConfigurations.add(configuration);
    }
    if (notifyCallbackListeners) {
        for (AudioManager.AudioPlaybackCallback callback : audioPlaybackCallbacks) {
            callback.onPlaybackConfigChanged(activePlaybackConfigurations);
        }
    }
}
Also used : AudioManager(android.media.AudioManager) AudioPlaybackConfiguration(android.media.AudioPlaybackConfiguration) AudioAttributes(android.media.AudioAttributes) TargetApi(android.annotation.TargetApi)

Example 2 with AudioPlaybackConfiguration

use of android.media.AudioPlaybackConfiguration in project robolectric by robolectric.

the class ShadowAudioManager method createAudioPlaybackConfiguration.

protected AudioPlaybackConfiguration createAudioPlaybackConfiguration(AudioAttributes audioAttributes) {
    // use reflection to call package private APIs
    if (RuntimeEnvironment.getApiLevel() >= S) {
        PlayerBase.PlayerIdCard playerIdCard = ReflectionHelpers.callConstructor(PlayerBase.PlayerIdCard.class, ReflectionHelpers.ClassParameter.from(int.class, 0), /* type */
        ReflectionHelpers.ClassParameter.from(AudioAttributes.class, audioAttributes), ReflectionHelpers.ClassParameter.from(IPlayer.class, null), ReflectionHelpers.ClassParameter.from(int.class, 0));
        AudioPlaybackConfiguration config = ReflectionHelpers.callConstructor(AudioPlaybackConfiguration.class, ReflectionHelpers.ClassParameter.from(PlayerBase.PlayerIdCard.class, playerIdCard), ReflectionHelpers.ClassParameter.from(int.class, 0), /* piid */
        ReflectionHelpers.ClassParameter.from(int.class, 0), /* uid */
        ReflectionHelpers.ClassParameter.from(int.class, 0));
        ReflectionHelpers.setField(config, "mPlayerState", AudioPlaybackConfiguration.PLAYER_STATE_STARTED);
        return config;
    } else {
        PlayerBase.PlayerIdCard playerIdCard = ReflectionHelpers.callConstructor(PlayerBase.PlayerIdCard.class, from(int.class, 0), /* type */
        from(AudioAttributes.class, audioAttributes), from(IPlayer.class, null));
        AudioPlaybackConfiguration config = ReflectionHelpers.callConstructor(AudioPlaybackConfiguration.class, from(PlayerBase.PlayerIdCard.class, playerIdCard), from(int.class, 0), /* piid */
        from(int.class, 0), /* uid */
        from(int.class, 0));
        ReflectionHelpers.setField(config, "mPlayerState", AudioPlaybackConfiguration.PLAYER_STATE_STARTED);
        return config;
    }
}
Also used : IPlayer(android.media.IPlayer) AudioPlaybackConfiguration(android.media.AudioPlaybackConfiguration) PlayerBase(android.media.PlayerBase) AudioAttributes(android.media.AudioAttributes)

Example 3 with AudioPlaybackConfiguration

use of android.media.AudioPlaybackConfiguration in project robolectric by robolectric.

the class ShadowAudioManagerTest method getActivePlaybackConfigurations.

@Test
@Config(minSdk = O)
public void getActivePlaybackConfigurations() {
    assertThat(audioManager.getActivePlaybackConfigurations()).isEmpty();
    AudioAttributes movieAttribute = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MOVIE).build();
    AudioAttributes musicAttribute = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build();
    shadowOf(audioManager).setActivePlaybackConfigurationsFor(Arrays.asList(movieAttribute, musicAttribute));
    List<AudioPlaybackConfiguration> playbackConfigurations = audioManager.getActivePlaybackConfigurations();
    assertThat(playbackConfigurations).hasSize(2);
    assertThat(playbackConfigurations.get(0).getAudioAttributes()).isEqualTo(movieAttribute);
    assertThat(playbackConfigurations.get(1).getAudioAttributes()).isEqualTo(musicAttribute);
}
Also used : AudioPlaybackConfiguration(android.media.AudioPlaybackConfiguration) AudioAttributes(android.media.AudioAttributes) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Aggregations

AudioAttributes (android.media.AudioAttributes)3 AudioPlaybackConfiguration (android.media.AudioPlaybackConfiguration)3 TargetApi (android.annotation.TargetApi)1 AudioManager (android.media.AudioManager)1 IPlayer (android.media.IPlayer)1 PlayerBase (android.media.PlayerBase)1 Test (org.junit.Test)1 Config (org.robolectric.annotation.Config)1