获取存储在res / raw文件夹中的3个mp3文件的URI

时间:2015-01-22 15:00:25

标签: android

如何获取存储在res / raw文件夹中的3个mp3文件的URI,我用过:Uri.parse(" android.resource://" + getPackageName()+" / " + R.raw.splash)但不行,你有什么建议吗?

public void getSongList(){
    //query external audio
    ContentResolver musicResolver = getContentResolver();

    //Uri musicUri = android.provider.MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;

    Uri musicUri = Uri.parse("android.resource://com.example.musicplayer/raw/"+R.raw.collide);

    Cursor musicCursor = musicResolver.query(musicUri, null, null, null, null);
    //iterate over results if valid
    if(musicCursor!=null && musicCursor.moveToFirst()){
        //get columns
        int titleColumn = musicCursor.getColumnIndex
                (android.provider.MediaStore.Audio.Media.TITLE);
        int idColumn = musicCursor.getColumnIndex
                (android.provider.MediaStore.Audio.Media._ID);
        int artistColumn = musicCursor.getColumnIndex
                (android.provider.MediaStore.Audio.Media.ARTIST);
        //add songs to list
        do {
            long thisId = musicCursor.getLong(idColumn);
            String thisTitle = musicCursor.getString(titleColumn);
            String thisArtist = musicCursor.getString(artistColumn);
            songList.add(new Song(thisId, thisTitle, thisArtist));
        } 
        while (musicCursor.moveToNext());
    }

}

1 个答案:

答案 0 :(得分:0)

这就是为这些资源获取Uri的方法。但是,这些内容没有ContentProvider,因此您的query()永远不会有效。您需要找到一些可以将InputStream作为输入的MP3元数据库,并为您提供所需的元数据。

另请注意,系统的许多部分都不尊重android.resource Uri计划,因为它们并不是特别受欢迎。