打从原文件夹中的MP3文件在我的Andr​​oid应用程序我的、应用程序、原文件、文件

2023-09-04 06:53:03 作者:1Msber。装傻-

您好,我有code哗哗获取列表的MP3文件从SD卡在我的手机, 我怎么可以将其更改为从原文件夹获取MP3

 公开的ArrayList<轨道> getTracksOnMDS(){
    开放的我们的uri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
    的String []投影=新的String [] {MediaStore.Audio.Media._ID,
            MediaStore.Audio.Media.TITLE,MediaStore.Audio.Media.ARTIST,
            MediaStore.Audio.Media.ALBUM_ID,MediaStore.Audio.Media.DATA};
    光标光标= ContentResolver的
            .query(URI,投影,NULL,NULL,NULL);
    返回convertMediaStoreCursorToArrayList(光标);
}
 

我代替一些code要做到这一点,但它不能正常工作

 文件圈=新的文件(android.resource://com.bk.lrandom/res/raw/_10.mp3);
开放的我们的uri = MediaStore.Audio.Media.getContentUriForPath(ring.getAbsolutePath());
 

解决方案

使用下面的code片段从原始文件夹播放音频文件

  MediaPlayer的MPlayer的;
MPLAYER = MediaPlayer.create(这一点,R.raw.bg_music);
mPlayer.start();
 

hi i have the code whish get list mp3 file from sdcard in my phone , how i can change it to get mp3 from raw folder

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);
}    

i replace some code to do this but it is not work

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

解决方案

Use the following code snippet to play audio file from raw folder

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