[Java]View Plaincopy
- public void Getalldata () {
- Contentresolver CR = Getapplication (). Getcontentresolver ();
- if (cr = = null) {
- return;
- }
- //Get All songs
- 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 {
- //Song name
- String title = cursor.getstring (cursor
- . Getcolumnindex (MediaStore.Audio.Media.TITLE));
- //singer
- String singer = cursor.getstring (cursor
- . Getcolumnindex (MediaStore.Audio.Media.ARTIST));
- //albums
- String album = cursor.getstring (cursor
- . Getcolumnindex (MediaStore.Audio.Media.ALBUM));
- //Length
- Long size = Cursor.getlong (cursor
- . Getcolumnindex (MediaStore.Audio.Media.SIZE));
- //Time length
- int duration = cursor.getint (cursor
- . Getcolumnindex (MediaStore.Audio.Media.DURATION));
- //Path
- String URL = cursor.getstring (cursor
- . Getcolumnindex (MediaStore.Audio.Media.DATA));
- //display filename
- String _display_name = cursor.getstring (cursor
- . Getcolumnindex (MediaStore.Audio.Media.DISPLAY_NAME));
- //Type
- 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 + "]";
- }
- }
http://blog.csdn.net/lzh7752/article/details/45131539
Android Multimedia Analytics-get audio information via Mediastore