Refine search
SoundPool sp = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); /** soundId for Later handling of sound pool **/ int soundId = sp.load(context, R.raw.windows_8_notify, 1); // in 2nd param u have to pass your desire ringtone sp.play(soundId, 1, 1, 0, 0, 1); MediaPlayer mPlayer = MediaPlayer.create(context, R.raw.windows_8_notify); // in 2nd param u have to pass your desire ringtone //mPlayer.prepare(); mPlayer.start();
@Test @Config(maxSdk = JELLY_BEAN_MR2) public void shouldCreateSoundPool_JellyBean() { SoundPool soundPool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); assertThat(soundPool).isNotNull(); }
/** Kills the soundpool and all other resources */ public void dispose () { if (soundPool == null) { return; } synchronized (musics) { // gah i hate myself.... music.dispose() removes the music from the list... ArrayList<AndroidMusic> musicsCopy = new ArrayList<AndroidMusic>(musics); for (AndroidMusic music : musicsCopy) { music.dispose(); } } soundPool.release(); } }
@Test public void notifyPathLoaded_notifiesListener() { SoundPool soundPool = createSoundPool(); SoundPool.OnLoadCompleteListener listener = mock(SoundPool.OnLoadCompleteListener.class); soundPool.setOnLoadCompleteListener(listener); int soundId = soundPool.load("/mnt/sdcard/sound.wav", 1); shadowOf(soundPool).notifyPathLoaded("/mnt/sdcard/sound.wav", true); verify(listener).onLoadComplete(soundPool, soundId, 0); }
SoundPool soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 100); Integer sound1 = soundPool.load(this, R.raw.file1, 1); Integer sound2 = soundPool.load(this, R.raw.file2, 1); playSound(sound1); public void playSound(int sound) { AudioManager mgr = (AudioManager)getSystemService(Context.AUDIO_SERVICE); float volume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC) / mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC); soundPool.play(sound, volume, volume, 1, -1, 1.0f); }
mSoundPoolMap.put(Index, mSoundPool.load(mContext, SoundID, 1)); int streamVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC); int soundId = mSoundPool.play(mSoundPoolMap.get(index), streamVolume, streamVolume, 1, 0, 1f); public void run() { if(!mKillSoundQueue.isEmpty()){ mSoundPool.stop(mKillSoundQueue.firstElement());
private void playSound(int soundId) { if(mSoundPool != null) { int streamVolume = mgr.getStreamVolume(AudioManager.STREAM_MUSIC); mSoundPool.play(soundIds[soundId],streamVolume,streamVolume,1,0,1f); } }
public int playMusic(boolean loop) { AudioManager mgr = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); float streamVolumeCurrent = mgr.getStreamVolume(AudioManager.STREAM_MUSIC); float streamVolumeMax = mgr.getStreamMaxVolume(AudioManager.STREAM_MUSIC); float volume = streamVolumeCurrent / streamVolumeMax; int streamId; if (loop) { streamId = mSoundPool.play(mVoiceResource, volume, volume, 1, -1, 1f); } else { streamId = mSoundPool.play(mVoiceResource, volume, volume, 1, 0, 1f); } return streamId; }
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); SoundPool soundPool = new SoundPool(4, AudioManager.STREAM_MUSIC, 0); int soundId = soundPool.load(theContext, R.raw.audio, 1); int streamVolume = audioManager.getStreamVolume(AudioManager.STREAM_MUSIC); int streamId = soundPool.play(soundId, streamVolume, streamVolume, 1, 0, 1f);
AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); int maxVolume = audioManager.getStreamMaxVolume(AudioManager.STREAM_NOTIFICATION); SoundPool soundPool = new SoundPool(10, AudioManager.STREAM_NOTIFICATION, 0); int sound = soundPool.load(context, R.raw.beep, 1); soundPool.play(sound, maxVolume, maxVolume, 1, 0, 1f);
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); }
@Override public long play (float volume, float pitch, float pan) { if (streamIds.size == 8) streamIds.pop(); float leftVolume = volume; float rightVolume = volume; if (pan < 0) { rightVolume *= (1 - Math.abs(pan)); } else if (pan > 0) { leftVolume *= (1 - Math.abs(pan)); } int streamId = soundPool.play(soundId, leftVolume, rightVolume, 1, 0, pitch); // standardise error code with other backends if (streamId == 0) return -1; streamIds.insert(0, streamId); return streamId; }
SoundPool soundPool = new SoundPool(2, // number of streams AudioManager.STREAM_MUSIC, // stream type 0); // source quality, does nothing soundPool.setOnLoadCompleteListener(loadCompleteListener); int soundOneId = soundPool.load(context, R.raw.sound1, 1); int soundTwoId = soundPool.load(context, R.raw.sound2, 1); // Once loadCompleteListener.onLoadComplete has been called for both sounds soundPool.play(soundOneId); soundPool.play(soundTwoId);
public void playSoundEffect() { mCurrVolume = mAudioManager.getStreamVolume(AudioManager.STREAM_SYSTEM); if (mSoundId > 0) { mSoundPool.play(mSoundId, mCurrVolume, mCurrVolume, 0, 0, 1); } else { mAudioManager.playSoundEffect(AudioManager.FX_KEY_CLICK, mCurrVolume); } }
public void tocarSom(int index) { if (index >= mListaIdsSons.size()) return; float volume = mAudioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC); int prioridade = 1; int repeticoes = 0; float rate = 1.0f; int playId = mSoundPool.play( mListaIdsSons.get(index), volume, volume, prioridade, repeticoes, rate); mSonsEmExecucao.push(playId); } public void pararTodosOsSons() {
private void play(int soundId) { if (isPlaying()) { return; } if (mAudioManager.getRingerMode() != AudioManager.RINGER_MODE_SILENT) { mSoundPool.stop(soundId); mSoundPool.play(soundId, 1f, 1f, 0, 0, 1f); } }
/** {@inheritDoc} */ @Override public Sound newSound (FileHandle file) { if (soundPool == null) { throw new GdxRuntimeException("Android audio is not enabled by the application config."); } AndroidFileHandle aHandle = (AndroidFileHandle)file; if (aHandle.type() == FileType.Internal) { try { AssetFileDescriptor descriptor = aHandle.getAssetFileDescriptor(); AndroidSound sound = new AndroidSound(soundPool, manager, soundPool.load(descriptor, 1)); descriptor.close(); return sound; } catch (IOException ex) { throw new GdxRuntimeException("Error loading audio file: " + file + "\nNote: Internal audio files must be placed in the assets directory.", ex); } } else { try { return new AndroidSound(soundPool, manager, soundPool.load(aHandle.file().getPath(), 1)); } catch (Exception ex) { throw new GdxRuntimeException("Error loading audio file: " + file, ex); } } }
public final void playSound() { if (mAudioManager.getRingerMode() == AudioManager.RINGER_MODE_NORMAL && mVolume > 0.001) { if (mSoundScheme != SOUND_ANDROID) { mSoundPool.play(mSoundPoolMap.get(mSoundScheme), mVolume, mVolume, 1, 0, 1f); } else { mAudioManager.playSoundEffect( AudioManager.FX_KEYPRESS_STANDARD, mVolume); } } }
public void reset() { pool.release(); pool = new SoundPool( MAX_STREAMS, AudioManager.STREAM_MUSIC, 0 ); pool.setOnLoadCompleteListener( this ); ids.clear(); }