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);
}
}
}
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;
}
}
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);
}
Aggregations