首先,我可以获得所有歌曲及其细节。我正在尝试的是从URL获取歌曲详细信息,因为我可以从文件导航中获取唯一的URL这是我正在尝试的
public ArrayList<Songfileinfo> getPlayList(Context context, String uri) {
{
String sortOrder = null;
try {
String[] proj = {MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.ALBUM_ID
};
String selection = null;
String[] selectionArgs = {uri};
Cursor audioCursor = context.getContentResolver().query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, proj, selection, selectionArgs, sortOrder);
if (audioCursor != null) {
if (audioCursor.moveToFirst()) {
do {
int audioTitle = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
int audioartist = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST);
int audioduration = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION);
int audiodata = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
int audioalbum = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM);
int audioalbumid = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM_ID);
int song_id = audioCursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID);
Songfileinfo info = new Songfileinfo();
info.setFile_uri(audioCursor.getString(audiodata));
info.setTitle(audioCursor.getString(audioTitle));
info.setDuration((audioCursor.getString(audioduration)));
info.setArtist(audioCursor.getString(audioartist));
info.setAlbum(audioCursor.getString(audioalbum));
info.setId(audioCursor.getLong(song_id));
info.setAlbum_art((ContentUris.withAppendedId(albumArtUri, audioCursor.getLong(audioalbumid))).toString());
songList.add(info);
} while (audioCursor.moveToNext());
}
}
assert audioCursor != null;
audioCursor.close();
} catch (Exception e) {
e.printStackTrace();
}
}
return songList;
}
这是我试图使用它的方法不起作用我得到的数组列表大小为0我还尝试比较所有位置列表中的字符串文件位置,但仍然是数组大小为0。我不想使用媒体元数据检索,因为我不会获得专辑封面网址。有关如何获取此特定位置的详细信息的任何提示? 我也尝试过这种方式但通过比较文件URI字符串
得到相同的结果if (audioCursor.getString(audiodata).equals(uri)){
} 我试图使用媒体元数据检索器类,但它不会给图像网址,它将在位图中,因为我的整个应用程序使用图像网址对我来说很难。
答案 0 :(得分:0)
我只是给它来从网址
获取所有数据 if (new File(audioCursor.getString(audiodata)).getName().equals(url.getName())) {
Songfileinfo info = new Songfileinfo();
info.setFile_uri(audioCursor.getString(audiodata));
info.setTitle(audioCursor.getString(audioTitle));
info.setDuration((audioCursor.getString(audioduration)));
info.setArtist(audioCursor.getString(audioartist));
info.setAlbum(audioCursor.getString(audioalbum));
info.setId(audioCursor.getLong(song_id));
info.setAlbum_art((ContentUris.withAppendedId(albumArtUri, audioCursor.getLong(audioalbumid))).toString());
songList.add(info);
}