码迷,mamicode.com
首页 > 移动开发 > 详细

Android多媒体分析-通过MediaStore获取Audio信息

时间:2015-11-18 21:06:57      阅读:229      评论:0      收藏:0      [点我收藏+]

标签:

[java] view plaincopy技术分享技术分享
 
  1.      public void getAlldata() {  
  2.         ContentResolver cr = getApplication().getContentResolver();  
  3.         if (cr == null) {  
  4.             return;  
  5.         }  
  6.         // 获取所有歌曲  
  7.         Cursor cursor = cr.query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI,  
  8.                 null, null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER);  
  9.         if (null == cursor) {  
  10.             return;  
  11.         }  
  12.         Music music;  
  13.         List<Music> list = new ArrayList<MainActivity.Music>();  
  14.         if (cursor.moveToFirst()) {  
  15.             do {  
  16.                   
  17.                 //歌曲名  
  18.                 String title = cursor.getString(cursor  
  19.                         .getColumnIndex(MediaStore.Audio.Media.TITLE));  
  20.                   
  21.                 //歌手  
  22.                 String singer = cursor.getString(cursor  
  23.                         .getColumnIndex(MediaStore.Audio.Media.ARTIST));  
  24.                   
  25.                 //专辑  
  26.                 String album = cursor.getString(cursor  
  27.                         .getColumnIndex(MediaStore.Audio.Media.ALBUM));  
  28.                   
  29.                 //长度  
  30.                 long size = cursor.getLong(cursor  
  31.                         .getColumnIndex(MediaStore.Audio.Media.SIZE));  
  32.                   
  33.                 //时长  
  34.                 int duration = cursor.getInt(cursor  
  35.                         .getColumnIndex(MediaStore.Audio.Media.DURATION));  
  36.                   
  37.                 //路径  
  38.                 String url = cursor.getString(cursor  
  39.                         .getColumnIndex(MediaStore.Audio.Media.DATA));  
  40.                   
  41.                 //显示的文件名  
  42.                 String _display_name = cursor.getString(cursor  
  43.                         .getColumnIndex(MediaStore.Audio.Media.DISPLAY_NAME));  
  44.                   
  45.                 //类型  
  46.                 String mime_type = cursor.getString(cursor  
  47.                         .getColumnIndex(MediaStore.Audio.Media.MIME_TYPE));  
  48.                 music = new Music();  
  49.                 music.setAlbum(album);  
  50.                 music.setDuration(duration);  
  51.                 music.setSinger(singer);  
  52.                 music.setSize(size);  
  53.                 music.setTitle(title);  
  54.                 music.setUrl(url);  
  55.                 music.set_display_name(_display_name);  
  56.                 music.setMime_type(mime_type);  
  57.                 list.add(music);  
  58.             } while (cursor.moveToNext());  
  59.         }  
  60.         System.out.println(list.size());  
  61.     }  
  62.     class Music  
  63.     {  
  64.         private  String title;  
  65.         private  String singer;  
  66.         private  String album;  
  67.         private  long size;  
  68.         private  int duration;  
  69.         private  String url;  
  70.         private  String _display_name;  
  71.         private String mime_type;  
  72.           
  73.         public String get_display_name() {  
  74.             return _display_name;  
  75.         }  
  76.         public void set_display_name(String _display_name) {  
  77.             this._display_name = _display_name;  
  78.         }  
  79.         public String getMime_type() {  
  80.             return mime_type;  
  81.         }  
  82.         public void setMime_type(String mime_type) {  
  83.             this.mime_type = mime_type;  
  84.         }  
  85.         public String getTitle() {  
  86.             return title;  
  87.         }  
  88.         public void setTitle(String title) {  
  89.             this.title = title;  
  90.         }  
  91.         public String getSinger() {  
  92.             return singer;  
  93.         }  
  94.         public void setSinger(String singer) {  
  95.             this.singer = singer;  
  96.         }  
  97.         public String getAlbum() {  
  98.             return album;  
  99.         }  
  100.         public void setAlbum(String album) {  
  101.             this.album = album;  
  102.         }  
  103.         public long getSize() {  
  104.             return size;  
  105.         }  
  106.         public void setSize(long size) {  
  107.             this.size = size;  
  108.         }  
  109.         public int getDuration() {  
  110.             return duration;  
  111.         }  
  112.         public void setDuration(int duration) {  
  113.             this.duration = duration;  
  114.         }  
  115.         public String getUrl() {  
  116.             return url;  
  117.         }  
  118.         public void setUrl(String url) {  
  119.             this.url = url;  
  120.         }  
  121.         @Override  
  122.         public String toString() {  
  123.             return "Music [title=" + title + ", singer=" + singer + ", album="  
  124.                     + album + ", size=" + size + ", duration=" + duration  
  125.                     + ", url=" + url + ", _display_name=" + _display_name  
  126.                     + ", mime_type=" + mime_type + "]";  
  127.         }  
  128.           
  129.     }  

 

http://blog.csdn.net/lzh7752/article/details/45131539

Android多媒体分析-通过MediaStore获取Audio信息

标签:

原文地址:http://www.cnblogs.com/cmblogs/p/4975661.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!