Java Code Examples for android.media.SoundPool#play()
The following examples show how to use
android.media.SoundPool#play() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CodeGenerateActivity.java From Ticket-Analysis with MIT License | 6 votes |
private void shake() { SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 5); int weiChatAudio = soundPool.load(CodeGenerateActivity.this, R.raw.weichat_audio, 1); Vibrator vibrator = (Vibrator) getSystemService(VIBRATOR_SERVICE); //发出提示音 soundPool.play(weiChatAudio, 1, 1, 0, 0, 1); vibrator.vibrate(300); generateGroup(); isShaking = true; try { Thread.sleep(100); isShaking = false; } catch (InterruptedException e) { e.printStackTrace(); } }
Example 2
Source File: TwoDScrollerListview.java From 2DScroller with Apache License 2.0 | 6 votes |
/** * To play sound. * * @param context * {@link Context} * * @param soundID * sound id. * * @param soundPool * {@link SoundPool} instance. * */ public void playSound(Context context, int soundID, SoundPool soundPool){ OnAudioFocusChangeListener afChangeListener = new OnAudioFocusChangeListener() { public void onAudioFocusChange(int focusChange) { if (focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK){ // Lower the volume } else if (focusChange == AudioManager.AUDIOFOCUS_GAIN) { // Raise it back to normal } } }; AudioManager audioManager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); // Request audio focus for playback int result = audioManager.requestAudioFocus(afChangeListener, // Use the music stream. AudioManager.STREAM_MUSIC, // Request permanent focus. AudioManager.AUDIOFOCUS_GAIN); if (result == AudioManager.AUDIOFOCUS_REQUEST_GRANTED) { // Start playback. soundPool.play(soundID, 10, 10, 1, 0,1f ); } }
Example 3
Source File: AndroidAudioRenderer.java From MikuMikuStudio with BSD 2-Clause "Simplified" License | 6 votes |
@Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { AudioNode src = mapLoadingAudioNodes.get(sampleId); if (src.getAudioData() instanceof AndroidAudioData) { AndroidAudioData audioData = (AndroidAudioData) src.getAudioData(); if (status == 0) // load was successfull { int channelIndex; channelIndex = soundPool.play(audioData.getId(), 1f, 1f, 1, -1, 1f); src.setChannel(channelIndex); // Playing started ? if (src.getChannel() > 0) { src.setStatus(Status.Playing); } } else { src.setChannel(-1); } } else { throw new IllegalArgumentException("AudioData is not of type AndroidAudioData for AudioNode " + src.toString()); } }
Example 4
Source File: BgdService2.java From Huochexing12306 with Apache License 2.0 | 5 votes |
private void doAlarm() { if (mCurrMInfo.isVibrate()){ mVibrator.vibrate(1000); } if (mCurrMInfo.isRing()){ SoundPool soundPool = new SoundPool(2, AudioManager.STREAM_SYSTEM, 5); soundPool.load(this, R.raw.ticket_alarm, 1); soundPool.play(1, 1, 1, 0, 0, 1); } }
Example 5
Source File: TriggerHelper.java From science-journal with Apache License 2.0 | 5 votes |
public void doAudioAlert(Context context) { // Use a throttler to keep this from interrupting itself too much. if (SystemClock.elapsedRealtime() - lastAudioMs < THROTTLE_LIMIT_MS) { return; } SoundPool soundPool = getSoundPool(context); if (soundId != -1) { lastAudioMs = SystemClock.elapsedRealtime(); soundPool.play(soundId, .8f, .8f, 0, 0, 1.0f); } }
Example 6
Source File: RequestHandler.java From spydroid-ipcamera with GNU General Public License v3.0 | 4 votes |
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { soundPool.play(sampleId, 0.99f, 0.99f, 1, 0, 1); }