0

我使用以下方法将文件保存到音乐目录中:

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_MUSIC, "SpaceJam.mp3");

在我的主要活动中,我现在想访问它并播放它。

如何检索歌曲的信息以便可以将其用于:

mp.setDataSource(??);

“mp”是我的 MediaPlayer 的名称。谢谢。

4

3 回答 3

4
    File path = Environment.getExternalStoragePublicDirectory(
            Environment.DIRECTORY_MUSIC);
     File file = new File(path, "Hunny.mp3");
    try {
        mp.setDataSource(file.toString());
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
于 2013-09-21T09:35:43.333 回答
0

如果您有外部存储,则类似这样:

 File path = Environment.getExternalStoragePublicDirectory(
        Environment.DIRECTORY_MUSIC);
 File file = new File(path, "SpaceJam.mp3");

....
于 2013-09-21T09:31:52.377 回答
0
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_MUSIC);
File file = new File(path, "SpaceJam.mp3");
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(file.getAbsolutePath());
mp.prepare();
mp.start();

编辑:

mp.setDataSource(file.getAbsolutePath());
于 2013-09-21T10:03:17.680 回答