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