Android developed to get local videos and get selfie videos

Source: Internet
Author: User

1. Get all local videos

     Public voidGetloadmedia () {cursor cursor= UILApplication.instance.getApplicationContext (). Getcontentresolver (). Query (MediaStore.Video.Media.EXTERNAL_ Content_uri,NULL,NULL,NULL, MediaStore.Video.Media.DEFAULT_SORT_ORDER); Try {             for(Cursor.movetofirst ();!cursor.isafterlast (); Cursor.movetonext ()) {                intid = cursor.getint (cursor.getcolumnindexorthrow (mediastore.video.media._id));//IDString DisplayName =cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Video.Media.TITLE)); String album= Cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Video.Media.ALBUM));//albumsString artist = cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Video.Media.ARTIST));//artistString title = cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Video.Media.DISPLAY_NAME));//Display NameString MimeType =cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Video.Media.MIME_TYPE)); String Path= Cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Video.Media.DATA));//Path                LongDuration = Cursor.getint (Cursor.getcolumnindexorthrow (MediaStore.Video.Media.DURATION));//Length of Time                LongSize = Cursor.getlong (Cursor.getcolumnindexorthrow (MediaStore.Video.Media.SIZE));//sizeString Resolution =cursor.getstring (Cursor.getcolumnindexorthrow (MediaStore.Video.Media.RESOLUTION)); }        } Catch(Exception e) {e.printstacktrace (); } finally{cursor.close (); }    }

2. Get Photo Video

 Public Static Finalstring[] Videocursorcols =Newstring[] {mediastore.video.media._id, MediaStore.Video.Media.DISPLAY_NAME, MediaStore.Video.Media.TITLE, MediaStore.Video.Media.DURATION, MediaStore.Video.Media.ARTIST, MediaStore.Video.Media.ALBUM, MediaStore.Video.Media.RESOLUTION, MediaStore.Video.Media.MIME_TYPE, MediaStore.Video.Media.SIZE,    MediaStore.Video.Media.DATA};  Public StaticVideo Fileuriforvideo (activity activity, URI URI) {cursor cursor= Activity.getcontentresolver (). Query (URI, Videocursorcols,NULL,NULL,NULL); if(Cursor = =NULL|| Cursor.getcount () = = 0) {            return NULL; } Else{Video Video=NewVideo ();            Cursor.movetofirst (); /*file name*/            if(cursor.getstring (1)! =NULL) {video.setname (cursor.getstring (1)); }            /*Media name*/            if (cursor.getstring (2)! = null) {Video.setdisplayname (cursor.getstring (2)); }            /*Play Duration*/            if(Cursor.getstring (3)! =NULL) {Video.settimelong (Cursor.getint (3) + "s"); }            /*artist*/            if(Cursor.getstring (4)! =NULL) {Video.setsinger (cursor.getstring (4)); }            /*album*/            if(Cursor.getstring (5)! =NULL) {video.setalbum (cursor.getstring (5)); }            /*resolution*/            if(Cursor.getstring (6)! =NULL) {video.setresolution (cursor.getstring (6)); }            /*Media Type*/            if(Cursor.getstring (7)! =NULL) {Video.setmimetype (cursor.getstring (7). Trim ()); }            /*Media Size*/            if(Cursor.getstring (8)! =NULL) {video.setdownfilesize (NewJava.text.DecimalFormat ("#.00"). Format ((Cursor.getint (8)/1024.0/1024.0) + "MB"); }            /*Media file path*/            if(Cursor.getstring (9)! =NULL) {Video.setvoiceurl (cursor.getstring (9)); }            if(Cursor! =NULL) {cursor.close (); }            returnvideo; }    }

Android developed to get local videos and get selfie videos

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.