2012年1月5日

Android获得mp3文件信息





public boolean GetMp3Info(String mpFullname)
{
try
{
mpFilename = "";
mpTitle = "";
mpArtist = "";
mpAlbum = "";
mpDuration = "";
mpSize = "0";
String selection = MediaStore.Audio.Media.DATA + " = ?"; // like
//String path="/mnt/sdcard/music";
String[] selectionArgs = {"/mnt" + mpFullname};
//String selection = MediaStore.Audio.Media.IS_MUSIC + "!=0";
String [] projection = {
//MediaStore.Audio.Media._ID,
MediaStore.Audio.Media.TITLE,
MediaStore.Audio.Media.ARTIST,
MediaStore.Audio.Media.ALBUM,
MediaStore.Audio.Media.DURATION,
MediaStore.Audio.Media.SIZE
//MediaStore.Audio.Media.DATA, // --> Location
//MediaStore.Audio.Media.DISPLAY_NAME,
};

Cursor cursor = null;
cursor = managedQuery(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, projection, selection, selectionArgs, null);
// Cursor cursor2 = query(MediaStore.Audio.Media.EXTERNAL_CONTENT_URI, null, 
// null, null, MediaStore.Audio.Media.DEFAULT_SORT_ORDER)
mpTitle = cursor.getString(0).toString();
mpArtist = cursor.getString(1).toString();
mpAlbum = cursor.getString(2).toString();
mpDuration = cursor.getString(3).toString();
mpSize = cursor.getString(4).toString();
//cursor.getString(5).toString();
return true;
}
catch (Exception e)
{
return false;
}
} // GetMp3Info() ends

没有评论: