Example usage for android.media SoundPool play

List of usage examples for android.media SoundPool play

Introduction

In this page you can find the example usage for android.media SoundPool play.

Prototype

public final int play(int soundID, float leftVolume, float rightVolume, int priority, int loop, float rate) 

Source Link

Document

Play a sound from a sound ID.

Usage

From source file:capstone.se491_phm.Alarm.java

@SuppressWarnings("deprecation")
public static void siren(Context context) {
    if (null == pool) {
        pool = new SoundPool(5, AudioManager.STREAM_ALARM, 0);
    }/*ww  w.  j a v a 2s  . co m*/
    if (-1 == id) {
        id = pool.load(context.getApplicationContext(), R.raw.alarm, 1);
        loudest(context, AudioManager.STREAM_ALARM);
        pool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
            @Override
            public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                soundPool.play(id, 1.0f, 1.0f, 1, 3, 1.0f);
            }
        });
        loudest(context, AudioManager.STREAM_ALARM);
        pool.play(id, 1.0f, 1.0f, 1, 3, 1.0f);
    } else {
        loudest(context, AudioManager.STREAM_ALARM);
        pool.play(id, 1.0f, 1.0f, 1, 3, 1.0f);
    }
}

From source file:com.albertcbraun.cms50fw.alert.ActivateAlertTask.java

@Override
public void run() {
    android.support.v4.app.FragmentActivity activity = mainUIFragment.getActivity();
    if (!mainUIFragment.uiAlertSet) {
        mainUIFragment.uiAlertSet = true;

        // animate the background
        View underlyingView = mainUIFragment.getActivity().getWindow().getDecorView()
                .findViewById(android.R.id.content);
        underlyingView.setBackgroundColor(
                mainUIFragment.getActivity().getResources().getColor(android.R.color.holo_red_dark));
        underlyingView.startAnimation(ALERT_DIALOG_FLASH_ANIMATION);

        // show problem dialog
        UIAlertDialog uiAlertDialog = new UIAlertDialog();
        Bundle arguments = new Bundle();
        arguments.putString(UIAlertDialog.ALERT_MESSAGE_KEY, alertMessage);
        uiAlertDialog.setArguments(arguments);

        // create dialog box and play a sound
        mainUIFragment.getFragmentManager().beginTransaction().add(uiAlertDialog, UIAlertDialog.TAG)
                .commitAllowingStateLoss();
        if (mainUIFragment.alertSoundEnabled) {
            final int soundId = mainUIFragment.soundPool.load(activity.getApplicationContext(), R.raw.beep, 1);
            mainUIFragment.soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
                @Override/*from w  ww .ja v  a  2  s .c  om*/
                public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
                    if (status == 0) { // sound loaded successfully
                        mainUIFragment.soundStreamId = soundPool.play(soundId, LEFT_VOLUME, RIGHT_VOLUME,
                                PRIORITY, LOOP_SETTING, RATE);
                    } else {
                        Log.e(TAG, ALERT_SOUND_COULD_NOT_BE_LOADED);
                    }
                }
            });
        }
    }
}

From source file:com.kentli.cycletrack.RecordingService.java

@Override
public void onCreate() {
    super.onCreate();
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        AudioAttributes attributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_GAME)
                .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION).build();

        soundpool = new SoundPool.Builder().setAudioAttributes(attributes).build();
    } else {/*  ww  w. j a v a 2  s.  c o m*/
        soundpool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0);
    }
    soundpool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        @Override
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            soundPool.play(sampleId, 1.0f, 1.0f, 0, 0, 1.0f);
        }
    });
    bikebell = soundpool.load(this.getBaseContext(), R.raw.bikebell, 1);
}

From source file:com.acceleratedio.pac_n_zoom.AnimActivity.java

