@@ -30,10 +30,10 @@ import java.util.*
3030
3131/* *
3232 * 创建日期:2018/8/21 0021on 下午 4:40
33- * 描述:图片选择工具类
33+ * 描述:多媒体选择工具类
3434 * @author:Vincent
3535 */
36- class EasyPhoto {
36+ class EasyMedia {
3737 /* *
3838 * 设置图片选择结果回调
3939 */
@@ -48,17 +48,17 @@ class EasyPhoto {
4848
4949 private val mainHandler = Handler (Looper .getMainLooper())
5050
51- fun setError (error : ((error: Exception ) -> Unit )? ): EasyPhoto {
51+ fun setError (error : ((error: Exception ) -> Unit )? ): EasyMedia {
5252 this .error = error
5353 return this
5454 }
5555
56- fun setCallback (callback : ((file: File ) -> Unit )): EasyPhoto {
56+ fun setCallback (callback : ((file: File ) -> Unit )): EasyMedia {
5757 this .callback = callback
5858 return this
5959 }
6060
61- fun setCrop (isCrop : Boolean ): EasyPhoto {
61+ fun setCrop (isCrop : Boolean ): EasyMedia {
6262 this .isCrop = isCrop
6363 return this
6464 }
@@ -68,7 +68,7 @@ class EasyPhoto {
6868 *
6969 * @param imgPath 图片的存储路径(包括文件名和后缀)
7070 */
71- fun setFilePath (imgPath : String? ): EasyPhoto {
71+ fun setFilePath (imgPath : String? ): EasyMedia {
7272 if (imgPath.isNullOrEmpty()) {
7373 this .mFilePath = null
7474 } else {
@@ -81,11 +81,13 @@ class EasyPhoto {
8181
8282 /* *
8383 * 选择文件
84- * 支持图片、音频、视频、联系人以及其它类型文件
84+ * 支持图片、音频、视频
8585 */
8686 fun selectFile (activity : Activity ) {
8787 val intent = Intent (Intent .ACTION_PICK , null ).apply {
8888 setDataAndType(MediaStore .Images .Media .EXTERNAL_CONTENT_URI , " */*" )
89+ setDataAndType(MediaStore .Audio .Media .EXTERNAL_CONTENT_URI , " */*" )
90+ setDataAndType(MediaStore .Video .Media .EXTERNAL_CONTENT_URI , " */*" )
8991 }
9092 if (Looper .myLooper() == Looper .getMainLooper()) {
9193 selectFileInternal(intent, activity)
@@ -99,7 +101,7 @@ class EasyPhoto {
99101 */
100102 fun selectVideo (activity : Activity ) {
101103 val intent = Intent (Intent .ACTION_PICK , null ).apply {
102- setDataAndType(MediaStore .Images .Media .EXTERNAL_CONTENT_URI , " video/*" )
104+ setDataAndType(MediaStore .Video .Media .EXTERNAL_CONTENT_URI , " video/*" )
103105 }
104106 if (Looper .myLooper() == Looper .getMainLooper()) {
105107 selectFileInternal(intent, activity)
@@ -113,7 +115,7 @@ class EasyPhoto {
113115 */
114116 fun selectAudio (activity : Activity ) {
115117 val intent = Intent (Intent .ACTION_PICK , null ).apply {
116- setDataAndType(MediaStore .Images .Media .EXTERNAL_CONTENT_URI , " audio/*" )
118+ setDataAndType(MediaStore .Audio .Media .EXTERNAL_CONTENT_URI , " audio/*" )
117119 }
118120 if (Looper .myLooper() == Looper .getMainLooper()) {
119121 selectFileInternal(intent, activity)
@@ -136,6 +138,8 @@ class EasyPhoto {
136138 }
137139 }
138140
141+
142+
139143 /* *
140144 * 选择文件
141145 */
@@ -146,7 +150,7 @@ class EasyPhoto {
146150 }
147151 data ? : return @start
148152 try {
149- val inputFile = uriToFile(activity, data.data!! )
153+ val inputFile = File ( data.data.path )
150154
151155 if (isCrop) {// 裁剪
152156 zoomPhoto(inputFile, mFilePath ? : File (generateFilePath(activity)), activity)
@@ -258,8 +262,8 @@ class EasyPhoto {
258262 } else {
259263 // 兼容android7.0 使用共享文件的形式
260264 val contentValues = ContentValues (1 )
261- contentValues.put(MediaStore .Images .Media .DATA , imgFile.absolutePath)
262- activity.application.contentResolver.insert(MediaStore .Images .Media .EXTERNAL_CONTENT_URI , contentValues)
265+ contentValues.put(MediaStore .Audio .Media .DATA , imgFile.absolutePath)
266+ activity.application.contentResolver.insert(MediaStore .Audio .Media .EXTERNAL_CONTENT_URI , contentValues)
263267 }
264268
265269 val intent = Intent (MediaStore .Audio .Media .RECORD_SOUND_ACTION ).apply {
@@ -285,8 +289,8 @@ class EasyPhoto {
285289 } else {
286290 // 兼容android7.0 使用共享文件的形式
287291 val contentValues = ContentValues (1 )
288- contentValues.put(MediaStore .Images .Media .DATA , imgFile.absolutePath)
289- activity.application.contentResolver.insert(MediaStore .Images .Media .EXTERNAL_CONTENT_URI , contentValues)
292+ contentValues.put(MediaStore .Video .Media .DATA , imgFile.absolutePath)
293+ activity.application.contentResolver.insert(MediaStore .Video .Media .EXTERNAL_CONTENT_URI , contentValues)
290294 }
291295
292296 val intent = Intent (MediaStore .ACTION_VIDEO_CAPTURE ).apply {
@@ -358,8 +362,8 @@ class EasyPhoto {
358362 } else {
359363 // 兼容android7.0 使用共享文件的形式
360364 val contentValues = ContentValues (1 )
361- contentValues.put(MediaStore .Images .Media .DATA , imgFile.absolutePath)
362- activity.application.contentResolver.insert(MediaStore .Images .Media .EXTERNAL_CONTENT_URI , contentValues)
365+ contentValues.put(MediaStore .Audio .Media .DATA , imgFile.absolutePath)
366+ activity.application.contentResolver.insert(MediaStore .Audio .Media .EXTERNAL_CONTENT_URI , contentValues)
363367 }
364368 val cameraIntents = ArrayList <Intent >()
365369 val captureIntent = Intent (MediaStore .Audio .Media .RECORD_SOUND_ACTION )
@@ -396,8 +400,8 @@ class EasyPhoto {
396400 } else {
397401 // 兼容android7.0 使用共享文件的形式
398402 val contentValues = ContentValues (1 )
399- contentValues.put(MediaStore .Images .Media .DATA , imgFile.absolutePath)
400- activity.application.contentResolver.insert(MediaStore .Images .Media .EXTERNAL_CONTENT_URI , contentValues)
403+ contentValues.put(MediaStore .Video .Media .DATA , imgFile.absolutePath)
404+ activity.application.contentResolver.insert(MediaStore .Video .Media .EXTERNAL_CONTENT_URI , contentValues)
401405 }
402406 val cameraIntents = ArrayList <Intent >()
403407 val captureIntent = Intent (MediaStore .ACTION_VIDEO_CAPTURE )
@@ -433,7 +437,8 @@ class EasyPhoto {
433437 fragment.start(intent, PhotoFragment .REQ_TAKE_FILE ) { requestCode: Int , data: Intent ? ->
434438 if (requestCode == PhotoFragment .REQ_TAKE_FILE ) {
435439 if (data?.data != null ){
436- mFilePath = uriToFile(activity,data.data)
440+ mFilePath = File (data.data.path)
441+
437442 if (isCrop){
438443 zoomPhoto(takePhotoPath, mFilePath
439444 ? : File (generateFilePath(activity)), activity)
0 commit comments