我正在使用mp3播放器播放mp3文件,这样我就可以从特定文件夹中获取所有mp3,但问题是当我点击列表视图播放歌曲时它不播放它会崩溃应用程序 主要活动
String path = Environment.getExternalStorageDirectory().getAbsolutePath()+"/Music";
Log.d("Files", "Path: " + path);
File f = new File(path);
File file[] = f.listFiles();
Log.d("Files", "Size: "+ file.length);
for (int i=0; i < file.length; i++)
{
//here populate your listview
Log.d("Files", "FileName:" + file[i].getName());
songlist.add(file[i].getPath());
lv.setAdapter(arrayadapter);
}
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Intent intent = new Intent(MainActivity.this, Main2Activity.class);
intent.putExtra("song", songlist.get(i));
startActivity(intent);
Intent Activity播放歌曲
songitem =getIntent().getExtras().getInt("song");
mediaPlayer = MediaPlayer.create(this,songitem);
mediaPlayer.start();