Example usage for android.media AudioManager STREAM_SYSTEM

List of usage examples for android.media AudioManager STREAM_SYSTEM

Introduction

In this page you can find the example usage for android.media AudioManager STREAM_SYSTEM.

Prototype

int STREAM_SYSTEM

To view the source code for android.media AudioManager STREAM_SYSTEM.

Click Source Link

Document

Used to identify the volume of audio streams for system sounds

Usage

From source file:org.noise_planet.noisecapture.CalibrationLinearityActivity.java

private int getAudioOutput() {
    SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    String value = sharedPref.getString("settings_calibration_audio_output", "STREAM_RING");

    if ("STREAM_VOICE_CALL".equals(value)) {
        return AudioManager.STREAM_VOICE_CALL;
    } else if ("STREAM_SYSTEM".equals(value)) {
        return AudioManager.STREAM_SYSTEM;
    } else if ("STREAM_RING".equals(value)) {
        return AudioManager.STREAM_RING;
    } else if ("STREAM_MUSIC".equals(value)) {
        return AudioManager.STREAM_MUSIC;
    } else if ("STREAM_ALARM".equals(value)) {
        return AudioManager.STREAM_ALARM;
    } else if ("STREAM_NOTIFICATION".equals(value)) {
        return AudioManager.STREAM_NOTIFICATION;
    } else if ("STREAM_DTMF".equals(value)) {
        return AudioManager.STREAM_DTMF;
    } else {//w w  w.j  av a 2 s . c  o m
        return AudioManager.STREAM_RING;
    }
}

From source file:com.evandroid.musica.MainLyricActivity.java

@SuppressLint("InlinedApi")
public void resync(MenuItem item) {
    AudioManager am = (AudioManager) getSystemService(Context.AUDIO_SERVICE);
    am.requestAudioFocus(null,//from  ww  w  . j  a v a  2 s .  c  o m
            // Use the music stream.
            AudioManager.STREAM_SYSTEM,
            // Request permanent focus.
            AudioManager.AUDIOFOCUS_GAIN_TRANSIENT);
    am.abandonAudioFocus(null);
}

From source file:com.PPRZonDroid.MainActivity.java

/**
 * Play warning sound if airspeed goes below the selected value
 *
 * @param context/*  w ww . j  a  v  a 2 s.  com*/
 * @throws IllegalArgumentException
 * @throws SecurityException
 * @throws IllegalStateException
 * @throws IOException
 */
public void play_sound(Context context)
        throws IllegalArgumentException, SecurityException, IllegalStateException, IOException {

    Uri soundUri = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    MediaPlayer mMediaPlayer = new MediaPlayer();
    mMediaPlayer.setDataSource(context, soundUri);
    final AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE);
    //Set volume max!!!
    audioManager.setStreamVolume(AudioManager.STREAM_SYSTEM,
            audioManager.getStreamMaxVolume(audioManager.STREAM_SYSTEM), 0);

    if (audioManager.getStreamVolume(AudioManager.STREAM_SYSTEM) != 0) {
        mMediaPlayer.setAudioStreamType(AudioManager.STREAM_SYSTEM);
        mMediaPlayer.setLooping(true);
        mMediaPlayer.prepare();
        mMediaPlayer.start();
    }
}

From source file:com.b44t.messenger.NotificationsController.java

private void playInChatSound() {
    if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) {
        return;/*from   w  w w.j a  va 2 s. c  om*/
    }
    try {
        if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            return;
        }
    } catch (Exception e) {
        FileLog.e("messenger", e);
    }

    try {
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
        int notifyOverride = getNotifyOverride(preferences, opened_dialog_id);
        if (notifyOverride == 2) {
            return;
        }
        notificationsQueue.postRunnable(new Runnable() {
            @Override
            public void run() {
                if (Math.abs(System.currentTimeMillis() - lastSoundPlay) <= 500) {
                    return;
                }
                lastSoundPlay = System.currentTimeMillis();
                try {
                    if (soundPool == null) {
                        soundPool = new SoundPool(3, AudioManager.STREAM_SYSTEM, 0);
                        soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
                            @Override
                            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                                if (status == 0) {
                                    soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
                                }
                            }
                        });
                    }
                    if (soundIn == 0 && !soundInLoaded) {
                        soundInLoaded = true;
                        soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1);
                    }
                    if (soundIn != 0) {
                        soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f);
                    }
                } catch (Exception e) {
                    FileLog.e("messenger", e);
                }
            }
        });
    } catch (Exception e) {
        FileLog.e("messenger", e);
    }
}

