Android之Audio常用属性变量

歌曲ID:MediaStore.Audio.Media._ID
Int id = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID));
歌曲的名称 :MediaStore.Audio.Media.TITLE
String tilte = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE));
歌曲的专辑名:MediaStore.Audio.Media.ALBUM
String album = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM));
歌曲的歌手名: MediaStore.Audio.Media.ARTIST
String artist = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST));
歌曲文件的全路径 :MediaStore.Audio.Media.DATA
String url = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA));
歌曲文件的名称:MediaStroe.Audio.Media.DISPLAY_NAME
String display_name = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME));
歌曲文件的发行日期:MediaStore.Audio.Media.YEAR
String year = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.YEAR));
歌曲的总播放时长 :MediaStore.Audio.Media.DURATION
Int duration = cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION));
歌曲文件的大小 :MediaStore.Audio.Media.SIZE
Int size = cursor.getLong(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.SIZE));

发布了71 篇原创文章 · 获赞 72 · 访问量 11万+
展开阅读全文

为什么用Android的MediaStore查不到SD卡的音乐,权限里已经设置了

11-25

``` import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; import android.app.Activity; import android.content.ContentResolver; import android.database.Cursor; import android.os.Bundle; import android.provider.MediaStore; import android.widget.ListView; import android.widget.SimpleAdapter; public class MainActivity extends Activity { private ListView list; private List<Map<String, String>> musicList = new ArrayList<Map<String, String>>(); private SimpleAdapter adapter; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.fragment_main); //musicList=loadSongs(); list=(ListView) super.findViewById(R.id.listView1); adapter = new SimpleAdapter(getApplicationContext(), musicList, R.layout.item, new String[] { "name", "artist", "time", "data", "id" }, new int[] { R.id.name, R.id.songer, R.id.time, R.id.path, R.id.musicRating }); list.setAdapter(adapter); } public List<Map<String, String>> getmusic(){ ContentResolver musicResolver = this.getContentResolver(); Cursor cursor = /*getContentResolver()*/ musicResolver .query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, new String[] { MediaStore.Audio.Media.TITLE, MediaStore.Audio.Media.DURATION, MediaStore.Audio.Media.ALBUM, MediaStore.Audio.Media.ARTIST, MediaStore.Audio.Media._ID, MediaStore.Audio.Media.DATA, MediaStore.Audio.Media.DISPLAY_NAME }, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER); if (cursor != null && cursor.moveToFirst()) { do { /*String mName = cursor.getString(0); long mTime = cursor.getLong(1); String mAlbum = cursor.getString(2); String mArtist = cursor.getString(3); long mId = cursor.getLong(4); String mData = cursor.getString(5); */ String mName =cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.TITLE)); int mTime=cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DURATION)); String mAlbum=cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ALBUM)); String mArtist=cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.ARTIST)); int mId=cursor.getInt(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media._ID)); String mData=cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA)); String mDisplay = cursor.getString(cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DISPLAY_NAME)); HashMap a = new HashMap(); a.put("name", mName); a.put("time", mTime); //a.put("time1", mTime); a.put("album", mAlbum); a.put("artist", mArtist); a.put("id", mId); a.put("data", mData); a.put("display", mDisplay); musicList.add(a);//ArrayList System.out.println(mName + "-->" + mTime + "---->>--" + mData); } while (cursor.moveToNext()); } if (!cursor.isClosed()) { cursor.close(); } return musicList; } } ``` 问答

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 终极编程指南 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览