限制:
1MB以下
.wav / .mp3 (ogg沒試)
SoundPool sp = SoundPool( 10, AudioManager.STREAM_MUSIC, 0); //(最大音效數 , 聲音類型 , 來源品質-0為預設)
放於res/raw讀入
soundId_ = soundPool_.load(this, R.raw.sound, 1);
放於asserts讀入
descriptor = this.getResources().getAssets().openFd("sound.wav"); seLogo = sp.load(descriptor, 1 );
播放
soundId_ = soundPool_.load(this, R.raw.sound, 1);
ample 1 not READY 錯誤時
方法1 - 需android2.2以上
sp.setOnLoadCompleteListener(new OnLoadCompleteListener(){ @Override public void onLoadComplete(SoundPool arg0, int arg1, int arg2) { sp.play(seLogo, 1, 1, 0, 0, 1.0f); }});
方法2
int sid=0; for (int i = 0; i < 1000; i++){ if (sid == 0) { try { sid = sp.play(seLogo, 1, 1, 0, 0, 1.0f); Thread.sleep(1); } catch (InterruptedException e) { e.printStackTrace(); } } else { break; } }
沒有留言:
張貼留言