概述
我回答了自己的问题,希望将来可以帮助其他人.
int REQUEST_MEDIA = 0;
SharedPreferences prefs;
String prefName = "MyPref";
String audioID, artist_name, artist_band;
Uri MyUri;
private OnClickListener startListener = new OnClickListener() {
public void onClick(View v) {
Intent i = new Intent(Intent.ACTION_PICK, MediaStore.Audio.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, REQUEST_MEDIA);//REQUEST_MEDIA is some const int to operate with in onActivityResult
}
};
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == REQUEST_MEDIA && resultCode == RESULT_OK) {
audioID = data.getDataString();
MyUri = Uri.parse(audioID);
String[] proj = { MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.DATA,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Artists.ARTIST };
Cursor tempCursor = managedQuery(MrUri,
proj, null, null, null);
tempCursor.moveToFirst(); //reset the cursor
int col_index=-1;
int numSongs=tempCursor.getCount();
int currentNum=0;
do{
col_index = tempCursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE);
artist_name = tempCursor.getString(col_index);
col_index = tempCursor.getColumnIndexOrThrow(MediaStore.Audio.Artists.ARTIST);
artist_band = tempCursor.getString(col_index);
//do something with artist name here
//we can also move into different columns to fetch the other values
currentNum++;
}while(tempCursor.moveToNext());
prefs = getSharedPreferences(prefName, MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();
editor.putString("alarm_selected", audioID);
editor.putString("alarm_name", artist_name);
editor.putString("alarm_band", artist_band);
editor.commit();
}
}
最后
以上就是善良缘分为你收集整理的android 获取mp3专辑id,Android如何从知道的URI中获取单首歌曲的ID信息的全部内容,希望文章能够帮你解决android 获取mp3专辑id,Android如何从知道的URI中获取单首歌曲的ID信息所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
发表评论 取消回复