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:com.panahit.telegramma.NotificationsController.java

private void playInChatSound() {
    if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) {
        return;//from   w  w  w .  ja va2  s  . co  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(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("tmessages", e);
                }
            }
        });
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

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

public void playOutChatSound() {
    if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) {
        return;//w w  w .  j av  a2 s  .c om
    }
    try {
        if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) {
            return;
        }
    } catch (Exception e) {
        FileLog.e("messenger", e);
    }
    notificationsQueue.postRunnable(new Runnable() {
        @Override
        public void run() {
            try {
                if (Math.abs(System.currentTimeMillis() - lastSoundOutPlay) <= 100) {
                    return;
                }
                lastSoundOutPlay = System.currentTimeMillis();
                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 (soundOut == 0 && !soundOutLoaded) {
                    soundOutLoaded = true;
                    soundOut = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1);
                }
                if (soundOut != 0) {
                    soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
                }
            } catch (Exception e) {
                FileLog.e("messenger", e);
            }
        }
    });
}

From source file:com.almalence.opencam.ApplicationScreen.java

public void muteShutter(boolean mute) {
    AudioManager mgr = (AudioManager) ApplicationScreen.instance
            .getSystemService(ApplicationScreen.AUDIO_SERVICE);
    mgr.setStreamMute(AudioManager.STREAM_SYSTEM, mute);
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

protected void muteAllSounds() {
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_ALARM, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_DTMF, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_MUSIC, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_NOTIFICATION, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_RING, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_SYSTEM, true);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_VOICE_CALL, true);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_RING, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_VOICE_CALL, 0, 0);

    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_ALARM, AudioManager.ADJUST_MUTE, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_DTMF, AudioManager.ADJUST_MUTE, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_MUSIC, AudioManager.ADJUST_MUTE, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_RING, AudioManager.ADJUST_MUTE, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_SYSTEM, AudioManager.ADJUST_MUTE, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).adjustStreamVolume(AudioManager.STREAM_VOICE_CALL, AudioManager.ADJUST_MUTE, 0);
}

From source file:com.almalence.plugins.capture.video.VideoCapturePlugin.java

protected void unmuteAllSounds() {
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_ALARM, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_DTMF, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_MUSIC, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_NOTIFICATION, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_RING, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_SYSTEM, false);
    ((AudioManager) ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE))
            .setStreamMute(AudioManager.STREAM_VOICE_CALL, false);

    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_ALARM, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_DTMF, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_MUSIC, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_RING, 0, 0);
    //      ((AudioManager)ApplicationScreen.instance.getSystemService(Context.AUDIO_SERVICE)).setStreamVolume(AudioManager.STREAM_SYSTEM, 0, 0);
}

From source file:ir.besteveryeverapp.telegram.NotificationsController.java

private void playInChatSound() {
    if (!inChatSoundEnabled || NightModeUtil.blockSound() || MediaController.getInstance().isRecordingAudio()) {
        return;//from  w  w w .  j a v  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, opened_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(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("tmessages", e);
                }
            }
        });
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

From source file:ir.irani.telecam.messenger.NotificationsController.java

private void playInChatSound() {
    if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) {
        return;/*from w w  w. 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, opened_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(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("tmessages", e);
                }
            }
        });
    } catch (Exception e) {
        FileLog.e("tmessages", e);
    }
}

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

public void playOutChatSound() {
    if (!inChatSoundEnabled) {
        return;//from www.  ja v 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 (lastSoundOutPlay > System.currentTimeMillis() - 100) {
                    return;
                }
                lastSoundOutPlay = System.currentTimeMillis();
                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 (soundOut == 0 && !soundOutLoaded) {
                    soundOutLoaded = true;
                    soundOut = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1);
                }
                if (soundOut != 0) {
                    soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
                }
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        }
    });
}

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

public void playOutChatSound() {
    if (!inChatSoundEnabled) {
        return;/*from  w  w  w .  j  a  v  a2  s  .  c  o  m*/
    }
    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 (Math.abs(System.currentTimeMillis() - lastSoundOutPlay) <= 100) {
                    return;
                }
                lastSoundOutPlay = System.currentTimeMillis();
                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 (soundOut == 0 && !soundOutLoaded) {
                    soundOutLoaded = true;
                    soundOut = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1);
                }
                if (soundOut != 0) {
                    soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
                }
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        }
    });
}

From source file:com.panahit.telegramma.NotificationsController.java

public void playOutChatSound() {
    if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) {
        return;//  w  w  w  .  ja va  2 s . 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 (Math.abs(System.currentTimeMillis() - lastSoundOutPlay) <= 100) {
                    return;
                }
                lastSoundOutPlay = System.currentTimeMillis();
                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 (soundOut == 0 && !soundOutLoaded) {
                    soundOutLoaded = true;
                    soundOut = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1);
                }
                if (soundOut != 0) {
                    soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f);
                }
            } catch (Exception e) {
                FileLog.e("tmessages", e);
            }
        }
    });
}