Android Multimedia Access

Source: Internet
Author: User

Android multimedia files are mainly stored in the/data/data/com.android.providers.media/databases directory, the directory has two DB files, one is the internal storage database file (internal.db), One is the memory card database (EXTERNAL-XXXX.DB).
The operation of the media file is mainly around these two databases. The two databases are completely identical in structure.

Android provides the Mediastore class, which is a contentprovider that manages the multimedia files that are on and off the device, and contains the data information for each multimedia file.

Through the URI we can get the full path to the media information, type and other information, as well, we can also create a URI through the file path

Get URI from File path

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)) {intRingtoneid =Cursor.getint (Cursor.getcolumnindex (mediastore.mediacolumns._id)); Mimageuri= Uri.withappendedpath (MUri, "" +Ringtoneid);  Break;    } cursor.movetonext (); }


Get file path by 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); intActual_image_column_index =Actualimagecursor.getcolumnindexorthrow (MediaStore.Images.Media.DATA);           Actualimagecursor.movetofirst (); String Img_path=actualimagecursor.getstring (Actual_image_column_index); File File=NewFile (Img_path); Uri Fileuri= Uri.fromfile (file);


Get video-related information in the local media database

    Private voidTestscanvideouri () {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); intTotalCount =Cursor.getcount (); LOG.W (TAG,"TotalCount =" +totalcount);                Cursor.movetofirst ();  for(inti = 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)); intID =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"); }

Reference :
Some usage summary of Android Media
http://blog.csdn.net/xingtian713/article/details/6458150

Some uses of Android media summary (2)
http://blog.csdn.net/xingtian713/article/details/6525411

Android Multimedia Learning One: A simple example of an image in Android.
http://blog.csdn.net/chenjie19891104/article/details/6320323

Android Development Tour: Intents and Intent Filters (theoretical part)
Http://www.cnblogs.com/skynet/archive/2010/07/20/1781644.html

Android Learning Note-file path (/mnt/sdcard/...), Uri (content://media/external/...) Learning (more thorough)
Http://www.cnblogs.com/lingyun1120/archive/2012/04/18/2455212.html

Android 4.4 Select picture from gallery, get picture path and crop
http://blog.csdn.net/tempersitu/article/details/20557383

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.