一。如何得到 Music列表
我们定义 Music类,并用set/get .如下
public class Music {
private String title;
private String album;
private String singer ;
private String url;
private long size;
private long time ;
private String name ;
//setters and getters
再定义 MusicList 类,用于得到系统 中mp3音乐 的列表 。里面的方法
public static List getMusicData(Context context)
我们要用到 ContentResolver 。
ContentResolver resolver = context.getContentResolver();
在这里,我们要补充查询歌曲的方法:
Android系统提供了MediaScanner,MediaProvider,MediaStore等接口,并且提供了一套数据库表格,通过Content Provider的方式提供给用户。当手机开机或者有SD卡插拔等事件发生时,系统将会自动扫描SD卡和手机内存上的媒体文件,如audio,video,图片等,将相应的信息放到定义好的数据库表格中。在这个程序中,我们不需要关心如何去扫描手机中的文件,只要了解如何查询和使用这些信息就可以了。
MediaStore中定义了一系列的数据表格,通过ContentResolver提供的查询