- public void getAlldata() {
- ContentResolver cr = getApplication().getContentResolver();
- if (cr == null) {
- return;
- }
-
- Cursor cursor = cr.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,
- null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);
- if (null == cursor) {
- return;
- }
- Music music;
- List<Music> list = new ArrayList<MainActivity.Music>();
- if (cursor.moveToFirst()) {
- do {
-
-
- String title = cursor.getString(cursor
- .getColumnIndex(MediaStore.Audio.Media.TITLE));
-
-
- String singer = cursor.getString(cursor
- .getColumnIndex(MediaStore.Audio.Media.ARTIST));
-
-
- String album = cursor.getString(cursor
- .getColumnIndex(MediaStore.Audio.Media.ALBUM));
-
-
- long size = cursor.getLong(cursor
- .getColumnIndex(MediaStore.Audio.Media.SIZE));
-
-
- int duration = cursor.getInt(cursor
- .getColumnIndex(MediaStore.Audio.Media.DURATION));
-
-
- String url = cursor.getString(cursor
- .getColumnIndex(MediaStore.Audio.Media.DATA));
-
-
- String _display_name = cursor.getString(cursor
- .getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));
-
-
- String mime_type = cursor.getString(cursor
- .getColumnIndex(MediaStore.Audio.Media.MIME_TYPE));
- music = new Music();
- music.setAlbum(album);
- music.setDuration(duration);
- music.setSinger(singer);
- music.setSize(size);
- music.setTitle(title);
- music.setUrl(url);
- music.set_display_name(_display_name);
- music.setMime_type(mime_type);
- list.add(music);
- } while (cursor.moveToNext());
- }
- System.out.println(list.size());
- }
- class Music
- {
- private String title;
- private String singer;
- private String album;
- private long size;
- private int duration;
- private String url;
- private String _display_name;
- private String mime_type;
-
- public String get_display_name() {
- return _display_name;
- }
- public void set_display_name(String _display_name) {
- this._display_name = _display_name;
- }
- public String getMime_type() {
- return mime_type;
- }
- public void setMime_type(String mime_type) {
- this.mime_type = mime_type;
- }
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public String getSinger() {
- return singer;
- }
- public void setSinger(String singer) {
- this.singer = singer;
- }
- public String getAlbum() {
- return album;
- }
- public void setAlbum(String album) {
- this.album = album;
- }
- public long getSize() {
- return size;
- }
- public void setSize(long size) {
- this.size = size;
- }
- public int getDuration() {
- return duration;
- }
- public void setDuration(int duration) {
- this.duration = duration;
- }
- public String getUrl() {
- return url;
- }
- public void setUrl(String url) {
- this.url = url;
- }
- @Override
- public String toString() {
- return "Music [title=" + title + ", singer=" + singer + ", album="
- + album + ", size=" + size + ", duration=" + duration
- + ", url=" + url + ", _display_name=" + _display_name
- + ", mime_type=" + mime_type + "]";
- }
-
- }
posted @
2015-06-18 09:14
brave-sailor
阅读(
745)
评论()
编辑
收藏
举报