private void mainAnmLoop() {

    AnimationSet anmSet = null;/*from w w  w.j  a va2 s .com*/

    if (onClickFlg == 1) {

        if (anmSet != null) {
            anmSet.cancel();
            anmSet.reset();
        }

        return;
    }

    // --- Loop through the frames
    int frm_nmbr = svg_data.frm.size();

    if (++frm_mbr >= frm_nmbr)
        frm_mbr = 0;

    // -- You need to turn the sprites on and off for the current frame
    LoadSVG.frame crt_frm = svg_data.frm.get(frm_mbr);
    String crt_frm_ordr = crt_frm.frm_ordr;
    ArrayList<String> sprt_ordr = svg_data.svg.ordr;
    int crt_dur = crt_frm.end - crt_frm.bgn;

    // - Loop through the sprites 
    int sprt_nmbr = sprt_ordr.size();
    int frm_sprt_mbr = 0;

    for (int sprt_mbr = 0; sprt_mbr < sprt_nmbr; sprt_mbr += 1) {

        String sprt_id = sprt_ordr.get(sprt_mbr);
        int sym_mbr = Integer.parseInt(sprt_id.substring(1, sprt_id.indexOf('_'))) - 2;

        if (sym_mbr >= 0) { // not g1 which is not loaded

            LoadSVG.symbol crt_sym = svg_data.symbl.get(sym_mbr);

            if (crt_frm_ordr.indexOf(sprt_id) >= 0) { // Sprite is present

                if (crt_sym.aud_id != null && !crt_sym.aud_id.equals("")) { // The sprite is audio

                    SoundPool mSoundPool = loadSVG.getMSoundPool();
                    int streamId = mSoundPool.play(svg_data.soundId[sym_mbr], 1.0f, 1.0f, 1, 0, 1.0f);
                    mSoundPool.setLoop(streamId, -1);
                } else { // The sprite is graphic
                    anim_view = anmViews.get(sprt_mbr);
                    anim_view.setAlpha(1f);
                    int xfm_idx = crt_frm.xfm_idx[frm_sprt_mbr];

                    if (xfm_idx >= 0) { // An animation tag is present

                        anmSet = new AnimationSet(false);
                        LoadSVG.xfrm crt_xfm = svg_data.xfm.get(xfm_idx);
                        ArrayList<Integer[]> pnts = crt_xfm.mov_path;
                        int init_scl = (int) (initScl[sprt_mbr] * 100);

                        if (pnts.size() > 0) {

                            final Path path = new Path();
                            ld_scl_pth_pnts(pnts, path);
                            PathAnimation pthAnm = new PathAnimation(path);
                            pthAnm.setDuration(crt_dur);
                            pthAnm.setInterpolator(new LinearInterpolator());
                            pthAnm.setFillAfter(true); // Needed to keep the result of the animation
                            anmSet.addAnimation(pthAnm);
                        }

                        if (crt_xfm.scl_bgn != init_scl) {

                            float crt_scl = crt_xfm.scl_bgn / init_scl;
                            float end_scl = crt_scl;

                            if (crt_xfm.scl_end != crt_xfm.scl_bgn)
                                end_scl = crt_xfm.scl_end / init_scl;

                            ScaleAnimation sclAnm = new ScaleAnimation(crt_scl, end_scl, crt_scl, end_scl,
                                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

                            sclAnm.setDuration(crt_dur);
                            anmSet.addAnimation(sclAnm);
                        }

                        if (crt_xfm.rot_bgn != 0) {

                            float crt_rot = crt_xfm.rot_bgn;
                            float end_rot = crt_rot;

                            if (crt_xfm.rot_end != crt_xfm.rot_bgn)
                                end_rot = crt_xfm.rot_end;

                            RotateAnimation rotAnm = new RotateAnimation(crt_rot, end_rot,
                                    Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);

                            rotAnm.setDuration(crt_dur);
                            anmSet.addAnimation(rotAnm);
                        }

                        anim_view.startAnimation(anmSet); //start animation
                    }
                }

                frm_sprt_mbr++;
            } else { // The sprite is not present
                if (!(crt_sym.aud_id != null && !crt_sym.aud_id.equals(""))) { // The sprite is graphic
                    anim_view = anmViews.get(sprt_mbr);
                    anim_view.setAlpha(0f);
                }
            }
        } else { // g1

            if (crt_frm_ordr.indexOf(sprt_id) >= 0)
                frm_sprt_mbr++;
        }
    }

    waitDur(crt_dur);
}

From source file:com.wheelphone.remotemini.WheelphoneRemoteMini.java

public void onCreate(Bundle savedInstanceState) {
    if (debugUsbComm) {
        logString = TAG + ": onCreate";
        Log.d(TAG, logString);/*w  ww  .j a v a2s  . co m*/
        appendLog("debugUsbComm.txt", logString, false);
    }

    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    camera = (SurfaceView) findViewById(R.id.smallcameraview);
    context = this.getApplicationContext();
    line1 = (TextView) findViewById(R.id.line1);
    line2 = (TextView) findViewById(R.id.line2);
    version = (TextView) findViewById(R.id.version);
    signWifi = (TextView) findViewById(R.id.advice);
    signStreaming = (TextView) findViewById(R.id.streaming);
    signInformation = (LinearLayout) findViewById(R.id.information);
    pulseAnimation = AnimationUtils.loadAnimation(this, R.anim.pulse);

    SharedPreferences settings = PreferenceManager.getDefaultSharedPreferences(this);

    settings.registerOnSharedPreferenceChangeListener(this);

    camera.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
    holder = camera.getHolder();

    PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
    wl = pm.newWakeLock(PowerManager.SCREEN_DIM_WAKE_LOCK, "com.wheelphone.remotemini.wakelock");

    httpServer = new CustomHttpServer(8080, this.getApplicationContext(), handler);

    soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() {
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            soundPool.play(sampleId, 0.99f, 0.99f, 1, 0, 1);
        }
    });

    timerImg = new Timer();

    intent = new Intent(context, FrontImageActivity.class);
    intent.setFlags(Intent.FLAG_ACTIVITY_REORDER_TO_FRONT);
    intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
    //startActivity(intent);        

    // Query the QCAR initialization flags:
    mQCARFlags = getInitializationFlags();

    // Update the application status to start initializing application
    updateApplicationStatus(APPSTATUS_INIT_APP);

    Display display = getWindowManager().getDefaultDisplay();
    Point size = new Point();
    display.getSize(size);
    updateRendering(size.x, size.y);

    btnStart = (Button) findViewById(R.id.btnStart);

    //Make sure that the app stays open:
    getWindow().addFlags(
            WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON | WindowManager.LayoutParams.FLAG_DISMISS_KEYGUARD
                    | WindowManager.LayoutParams.FLAG_SHOW_WHEN_LOCKED
                    | WindowManager.LayoutParams.FLAG_TURN_SCREEN_ON);

    wheelphone = new WheelphoneRobot(getApplicationContext(), getIntent());
    wheelphone.enableSpeedControl();
    wheelphone.setWheelPhoneRobotListener(this);

}

From source file:com.ayaseya.nolnotification.GcmIntentService.java

@Override
protected void onHandleIntent(final Intent intent) {

    extras = intent.getExtras();//  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();// w  ww  .j av a2s . c o  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.b44t.messenger.NotificationsController.java

public void playOutChatSound() {
    if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) {
        return;/*from   ww w.j a va  2 s.  c o m*/
    }
    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.b44t.messenger.NotificationsController.java

private void playInChatSound() {
    if (!inChatSoundEnabled || MediaController.getInstance().isRecordingAudio()) {
        return;//w  ww.  j a v  a  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.telegram.messenger.NotificationsController.java

public void playOutChatSound() {
    if (!inChatSoundEnabled) {
        return;//from   w  ww  . ja va 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 (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);
            }
        }
    });
}