@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); }
SoundPool sound; protected void createSoundPool() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { createNewSoundPool(); } else { createOldSoundPool(); } } @TargetApi(Build.VERSION_CODES.LOLLIPOP) protected void createNewSoundPool(){ AudioAttributes attributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_GAME) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); sounds = new SoundPool.Builder() .setAudioAttributes(attributes) .build(); } @SuppressWarnings("deprecation") protected void createOldSoundPool(){ sounds = new SoundPool(5,AudioManager.STREAM_MUSIC,0); }
public AndroidAudio (Context context, AndroidApplicationConfiguration config) { if (!config.disableAudio) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes audioAttrib = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_GAME) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); soundPool = new SoundPool.Builder().setAudioAttributes(audioAttrib).setMaxStreams(config.maxSimultaneousSounds).build(); }else { soundPool = new SoundPool(config.maxSimultaneousSounds, AudioManager.STREAM_MUSIC, 0);// srcQuality: the sample-rate converter quality. Currently has no effect. Use 0 for the default. } manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); if (context instanceof Activity) { ((Activity)context).setVolumeControlStream(AudioManager.STREAM_MUSIC); } } else { soundPool = null; manager = null; } }
@SuppressLint("NewApi") public SoundManager(BaseApp baseApp) { root = baseApp; ismastersoundon = true; try { SoundPool.Builder spb = new SoundPool.Builder() .setMaxStreams(8) .setAudioAttributes(new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_GAME) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build() ); soundpool = spb.build(); } catch (NoClassDefFoundError e) { soundpool = new SoundPool(8, AudioManager.STREAM_MUSIC, 0); } }
SoundPool mSoundPool; int mSoundId; //... if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mSoundPool = new SoundPool.Builder() .setMaxStreams(10) .build(); } else { mSoundPool = new SoundPool(10, AudioManager.STREAM_MUSIC, 1); } mSoundId = mSoundPool.load(this, R.raw.somesound, 1); // ... mSoundPool.play(mSoundId, 1, 1, 1, 0, 1);
@TargetApi(Build.VERSION_CODES.LOLLIPOP) private void setUpSoundPoolLollipop(){ soundPool = new SoundPool.Builder() .setAudioAttributes(new AudioAttributes.Builder().setContentType(AudioAttributes.USAGE_ASSISTANCE_SONIFICATION).build()) .setMaxStreams(MAX_STREAMS) .build(); }
AudioAttributes attrs = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_GAME) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); SoundPool sp = new SoundPool.Builder() .setMaxStreams(10) .setAudioAttributes(attrs) .build();
@TargetApi(Build.VERSION_CODES.LOLLIPOP) protected void createNewSoundPool() { AudioAttributes attributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_GAME) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); sp = new SoundPool.Builder() .setAudioAttributes(attributes) .build(); }
AudioAttributes attributes = new AudioAttributes.Builder() .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED) .setUsage(AudioAttributes.USAGE_GAME) .build(); pool = new SoundPool.Builder().setAudioAttributes(attributes).setMaxStreams(2).build()
@Override public void onCreate() { super.onCreate(); AudioAttributes attributes = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_NOTIFICATION) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); soundpool_ = new SoundPool.Builder().setAudioAttributes(attributes).build(); bikebell_ = soundpool_.load(this.getBaseContext(), R.raw.bikebell,1); locationManager_ = (LocationManager) getSystemService(Context.LOCATION_SERVICE); }
@SuppressWarnings("deprecation") private SoundHelper() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mSoundPool = new SoundPool.Builder().build(); } else { mSoundPool = new SoundPool(1, AudioManager.STREAM_SYSTEM, 1); } }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes audioAttrib = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_GAME) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); mSound = new SoundPool.Builder().setAudioAttributes(audioAttrib).setMaxStreams(6).build(); } else { mSound = new SoundPool(6, AudioManager.STREAM_MUSIC, 0); }
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes attributes = new AudioAttributes.Builder().setUsage(AudioAttributes.USAGE_MEDIA) .setFlags(AudioAttributes.FLAG_AUDIBILITY_ENFORCED) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC).build(); mSoundPool = new SoundPool.Builder().setAudioAttributes(attributes).setMaxStreams(6).build(); } else { mSoundPool = new SoundPool(6, AudioManager.STREAM_MUSIC, 0); }
private MQSoundPoolManager(Context context) { this.mContext = context; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { mSoundPool = new SoundPool.Builder().setMaxStreams(STREAMS_COUNT).build(); } else { mSoundPool = new SoundPool(STREAMS_COUNT, AudioManager.STREAM_MUSIC, 0); } mAudioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); mSoundSourceMap = new HashMap<>(); }
Log.d("Sound", "Set AudioAttributes for SoundPool."); // Set the audioAttributes for the SoundPool and specify maximum number of streams. soundPool = new SoundPool.Builder() .setAudioAttributes(attributes) .setMaxStreams(7) .build();
AudioAttributes attr = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_MEDIA) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .build(); pool = new SoundPool.Builder().setAudioAttributes(attr).setMaxStreams(6).build();
SoundPool sounds = new SoundPool.Builder() .setAudioAttributes(attributes) .build();
AudioAttributes attrs = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_GAME) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); SoundPool sp = new SoundPool.Builder() .setMaxStreams(10) .setAudioAttributes(attrs) .build();
public AndroidAudio (Context context, AndroidApplicationConfiguration config) { if (!config.disableAudio) { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { AudioAttributes audioAttrib = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_GAME) .setContentType(AudioAttributes.CONTENT_TYPE_SONIFICATION) .build(); soundPool = new SoundPool.Builder().setAudioAttributes(audioAttrib).setMaxStreams(config.maxSimultaneousSounds).build(); }else { soundPool = new SoundPool(config.maxSimultaneousSounds, AudioManager.STREAM_MUSIC, 0);// srcQuality: the sample-rate converter quality. Currently has no effect. Use 0 for the default. } manager = (AudioManager)context.getSystemService(Context.AUDIO_SERVICE); if (context instanceof Activity) { ((Activity)context).setVolumeControlStream(AudioManager.STREAM_MUSIC); } } else { soundPool = null; manager = null; } }
private SoundPool createSoundPool() { return RuntimeEnvironment.getApiLevel() >= LOLLIPOP ? new SoundPool.Builder().build() : new SoundPool(1, AudioManager.STREAM_MUSIC, 0); } }