From source file:org.hermes.android.NotificationsController.java

private void playInChatSound() {
    if (!inChatSoundEnabled) {
        return;//  ww  w . java 2s .  c  o  m
    }
    try {
        if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            return;
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    try {
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
        int notify_override = preferences.getInt("notify2_" + openned_dialog_id, 0);
        if (notify_override == 3) {
            int mute_until = preferences.getInt("notifyuntil_" + openned_dialog_id, 0);
            if (mute_until >= ConnectionsManager.getInstance().getCurrentTime()) {
                notify_override = 2;
            }
        }
        if (notify_override == 2) {
            return;
        }
        notificationsQueue.postRunnable(new Runnable() {
            @Override
            public void run() {
                if (lastSoundPlay > System.currentTimeMillis() - 500) {
                    return;
                }
                try {
                    if (mediaPlayerIn == null) {
                        AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext
                                .getResources().openRawResourceFd(R.raw.sound_in);
                        if (assetFileDescriptor != null) {
                            mediaPlayerIn = new MediaPlayer();
                            mediaPlayerIn.setAudioStreamType(AudioManager.STREAM_SYSTEM);
                            mediaPlayerIn.setDataSource(assetFileDescriptor.getFileDescriptor(),
                                    assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
                            mediaPlayerIn.setLooping(false);
                            assetFileDescriptor.close();
                            mediaPlayerIn.prepare();
                        }
                    }
                    mediaPlayerIn.start();
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        });
        /*String choosenSoundPath = null;
        String defaultPath = Settings.System.DEFAULT_NOTIFICATION_URI.getPath();
                
        choosenSoundPath = preferences.getString("sound_path_" + openned_dialog_id, null);
        boolean isChat = (int)(openned_dialog_id) < 0;
        if (isChat) {
        if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
            choosenSoundPath = null;
        } else if (choosenSoundPath == null) {
            choosenSoundPath = preferences.getString("GroupSoundPath", defaultPath);
        }
        } else {
        if (choosenSoundPath != null && choosenSoundPath.equals(defaultPath)) {
            choosenSoundPath = null;
        } else if (choosenSoundPath == null) {
            choosenSoundPath = preferences.getString("GlobalSoundPath", defaultPath);
        }
        }
                
        if (choosenSoundPath != null && !choosenSoundPath.equals("NoSound")) {
        if (lastMediaPlayerUri == null || !choosenSoundPath.equals(lastMediaPlayerUri)) {
            lastMediaPlayerUri = choosenSoundPath;
            mediaPlayer.reset();
            mediaPlayer.setAudioStreamType(AudioManager.STREAM_NOTIFICATION);
            if (choosenSoundPath.equals(defaultPath)) {
                mediaPlayer.setDataSource(ApplicationLoader.applicationContext, Settings.System.DEFAULT_NOTIFICATION_URI);
            } else {
                mediaPlayer.setDataSource(ApplicationLoader.applicationContext, Uri.parse(choosenSoundPath));
            }
            mediaPlayer.prepare();
        }
        mediaPlayer.start();
        }*/
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:org.vshgap.android.NotificationsController.java

private void playInChatSound() {
    if (!inChatSoundEnabled) {
        return;/*from w ww.  j  a  v  a2  s .c  o m*/
    }
    try {
        if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            return;
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    try {
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
        int notifyOverride = getNotifyOverride(preferences, openned_dialog_id);
        if (notifyOverride == 2) {
            return;
        }
        notificationsQueue.postRunnable(new Runnable() {
            @Override
            public void run() {
                if (lastSoundPlay > System.currentTimeMillis() - 500) {
                    return;
                }
                try {
                    if (soundPool == null) {
                        soundPool = new SoundPool(4, AudioManager.STREAM_SYSTEM, 0);
                    }
                    if (soundIn == 0) {
                        soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1);
                    }
                    soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f);
                    /*if (mediaPlayerIn == null) {
                    AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext.getResources().openRawResourceFd(R.raw.sound_in);
                    if (assetFileDescriptor != null) {
                        mediaPlayerIn = new MediaPlayer();
                        mediaPlayerIn.setAudioStreamType(AudioManager.STREAM_SYSTEM);
                        mediaPlayerIn.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
                        mediaPlayerIn.setLooping(false);
                        assetFileDescriptor.close();
                        mediaPlayerIn.prepare();
                    }
                    }
                    try {
                    mediaPlayerIn.pause();
                    mediaPlayerIn.seekTo(0);
                    } catch (Exception e) {
                    FileLog.e("tmessages", e);
                    }
                    mediaPlayerIn.start();*/
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        });
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:org.hermes.android.NotificationsController.java

public void playOutChatSound() {
    if (!inChatSoundEnabled) {
        return;//from w  ww.j  av  a  2s.c  om
    }
    try {
        if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            return;
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    notificationsQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            try {
                if (mediaPlayerOut == null) {
                    AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext
                            .getResources().openRawResourceFd(R.raw.sound_out);
                    if (assetFileDescriptor != null) {
                        mediaPlayerOut = new MediaPlayer();
                        mediaPlayerOut.setAudioStreamType(AudioManager.STREAM_SYSTEM);
                        mediaPlayerOut.setDataSource(assetFileDescriptor.getFileDescriptor(),
                                assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
                        mediaPlayerOut.setLooping(false);
                        assetFileDescriptor.close();
                        mediaPlayerOut.prepare();
                    }
                }
                mediaPlayerOut.start();
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        }
    });
}

From source file:org.vshgap.android.NotificationsController.java

public void playOutChatSound() {
    if (!inChatSoundEnabled) {
        return;//  ww  w.j  av  a2s . c om
    }
    try {
        if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            return;
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
    notificationsQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            try {
                if (soundPool == null) {
                    soundPool = new SoundPool(4, AudioManager.STREAM_SYSTEM, 0);
                }
                if (soundOut == 0) {
                    soundOut = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1);
                }
                soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
                /*if (mediaPlayerOut == null) {
                AssetFileDescriptor assetFileDescriptor = ApplicationLoader.applicationContext.getResources().openRawResourceFd(R.raw.sound_out);
                if (assetFileDescriptor != null) {
                    mediaPlayerOut = new MediaPlayer();
                    mediaPlayerOut.setAudioStreamType(AudioManager.STREAM_SYSTEM);
                    mediaPlayerOut.setDataSource(assetFileDescriptor.getFileDescriptor(), assetFileDescriptor.getStartOffset(), assetFileDescriptor.getLength());
                    mediaPlayerOut.setLooping(false);
                    assetFileDescriptor.close();
                    mediaPlayerOut.prepare();
                }
                }
                try {
                mediaPlayerOut.pause();
                mediaPlayerOut.seekTo(0);
                } catch (Exception e) {
                FileLog.e("tmessages", e);
                }
                mediaPlayerOut.start();*/
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        }
    });
}

From source file:org.telegram.messenger.NotificationsController.java

private void playInChatSound() {
    if (!inChatSoundEnabled) {
        return;//from  w  w w. j av  a 2  s  . c om
    }
    try {
        if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            return;
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    try {
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
        int notifyOverride = getNotifyOverride(preferences, openned_dialog_id);
        if (notifyOverride == 2) {
            return;
        }
        notificationsQueue.postRunnable(new Runnable() {
            @Override
            public void run() {
                if (lastSoundPlay > System.currentTimeMillis() - 500) {
                    return;
                }
                try {
                    if (soundPool == null) {
                        soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 0);
                        soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
                            @Override
                            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                                if (status == 0) {
                                    soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
                                }
                            }
                        });
                    }
                    if (soundIn == 0 && !soundInLoaded) {
                        soundInLoaded = true;
                        soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1);
                    }
                    if (soundIn != 0) {
                        soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f);
                    }
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        });
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:com.goftagram.telegram.messenger.NotificationsController.java

private void playInChatSound() {
    if (!inChatSoundEnabled) {
        return;// w w w  .  j a  va  2s.c o m
    }
    try {
        if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            return;
        }
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }

    try {
        SharedPreferences preferences = ApplicationLoader.applicationContext
                .getSharedPreferences("Notifications", Context.MODE_PRIVATE);
        int notifyOverride = getNotifyOverride(preferences, openned_dialog_id);
        if (notifyOverride == 2) {
            return;
        }
        notificationsQueue.postRunnable(new Runnable() {
            @Override
            public void run() {
                if (Math.abs(System.currentTimeMillis() - lastSoundPlay) <= 500) {
                    return;
                }
                try {
                    if (soundPool == null) {
                        soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 0);
                        soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
                            @Override
                            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                                if (status == 0) {
                                    soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f);
                                }
                            }
                        });
                    }
                    if (soundIn == 0 && !soundInLoaded) {
                        soundInLoaded = true;
                        soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1);
                    }
                    if (soundIn != 0) {
                        soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f);
                    }
                } catch (Exception e) {
                    FileLog.e("tmessages", e);
                }
            }
        });
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}