2015-01-02 248 views
-1

您好我有代碼嘩嘩得到的SD卡列表的MP3文件在我的手機, 我怎麼可以將其更改爲從原文件夾獲取MP3播放MP3文件

public ArrayList<Track> getTracksOnMDS() { 
    Uri uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; 
    String[] projection = new String[] { MediaStore.Audio.Media._ID, 
      MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.ARTIST, 
      MediaStore.Audio.Media.ALBUM_ID, MediaStore.Audio.Media.DATA }; 
    Cursor cursor = contentResolver 
      .query(uri, projection, null, null, null); 
    return convertMediaStoreCursorToArrayList(cursor); 
}  

我更換一些代碼來做到這一點,但實在不行

File ring = new File("android.resource://com.bk.lrandom/res/raw/_10.mp3"); 
Uri uri = MediaStore.Audio.Media.getContentUriForPath(ring.getAbsolutePath());  
+2

我沒有看到任何實際播放音頻文件的代碼。 –

+0

是的,沒有任何代碼播放MP3文件 –

+0

原始資源不是在運行時的文件,所以你不能爲它們獲取一個File對象。 –

回答

0

使用下面的代碼片段從原始文件夾播放音頻文件

MediaPlayer mPlayer; 
mPlayer= MediaPlayer.create(this, R.raw.bg_music); 
mPlayer.start(); 
+1

謝謝這是一個錯誤:)。其實那些許可是另一個答案的一部分: – BeingMIAkashs