我正在使用以下代碼從我的res/raw文件播放媒體文件,並且工作正常。但是,我的res/raw文件夾中有20個mp3文件我應該如何在res/raw文件夾中創建mp3文件的ArrayList?在Android的res/raw文件夾中創建mp3文件的ArrayList
MediaPlayer mediaPlayer = MediaPlayer.create(context, R.raw.music_file);
mediaPlayer.start();
下面是我的完整代碼;我是個無法播放第二音頻文件,
public class Datadetail extends AppCompatActivity {
private Context context;
TextView txtname;
TextView txtaarti;
String[] itemname;
int position;
ImageButton buttonPlay;
int[] songlist = {R.raw.ganesh_aarti, R.raw.durga_aarti};
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.setContentView(R.layout.data_detail);
Intent i = getIntent();
position = i.getExtras().getInt("position");
itemname = i.getStringArrayExtra("itemname");
txtname = (TextView) findViewById(R.id.textView2);
txtname.setText(itemname[position]);
txtaarti = (TextView) findViewById(R.id.textView3);
txtaarti.setText(Aarti.aartitxt[position]);
final MediaPlayer[] mPlayer = {MediaPlayer.create(this, songlist[0])};
buttonPlay = (ImageButton) findViewById(R.id.imageButton);
buttonPlay.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
if (position==0) {
mPlayer[0] = MediaPlayer.create(getApplicationContext(), R.raw.ganesh_aarti);
mPlayer[0].start();
}
if (position==1){
mPlayer[1] = MediaPlayer.create(getApplicationContext(), R.raw.durga_aarti);
mPlayer[1].start();
}
}
});
}
應該是什麼ArrayList中? – greenapps
mp3文件示例,R.raw.song1,R.raw.song2等。 –
那麼,您在創建Integer ArrayList並添加一些整數值時遇到了什麼問題? – greenapps