Example usage for android.media SoundPool release

List of usage examples for android.media SoundPool release

Introduction

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

Prototype

public final void release() 

Source Link

Document

Release the SoundPool resources.

Usage

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

@Override
protected void onHandleIntent(final Intent intent) {

    extras = intent.getExtras();/*www .j av  a2  s.c  om*/

    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();//from ww w.  j  ava 2  s. c  om

    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);
}