Search in sources :

Example 41 with AudioAttributes

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);
}
Also used : AudioPlaybackConfiguration(android.media.AudioPlaybackConfiguration) AudioAttributes(android.media.AudioAttributes) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 42 with AudioAttributes

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);
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) AudioAttributes(android.media.AudioAttributes) RequiresApi(android.support.annotation.RequiresApi)

Example 43 with AudioAttributes

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);
}
Also used : AudioManager(android.media.AudioManager) AudioAttributes(android.media.AudioAttributes) AudioFocusRequest(android.media.AudioFocusRequest)

Example 44 with AudioAttributes

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);
}
Also used : AudioManager(android.media.AudioManager) AudioAttributes(android.media.AudioAttributes) SoundPool(android.media.SoundPool)

Example 45 with AudioAttributes

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);
    }
}
Also used : NotificationChannel(android.app.NotificationChannel) NotificationManager(android.app.NotificationManager) JSONArray(org.json.JSONArray) AudioAttributes(android.media.AudioAttributes) Uri(android.net.Uri) TargetApi(android.annotation.TargetApi)

Aggregations

AudioAttributes (android.media.AudioAttributes)46 NotificationChannel (android.app.NotificationChannel)13 Notification (android.app.Notification)11 RemoteException (android.os.RemoteException)10 TargetApi (android.annotation.TargetApi)9 Uri (android.net.Uri)9 NotificationManager (android.app.NotificationManager)6 Test (org.junit.Test)6 Config (org.robolectric.annotation.Config)6 ITransientNotification (android.app.ITransientNotification)5 IRingtonePlayer (android.media.IRingtonePlayer)5 SoundPool (android.media.SoundPool)5 StatusBarNotification (android.service.notification.StatusBarNotification)5 VisibleForTesting (com.android.internal.annotations.VisibleForTesting)5 NotificationChannelGroup (android.app.NotificationChannelGroup)4 PendingIntent (android.app.PendingIntent)3 AudioManager (android.media.AudioManager)3 AudioPlaybackConfiguration (android.media.AudioPlaybackConfiguration)3 RequiresApi (android.support.annotation.RequiresApi)3 Intent (android.content.Intent)2