@@ -6,14 +6,12 @@ import android.content.Context
6
6
import android.database.Cursor
7
7
import android.database.sqlite.SQLiteException
8
8
import android.graphics.Bitmap
9
- import android.media.MediaMetadataRetriever
10
9
import android.net.Uri
11
10
import android.os.Build
12
11
import android.provider.MediaStore
13
12
import com.xyoye.common_component.base.app.BaseApplication
14
- import com.xyoye.common_component.extension.isInvalid
15
13
import com.xyoye.common_component.extension.toText
16
- import com.xyoye.data_component.entity.VideoEntity
14
+ import com.xyoye.common_component.utils.meida.VideoExtension
17
15
import java.io.File
18
16
import java.io.FileOutputStream
19
17
import java.io.IOException
@@ -25,14 +23,6 @@ import java.util.Locale
25
23
* Created by xyoye on 2020/11/26.
26
24
*/
27
25
28
- private val commonVideoExtension = arrayOf(
29
- " 3gp" , " avi" , " flv" , " mp4" ,
30
- " m4v" , " mkv" , " mov" , " mpeg" ,
31
- " mpg" , " mpe" , " rm" , " rmvb" ,
32
- " wmv" , " asf" , " asx" , " dat" ,
33
- " vob" , " m3u8" , " m2ts" , " m4s"
34
- )
35
-
36
26
val supportSubtitleExtension = arrayOf(
37
27
" ass" , " scc" , " stl" , " srt" ,
38
28
" ttml"
@@ -45,7 +35,7 @@ val supportAudioExtension = arrayOf(
45
35
46
36
fun isVideoFile (filePath : String ): Boolean {
47
37
val extension = getFileExtension(filePath)
48
- return commonVideoExtension.contains (extension.lowercase( Locale . ROOT ) )
38
+ return VideoExtension .isSupport (extension)
49
39
}
50
40
51
41
fun isSubtitleFile (filePath : String ): Boolean {
@@ -109,41 +99,6 @@ object MediaUtils {
109
99
}
110
100
}
111
101
112
- /* *
113
- * 扫描文件夹内视频文件
114
- */
115
- fun scanVideoFile (folderPath : String ): MutableList <VideoEntity > {
116
- val folderFile = File (folderPath)
117
- if (! folderFile.exists())
118
- return mutableListOf ()
119
-
120
- val childFileArray = folderFile.listFiles() ? : return mutableListOf ()
121
-
122
- val videoEntities = mutableListOf<VideoEntity >()
123
- childFileArray.forEach {
124
- if (it.isFile && isVideoFile(it.absolutePath)) {
125
- videoEntities.add(
126
- VideoEntity (
127
- 0 ,
128
- 0 ,
129
- 0 ,
130
- it.absolutePath,
131
- folderPath,
132
- null ,
133
- null ,
134
- getVideoDuration(it),
135
- it.length(),
136
- isFilter = false ,
137
- isExtend = true
138
- )
139
- )
140
- } else if (it.isDirectory) {
141
- videoEntities.addAll(scanVideoFile(it.absolutePath))
142
- }
143
- }
144
- return videoEntities
145
- }
146
-
147
102
/* *
148
103
* 获取Uri对应文件的真实路径
149
104
*/
@@ -210,22 +165,4 @@ object MediaUtils {
210
165
}
211
166
return false
212
167
}
213
-
214
- private fun getVideoDuration (videoFile : File ): Long {
215
- if (videoFile.isInvalid()) {
216
- return 0
217
- }
218
- val retriever = MediaMetadataRetriever ()
219
- return try {
220
- retriever.setDataSource(BaseApplication .getAppContext(), Uri .fromFile(videoFile))
221
- retriever.extractMetadata(MediaMetadataRetriever .METADATA_KEY_DURATION )
222
- ?.toLongOrNull()
223
- ? : 0
224
- } catch (e: Exception ) {
225
- e.printStackTrace()
226
- 0
227
- } finally {
228
- retriever.release()
229
- }
230
- }
231
168
}
0 commit comments