use of android.media.AudioAttributes 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);
}
use of android.media.AudioAttributes in project SpotiQ by ZinoKader.
the class NotificationUtil method createNotificationChannels.
/**
* Create notification channels required for displayal of notifications on >=API O
*/
@RequiresApi(api = Build.VERSION_CODES.O)
public static void createNotificationChannels(Context context) {
NotificationManager mNotificationManager = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE);
String channelId = ApplicationConstants.MEDIA_NOTIFICATION_CHANNEL_ID;
CharSequence userVisibleChannelName = context.getString(R.string.media_notification_channel_name);
String userVisibleDescription = context.getString(R.string.media_notification_channel_description);
int notificationImportance = NotificationManager.IMPORTANCE_DEFAULT;
AudioAttributes audioAttributes = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build();
NotificationChannel mediaNotificationChannel = new NotificationChannel(channelId, userVisibleChannelName, notificationImportance);
mediaNotificationChannel.setDescription(userVisibleDescription);
mediaNotificationChannel.enableVibration(false);
mediaNotificationChannel.enableLights(false);
mediaNotificationChannel.setSound(Uri.EMPTY, audioAttributes);
mNotificationManager.createNotificationChannel(mediaNotificationChannel);
}
use of android.media.AudioAttributes in project react-native-twilio-programmable-voice by hoxfon.
the class TwilioVoiceModule method setAudioFocus.
private void setAudioFocus() {
if (audioManager == null) {
return;
}
originalAudioMode = audioManager.getMode();
// Request audio focus before making any device switch
if (Build.VERSION.SDK_INT >= 26) {
AudioAttributes playbackAttributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_VOICE_COMMUNICATION).setContentType(AudioAttributes.CONTENT_TYPE_SPEECH).build();
focusRequest = new AudioFocusRequest.Builder(AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE).setAudioAttributes(playbackAttributes).setAcceptsDelayedFocusGain(true).setOnAudioFocusChangeListener(new AudioManager.OnAudioFocusChangeListener() {
@Override
public void onAudioFocusChange(int i) {
}
}).build();
audioManager.requestAudioFocus(focusRequest);
} else {
audioManager.requestAudioFocus(null, AudioManager.STREAM_VOICE_CALL, AudioManager.AUDIOFOCUS_GAIN_TRANSIENT_EXCLUSIVE);
}
/*
* Start by setting MODE_IN_COMMUNICATION as default audio mode. It is
* required to be in this mode when playout and/or recording starts for
* best possible VoIP performance. Some devices have difficulties with speaker mode
* if this is not set.
*/
audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION);
}
use of android.media.AudioAttributes in project EasyPlayer-RTMP-Android by EasyDSS.
the class PlayActivity method initSoundPool.
protected void initSoundPool() {
if (true)
return;
AudioManager mAudioManager = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
mAudioVolumn = (float) mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC);
mMaxVolume = (float) mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC);
setVolumeControlStream(AudioManager.STREAM_MUSIC);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AudioAttributes attributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_NOTIFICATION).setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();
mSoundPool = new SoundPool.Builder().setMaxStreams(10).setAudioAttributes(attributes).build();
} else {
mSoundPool = new SoundPool(10, AudioManager.STREAM_NOTIFICATION, 0);
}
mTalkPictureSound = mSoundPool.load("/system/media/audio/ui/camera_click.ogg", 1);
mActionStartSound = mSoundPool.load(this, R.raw.action_start, 1);
mActionStopSound = mSoundPool.load(this, R.raw.action_stop, 1);
}
use of android.media.AudioAttributes in project phonegap-plugin-push by phonegap.
the class PushPlugin method createChannel.
@TargetApi(26)
private void createChannel(JSONObject channel) throws JSONException {
// only call on Android O and above
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
final NotificationManager notificationManager = (NotificationManager) cordova.getActivity().getSystemService(Context.NOTIFICATION_SERVICE);
String packageName = getApplicationContext().getPackageName();
NotificationChannel mChannel = new NotificationChannel(channel.getString(CHANNEL_ID), channel.optString(CHANNEL_DESCRIPTION, ""), channel.optInt(CHANNEL_IMPORTANCE, NotificationManager.IMPORTANCE_DEFAULT));
int lightColor = channel.optInt(CHANNEL_LIGHT_COLOR, -1);
if (lightColor != -1) {
mChannel.setLightColor(lightColor);
}
int visibility = channel.optInt(VISIBILITY, NotificationCompat.VISIBILITY_PUBLIC);
mChannel.setLockscreenVisibility(visibility);
boolean badge = channel.optBoolean(BADGE, true);
mChannel.setShowBadge(badge);
String sound = channel.optString(SOUND, "default");
AudioAttributes audioAttributes = new AudioAttributes.Builder().setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).setUsage(AudioAttributes.USAGE_NOTIFICATION_RINGTONE).build();
if (SOUND_RINGTONE.equals(sound)) {
mChannel.setSound(android.provider.Settings.System.DEFAULT_RINGTONE_URI, audioAttributes);
} else if (sound != null && sound.isEmpty()) {
// Disable sound for this notification channel if an empty string is passed.
// https://stackoverflow.com/a/47144981/6194193
mChannel.setSound(null, null);
} else if (sound != null && !sound.contentEquals(SOUND_DEFAULT)) {
Uri soundUri = Uri.parse(ContentResolver.SCHEME_ANDROID_RESOURCE + "://" + packageName + "/raw/" + sound);
mChannel.setSound(soundUri, audioAttributes);
} else {
mChannel.setSound(android.provider.Settings.System.DEFAULT_NOTIFICATION_URI, audioAttributes);
}
// If vibration settings is an array set vibration pattern, else set enable
// vibration.
JSONArray pattern = channel.optJSONArray(CHANNEL_VIBRATION);
if (pattern != null) {
int patternLength = pattern.length();
long[] patternArray = new long[patternLength];
for (int i = 0; i < patternLength; i++) {
patternArray[i] = pattern.optLong(i);
}
mChannel.setVibrationPattern(patternArray);
} else {
boolean vibrate = channel.optBoolean(CHANNEL_VIBRATION, true);
mChannel.enableVibration(vibrate);
}
notificationManager.createNotificationChannel(mChannel);
}
}
Aggregations