List of usage examples for android.media SoundPool load
public int load(Context context, int resId, int priority)
From source file:com.panahit.telegramma.NotificationsController.java
public void playOutChatSound() { if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) { return;/*w w w . j a v a2 s . co 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(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); } } }); }
From source file:com.panahit.telegramma.NotificationsController.java
private void playInChatSound() { if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) { return;/*from www .j a v a 2 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 (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.besteveryeverapp.telegram.NotificationsController.java
public void playOutChatSound() { if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio() || NightModeUtil.blockSound()) { return;/*from w w w . ja v a 2 s . co 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(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); } } }); }
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 a 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, 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.besteveryeverapp.telegram.NotificationsController.java
private void playInChatSound() { if (!inChatSoundEnabled || NightModeUtil.blockSound() || MediaController.getInstance().isRecordingAudio()) { return;//from www .j a v a 2 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:com.ferdi2005.secondgram.NotificationsController.java
public void playOutChatSound() { if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) { return;/*from w w w.j av a 2s . c om*/ } try { if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { return; } } catch (Exception e) { FileLog.e(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) { try { soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f); } catch (Exception e) { FileLog.e(e); } } } }); } if (soundOut == 0 && !soundOutLoaded) { soundOutLoaded = true; soundOut = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_out, 1); } if (soundOut != 0) { try { soundPool.play(soundOut, 1.0f, 1.0f, 1, 0, 1.0f); } catch (Exception e) { FileLog.e(e); } } } catch (Exception e) { FileLog.e(e); } } }); }
From source file:com.ferdi2005.secondgram.NotificationsController.java
private void playInChatSound() { if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) { return;/*w ww . ja v a 2 s . c o m*/ } try { if (audioManager.getRingerMode() == AudioManager.RINGER_MODE_SILENT) { return; } } catch (Exception e) { FileLog.e(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) { try { soundPool.play(sampleId, 1.0f, 1.0f, 1, 0, 1.0f); } catch (Exception e) { FileLog.e(e); } } } }); } if (soundIn == 0 && !soundInLoaded) { soundInLoaded = true; soundIn = soundPool.load(ApplicationLoader.applicationContext, R.raw.sound_in, 1); } if (soundIn != 0) { try { soundPool.play(soundIn, 1.0f, 1.0f, 1, 0, 1.0f); } catch (Exception e) { FileLog.e(e); } } } catch (Exception e) { FileLog.e(e); } } }); } catch (Exception e) { FileLog.e(e); } }
From source file:com.ayaseya.nolnotification.GcmIntentService.java
@Override protected void onHandleIntent(final Intent intent) { extras = intent.getExtras();//from w w w .j a v a2 s. co m GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); // displayMessage(this, extras.toString()); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { // sendNotification("Send error: " + extras.toString()); Log.v(TAG, "Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { // sendNotification("Deleted messages on server: " + extras.toString()); Log.v(TAG, "Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. // ?????IntentService???????? // ????????? new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { // Log.v(TAG, "doInBackground()"); // soundPool????? soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); // soundPool??Listener?????? soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(final SoundPool soundPool, int sampleId, int status) { if (status == 0) { if (notificationPermission) {// ???????? // Notification???? sendNotification("?????" + extras.get("INDEX") + "????", intent); //?????????? if (isPlugged) {// ??????? Log.v(TAG, "??????"); if (ringerMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (vibrateMode) {// Log.v(TAG, ""); if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (silentMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } } } else {// ????????? Log.v(TAG, "??????"); if (ringerMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (vibrateMode) {// Log.v(TAG, ""); if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (silentMode) {// Log.v(TAG, ""); } } } // ?soundPool???? new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(30000); } catch (InterruptedException e) { } // Log.v(TAG, "soundPool.release()"); soundPool.release(); } }).start(); } } }); // soundPool????? se = soundPool.load(GcmIntentService.this, R.raw.notification_sound, 1); return null; } }.execute(null, null, null); // sendNotification("??????" + extras.get("INDEX") + "???", intent); // sendNotification("Received: " + extras.toString()); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }
From source file:com.ayaseya.padnotification.GcmIntentService.java
@Override protected void onHandleIntent(final Intent intent) { extras = intent.getExtras();/*ww w.j av a 2 s . com*/ GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(this); // The getMessageType() intent parameter must be the intent you received // in your BroadcastReceiver. String messageType = gcm.getMessageType(intent); // displayMessage(this, extras.toString()); if (!extras.isEmpty()) { // has effect of unparcelling Bundle /* * Filter messages based on message type. Since it is likely that GCM will be * extended in the future with new message types, just ignore any message types you're * not interested in, or that you don't recognize. */ if (GoogleCloudMessaging.MESSAGE_TYPE_SEND_ERROR.equals(messageType)) { // sendNotification("Send error: " + extras.toString()); Log.v(TAG, "Send error: " + extras.toString()); } else if (GoogleCloudMessaging.MESSAGE_TYPE_DELETED.equals(messageType)) { // sendNotification("Deleted messages on server: " + extras.toString()); Log.v(TAG, "Deleted messages on server: " + extras.toString()); // If it's a regular GCM message, do some work. } else if (GoogleCloudMessaging.MESSAGE_TYPE_MESSAGE.equals(messageType)) { // This loop represents the service doing some work. for (int i = 0; i < 5; i++) { Log.i(TAG, "Working... " + (i + 1) + "/5 @ " + SystemClock.elapsedRealtime()); try { Thread.sleep(5000); } catch (InterruptedException e) { } } Log.i(TAG, "Completed work @ " + SystemClock.elapsedRealtime()); // Post notification of received message. // ?????IntentService???????? // ????????? new AsyncTask<Void, Void, Void>() { @Override protected Void doInBackground(Void... params) { // Log.v(TAG, "doInBackground()"); // soundPool????? soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); // soundPool??Listener?????? soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(final SoundPool soundPool, int sampleId, int status) { if (status == 0) { if (notificationPermission) {// ???????? // Notification???? sendNotification("??????" + extras.get("INDEX") + "??", intent); //?????????? if (isPlugged) {// ??????? Log.v(TAG, "??????"); if (ringerMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (vibrateMode) {// Log.v(TAG, ""); if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (silentMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } } } else {// ????????? Log.v(TAG, "??????"); if (ringerMode) {// Log.v(TAG, ""); if (checkbox_sound) { soundPool.play(se, 0.5F, 0.5F, 0, 0, 1.0F); } if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (vibrateMode) {// Log.v(TAG, ""); if (checkbox_vibration) { vibrator.vibrate(1500); } } else if (silentMode) {// Log.v(TAG, ""); } } } // ?soundPool???? new Thread(new Runnable() { @Override public void run() { try { Thread.sleep(30000); } catch (InterruptedException e) { } // Log.v(TAG, "soundPool.release()"); soundPool.release(); } }).start(); } } }); // soundPool????? se = soundPool.load(GcmIntentService.this, R.raw.notification_sound, 1); return null; } }.execute(null, null, null); // sendNotification("??????" + extras.get("INDEX") + "???", intent); // sendNotification("Received: " + extras.toString()); Log.i(TAG, "Received: " + extras.toString()); } } // Release the wake lock provided by the WakefulBroadcastReceiver. GcmBroadcastReceiver.completeWakefulIntent(intent); }