我有使用 soundpool 播放声音的按钮。我想打开我的应用程序,然后从 SD 卡手动加载 .mp3 文件并用我的按钮播放。我的Java代码:
package com.example.idea;
import android.media.SoundPool;
import android.os.Bundle;
import android.app.Activity;
import android.view.Menu;
import android.view.View;
public class MainActivity extends Activity {
SoundPool sp;
int mSoundId;
int mStreamId;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mSoundId = sp.load(this, R.raw.sound1, 1);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_main, menu);
return true;
}
public void button1(View view){
if (mStreamId != 0) {
sp.stop(mStreamId);
}
`mStreamId = sp.play(mSoundId, 1, 1, 1, 0, 1f);`
}
}