Example usage for android.media SoundPool setOnLoadCompleteListener

List of usage examples for android.media SoundPool setOnLoadCompleteListener

Introduction

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

Prototype

public void setOnLoadCompleteListener(OnLoadCompleteListener listener) 

Source Link

Document

Sets the callback hook for the OnLoadCompleteListener.

Usage

From source file:com.intel.xdk.notification.Notification.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();/*from w w w . jav a2  s.c o m*/

    //init sounds
    soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100);

    //this is needed so that the sound plays the first time
    soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            if (beepCount != -1 && soundPool == Notification.this.soundPool && sampleId == SOUND_BEEP
                    && status == 0) {
                beep(beepCount);
            }
        }
    });

    //SOUND_BEEP = soundPool.load(activity, R.raw.beep, 1);
    SOUND_BEEP = soundPool.load(activity,
            activity.getResources().getIdentifier("xdkbeep", "raw", activity.getPackageName()), 1);
}

From source file:org.peaklabs.consumer.Escanea.java

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    // Initialize and start the bar code recognition.
    initializeAndStartBarcodeScanning();

    ActionBar actionBar = getSupportActionBar();
    actionBar.setDisplayHomeAsUpEnabled(true);
    actionBar.setDisplayShowTitleEnabled(true);
    actionBar.setTitle(getResources().getString(R.string.scan));
    soundpool = new SoundPool(5, AudioManager.STREAM_NOTIFICATION, 0);
    soundpool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            loaded = true;//from  ww  w .  ja v a 2s  .co m
        }
    });
    idBeep = soundpool.load(this, R.raw.beep, 1);
}

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 {//from   w  w  w.j av a  2  s  .c om
        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.ayaseya.padnotification.GcmIntentService.java

@Override
protected void onHandleIntent(final Intent intent) {

    extras = intent.getExtras();//from w  w 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);
}

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

@Override
protected void onHandleIntent(final Intent intent) {

    extras = intent.getExtras();/*from w  w  w .ja va  2s .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.intel.xdk.player.Player.java

@Override
public void initialize(CordovaInterface cordova, CordovaWebView webView) {
    super.initialize(cordova, webView);

    //get convenience reference to activity
    activity = cordova.getActivity();/*w  ww.j  a va  2 s.c  om*/

    //get the current url
    final CordovaWebView wv = webView;
    activity.runOnUiThread(new Runnable() {
        public void run() {
            currentUrl = wv.getUrl();
        }
    });

    //turn on remote debugging
    // activity.runOnUiThread(new Runnable() {
    //     public void run() {
    //         if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
    //          try {
    //              Method m = WebView.class.getMethod("setWebContentsDebuggingEnabled", boolean.class);
    //              m.invoke(WebView.class, true);
    //          } catch (Exception e) {
    //              // TODO Auto-generated catch block
    //              e.printStackTrace();
    //          }
    //         }
    //     }
    // });

    soundPool = new SoundPool(30, AudioManager.STREAM_MUSIC, 100);
    soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
        public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
            soundLoaded(sampleId, status);
        }
    });
    hasLoadSoundCallback = true;
}

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

public void onCreate(Bundle savedInstanceState) {
    if (debugUsbComm) {
        logString = TAG + ": onCreate";
        Log.d(TAG, logString);/*ww  w  .ja va2  s .  com*/
        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.b44t.messenger.NotificationsController.java

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