float j = 1.0f;
SoundPool sp = null;
int sID = 0;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Button b = (Button)findViewById(R.id.Button01);
b.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
j = (float) (j +.5f);
sp.setRate(sID,j);
}
});
AssetFileDescriptor afd;
try {
sp = new SoundPool(1, AudioManager.STREAM_MUSIC, 0);
afd = getAssets().openFd("wav/sample.wav");
int id = sp.load(afd, 1);
sID = sp.play(id, 1, 1, 1, 0, j);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
SoundPool 大小文件在1m的样子,同时setrate的频率 在0.5- 2注意约束