Android的多媒體文件主要存儲在/data/data/com.android.providers.media/databases目錄下,該目錄下有兩個db文件,一個是內部存儲數據庫文件(internal.db),一個是存儲卡數據庫(external-XXXX.db)。
媒體文件的操做主要是圍繞着這兩個數據庫來進行。這兩個數據庫的結構是徹底如出一轍的。html
Android提供了MediaStore類,該類是一個ContentProvider,管理着設備上自帶的和外部的多媒體文件,同時包含着每個多媒體文件的數據信息。 android
經過Uri咱們能夠獲取到媒體信息的完整路徑,類型等信息,一樣,咱們也能夠經過文件路徑建立Uri數據庫
由文件路徑獲得URIide
Uri mUri = Uri.parse("content://media/external/images/media"); Uri mImageUri = null; Cursor cursor = mContext.getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, null, null, MediaStore.Images.Media.DEFAULT_SORT_ORDER); cursor.moveToFirst(); while (!cursor.isAfterLast()) { String data = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA)); if (picPath.equals(data)) { int ringtoneID = cursor.getInt(cursor.getColumnIndex(MediaStore.MediaColumns._ID)); mImageUri = Uri.withAppendedPath(mUri, ""+ ringtoneID); break; } cursor.moveToNext(); }
由Uri獲取文件路徑學習
string myImageUrl = "content://media/external/images/media/***"; Uri uri = Uri.parse(myImageUrl); String[] proj = { MediaStore.Images.Media.DATA }; Cursor actualimagecursor = mContext.getContentResolver().query(uri,proj,null,null,null); int actual_image_column_index = actualimagecursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA); actualimagecursor.moveToFirst(); String img_path = actualimagecursor.getString(actual_image_column_index); File file = new File(img_path); Uri fileUri = Uri.fromFile(file);
獲取本地媒體數據庫中的video相關信息spa
private void testScanVideoUri(){ Log.w(TAG,"testScanVideoUri come in=="+MediaStore.Video.Media.EXTERNAL_CONTENT_URI); Cursor cursor = mContext.getContentResolver().query(MediaStore.Video.Media.EXTERNAL_CONTENT_URI, null, null,null, null); int totalCount =cursor.getCount(); Log.w(TAG,"totalCount = "+totalCount); cursor.moveToFirst(); for( int i = 0;i < totalCount;i++){ String data = cursor.getString(cursor.getColumnIndex(MediaStore.MediaColumns.DATA)); String data1 = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.DATA)); String title = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.TITLE)); String type = cursor.getString(cursor.getColumnIndex(MediaStore.Video.Media.MIME_TYPE)); int id = cursor.getInt(cursor.getColumnIndex(MediaStore.Video.Media._ID)); Log.i(TAG,"data="+data); Log.i(TAG,"data1="+data1); Log.i(TAG,"title="+title); Log.i(TAG,"type="+type); Log.i(TAG,"id="+id); cursor.moveToNext(); } Log.w(TAG,"testScanVideoUri come out"); }
參考:
Android媒體的一些使用總結
http://blog.csdn.net/xingtian713/article/details/6458150.net
Android媒體的一些使用總結(2)
http://blog.csdn.net/xingtian713/article/details/6525411code
Android多媒體學習一:Android中Image的簡單實例。
http://blog.csdn.net/chenjie19891104/article/details/6320323htm
Android開發之旅: Intents和Intent Filters(理論部分)
http://www.cnblogs.com/skynet/archive/2010/07/20/1781644.htmlblog
Android學習筆記——文件路徑(/mnt/sdcard/...)、Uri(content://media/external/...)學習 (比較透徹)
http://www.cnblogs.com/lingyun1120/archive/2012/04/18/2455212.html
Android 4.4從圖庫選擇圖片,獲取圖片路徑並裁剪
http://blog.csdn.net/tempersitu/article/details/20557383