Android examples for Media:Sound
build Sound Pool
//package com.java2s; import android.annotation.TargetApi; import android.media.AudioAttributes; import android.media.AudioManager; import android.media.SoundPool; import android.os.Build; public class Main { @SuppressWarnings("deprecation") @TargetApi(Build.VERSION_CODES.LOLLIPOP) public static SoundPool buildSoundPool(int poolMax) { SoundPool pool;/*from w w w . ja v a 2 s.com*/ if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { pool = new SoundPool(poolMax, AudioManager.STREAM_MUSIC, 0); } else { AudioAttributes attr = new AudioAttributes.Builder() .setUsage(AudioAttributes.USAGE_MEDIA) .setContentType(AudioAttributes.CONTENT_TYPE_MUSIC) .build(); pool = new SoundPool.Builder().setAudioAttributes(attr) .setMaxStreams(poolMax).build(); } return pool; } }