0

我正在使用 mp3 Player 播放 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();
4

0 回答 0