@Test @Config(minSdk = LOLLIPOP) public void shouldCreateSoundPool_Lollipop() { SoundPool soundPool = new SoundPool.Builder().build(); assertThat(soundPool).isNotNull(); SoundPool.OnLoadCompleteListener listener = mock(SoundPool.OnLoadCompleteListener.class); soundPool.setOnLoadCompleteListener(listener); }
@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); }
@Test public void notifyPathLoaded_notifiesFailure() { 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", false); verify(listener).onLoadComplete(soundPool, soundId, 1); }
@Test public void notifyResourceLoaded_notifiesListener() { SoundPool soundPool = createSoundPool(); SoundPool.OnLoadCompleteListener listener = mock(SoundPool.OnLoadCompleteListener.class); soundPool.setOnLoadCompleteListener(listener); int soundId = soundPool.load(ApplicationProvider.getApplicationContext(), R.raw.sound, 1); shadowOf(soundPool).notifyResourceLoaded(R.raw.sound, true); verify(listener).onLoadComplete(soundPool, soundId, 0); }
public SoundManager(Context ctx) { mAppContext = ctx.getApplicationContext(); mSantaPreferences = new SantaPreferences(mAppContext); mSoundPool = new SoundPool(MAX_STREAMS, STREAM_TYPE, SRC_QUALITY); mSoundPool.setOnLoadCompleteListener(this); }
soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { public void onLoadComplete(SoundPool soundPool, int sampleId,int status) { //play the sound. } });
private SoundPool voices; @Override public void onCreate(Bundle savedInstanceState) { voices = new SoundPool(1, 3, 0); voices.setOnLoadCompleteListener(this); }
private Context mContext; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gameplay); mContext=this; public static void loadAudioToSoundPool(Context mContext, int id) { soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { loaded = true; } }); soundID = soundPool.load(mContext, SoundList.soundListfire.get(id), 1); }
public void reset() { ids.clear(); loadingQueue = new LinkedList<>(); pool.release(); pool = new SoundPool( MAX_STREAMS, AudioManager.STREAM_MUSIC, 0 ); pool.setOnLoadCompleteListener( this ); }
public void reset() { pool.release(); pool = new SoundPool( MAX_STREAMS, AudioManager.STREAM_MUSIC, 0 ); pool.setOnLoadCompleteListener( this ); ids.clear(); }
SoundPool pool = new SoundPool(1, AudioManager.STREAM_MUSIC, 0); afd = getResources().openRawResourceFd(audioResource); pool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { if (0 == status) { soundPool.play(sampleId, 1f, 1f, 10, -1 /* looping parameter */, 1f); } } }); pool.load(afd, 10); afd.close();
private AudioClip(int maxStreams, int streamType, int srcQuality, Context context) { this.context = context; soundPool = new SoundPool(maxStreams, streamType, srcQuality); soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { loaded = true; } }); loadinSounds(); }
private AudioClip(int maxStreams, int streamType, int srcQuality, Context context) { this.context = context; soundPool = new SoundPool(maxStreams, streamType, srcQuality); soundPool.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { loaded = true; } }); loadinSounds(); }
private void playSound() { // TODO Auto-generated method stub SoundPool pl = new SoundPool(5, AudioManager.STREAM_MUSIC, 0); // 5 indicates the maximum number of simultaneous streams for this SoundPool object int waterSound = pl.load(this, R.raw.water_sound_01, 0); // is the audio file I have imported in my project as resource pl.setOnLoadCompleteListener(new OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { // The onLoadComplet method is called when a sound has completed loading. // TODO Auto-generated method stub soundPool.play(sampleId, 1f, 1f, 0, 0, 1); // second and third parameters indicates left and right value (range = 0.0 to 1.0) } }); }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mSoundPool = new SoundPool(1, AudioManager.STREAM_ALARM, 0); mSoundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int sampleId, int status) { alert(" " + sampleId); } }); soundPoolMap = new HashMap<Integer, Integer>(); soundPoolMap.put(KEY_SOUND_A1, mSoundPool.load(this, R.raw.a1, 1)); soundPoolMap.put(KEY_SOUND_A2, mSoundPool.load(this, R.raw.a2, 1)); }
public AndroidAudio(final AndroidPlatform plat) { this.plat = plat; this.pool = new SoundPool(plat.activity.maxSimultaneousSounds(), AudioManager.STREAM_MUSIC, 0); this.pool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { public void onLoadComplete(SoundPool soundPool, int soundId, int status) { PooledSound sound = loadingSounds.remove(soundId); if (sound == null) { plat.log().warn("Got load complete for unknown sound [id=" + soundId + "]"); } else if (status == 0) { sound.succeed(soundId); } else { sound.fail(new Exception("Sound load failed [errcode=" + status + "]")); } } }); }
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);
private SoundManager(Context context){ this.context = context; if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP){ setUpSoundPoolLollipop(); }else{ setUpSoundPool(); } soundPool.setOnLoadCompleteListener(this); sounds = new HashMap<>(); sounds.put(APPEAR, soundPool.load(context, R.raw.appear, 1)); sounds.put(LEAVE, soundPool.load(context, R.raw.leave, 1)); sounds.put(SELECT, soundPool.load(context, R.raw.select, 1)); sounds.put(CANCEL, soundPool.load(context, R.raw.cancel, 1)); sounds.put(UP, soundPool.load(context, R.raw.up, 1)); sounds.put(DOWN, soundPool.load(context, R.raw.appear, 1)); }
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); }
public void intMediaPlayer(int raw, final boolean isOutiong1) { if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) { soundPool = new SoundPool.Builder().build(); } else { soundPool = new SoundPool(10, AudioManager.STREAM_SYSTEM, 5); } streamID = soundPool.load(this, raw, 1); soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() { @Override public void onLoadComplete(SoundPool soundPool, int i, int i1) { soundPool.play(1, 1, 1, 0, -1, 1); if (isOutiong1) { releaseHandler.postDelayed(runnable, TIME); } } }); }