android.media.SoundPool.OnLoadCompleteListener Java Examples
The following examples show how to use
android.media.SoundPool.OnLoadCompleteListener.
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: FeedbackController.java From brailleback with Apache License 2.0 | 6 votes |
/** * Constructs and initializes a new feedback controller. */ public FeedbackController(Context context) { mContext = context; mResources = context.getResources(); mVibrator = (Vibrator) mContext.getSystemService(Context.VIBRATOR_SERVICE); mSoundPool = new SoundPool(NUMBER_OF_CHANNELS, DEFAULT_STREAM, 1); mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if (status == 0) { synchronized (mPostLoadPlayables) { if (mPostLoadPlayables.contains(sampleId)) { soundPool.play( sampleId, DEFAULT_VOLUME, DEFAULT_VOLUME, 1, 0, DEFAULT_RATE); mPostLoadPlayables.remove(Integer.valueOf(sampleId)); } } } } }); mHandler = new Handler(); mResourceIdToSoundMap.clear(); mResourceIdToVibrationPatternMap.clear(); MidiUtils.purgeMidiTempFiles(context); }
Example #2
Source File: PlaySound.java From bither-android with Apache License 2.0 | 6 votes |
public static void play(final int soundId, final PlaySoundCompletionListener playSoundCompletionListener) { if (sounds.get(soundId) != null) { int soundID1 = sounds.get(soundId); beginPlay(soundID1, playSoundCompletionListener); } else { synchronized (sounds) { final int soundIDOfPool = soundPool.load( BitherApplication.mContext, soundId, 1); soundPool .setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool arg0, int arg1, int arg2) { if (arg1 == soundIDOfPool) { beginPlay(soundIDOfPool, playSoundCompletionListener); } } }); LogUtil.d("record", "load:" + soundId); sounds.put(soundId, soundIDOfPool); } } }
Example #3
Source File: CameraActivity.java From vocefiscal-android with Apache License 2.0 | 6 votes |
private void setupSound() { spool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); spool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if(status==0) { if(sampleId==soundID) canPlaySound = true; } } }); soundID = spool.load(getApplicationContext(), R.raw.one_click, 1); }
Example #4
Source File: FeedbackController.java From talkback with Apache License 2.0 | 5 votes |
/** * Plays the auditory feedback associated with the given resource ID using the specified rate, * volume, and panning. * * @param resId The auditory feedback's resource identifier. * @param rate The playback rate adjustment, from 0.5 (half speed) to 2.0 (double speed). * @param volume The volume adjustment, from 0.0 (mute) to 1.0 (original volume). */ public void playAuditory(int resId, final float rate, float volume, @Nullable EventId eventId) { if (!mAuditoryEnabled || resId == 0) { return; } LogUtils.v(TAG, "playAuditory() resId=%d eventId=%s", resId, eventId); final float adjustedVolume = volume * mVolumeAdjustment; int soundId = mSoundIds.get(resId); if (soundId != 0) { new EarconsPlayTask(mSoundPool, soundId, adjustedVolume, rate).execute(); } else { // The sound could not be played from the cache. Start loading the sound into the // SoundPool for future use, and use a listener to play the sound ASAP. mSoundPool.setOnLoadCompleteListener( new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if (sampleId != 0) { new EarconsPlayTask(mSoundPool, sampleId, adjustedVolume, rate).execute(); } } }); mSoundIds.put(resId, mSoundPool.load(mContext, resId, 1)); } }
Example #5
Source File: BubbleActivity.java From android_coursera_1 with MIT License | 5 votes |
@Override protected void onResume() { super.onResume(); // Manage bubble popping sound // Use AudioManager.STREAM_MUSIC as stream type mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); mStreamVolume = (float) mAudioManager .getStreamVolume(AudioManager.STREAM_MUSIC) / mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); // TODO - make a new SoundPool, allowing up to 10 streams mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0); // TODO - set a SoundPool OnLoadCompletedListener that calls setupGestureDetector() mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if (0 == status) { setupGestureDetector(); } } }); // TODO - load the sound from res/raw/bubble_pop.wav mSoundID = mSoundPool.load(this, R.raw.bubble_pop, 1); }
Example #6
Source File: MainActivity.java From crazyflie-android-client with GNU General Public License v2.0 | 5 votes |
private void initializeSounds() { this.setVolumeControlStream(AudioManager.STREAM_MUSIC); // Load sounds mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 0); mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { mLoaded = true; } }); mSoundConnect = mSoundPool.load(this, R.raw.proxima, 1); mSoundDisconnect = mSoundPool.load(this, R.raw.tejat, 1); }
Example #7
Source File: AudioVideoAudioManagerActivity.java From coursera-android with MIT License | 4 votes |
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); // Get reference to the AudioManager mAudioManager = (AudioManager) getSystemService(AUDIO_SERVICE); // Display current volume level in TextView mTextView= findViewById(R.id.textView1); mTextView.setText(String.valueOf(mVolume)); final Button playButton = findViewById(R.id.button3); // Disable the Play Button so user can't click it before sounds are ready playButton.setEnabled(false); // Create a SoundPool AudioAttributes audioAttributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_MEDIA) .build(); mSoundPool = new SoundPool.Builder() .setAudioAttributes(audioAttributes) .build(); // Load bubble popping sound into the SoundPool mSoundId = mSoundPool.load(this, R.raw.slow_whoop_bubble_pop, 1); // Set an OnLoadCompleteListener on the SoundPool mSoundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { // If sound loading was successful enable the play Button if (0 == status) { playButton.setEnabled(true); } else { Log.i(TAG, "Unable to load sound"); finish(); } } }); // Request audio focus int result = mAudioManager.requestAudioFocus(afChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); // Set to true if app has audio focus mCanPlayAudio = AudioManager.AUDIOFOCUS_REQUEST_GRANTED == result; }