2017年7月31日月曜日
Android SoundPool soundPool
public class MainActivity extends AppCompatActivity {
protected SoundPool soundPool;
protected int id;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
test();
AssetManager am = getAssets();
try {
id = soundPool.load(am.openFd("PCM-M10_441kHz16bit.wav"), 1);
} catch (IOException e) {
e.printStackTrace();
}
soundPool.setOnLoadCompleteListener(new SoundPool.OnLoadCompleteListener() {
@Override
public void onLoadComplete(SoundPool soundPool, int sampleId, int status) {
Toast.makeText(MainActivity.this, "9999999999999", Toast.LENGTH_SHORT).show();
soundPool.play(id, 1, 1, 1, 1, 1);
}
});
}
protected void test() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.LOLLIPOP) {
SoundPool.Builder spb = new SoundPool.Builder();
AudioAttributes.Builder b = new AudioAttributes.Builder();
b.setUsage(AudioAttributes.USAGE_MEDIA);
b.setContentType(AudioAttributes.CONTENT_TYPE_MUSIC);
AudioAttributes a = b.build();
spb.setAudioAttributes(a);
spb.setMaxStreams(12);
soundPool = spb.build();
}
}
}
登録:
投稿 (Atom)