1111import android .text .TextUtils ;
1212import android .util .Log ;
1313
14+ import android .webkit .MimeTypeMap ;
1415import com .yuruiyin .richeditor .enumtype .FileTypeEnum ;
1516
1617import java .io .File ;
@@ -31,19 +32,26 @@ public static String getFileType(String path) {
3132 return FileTypeEnum .STATIC_IMAGE ;
3233 }
3334
34- if (path .endsWith (".mp4" ) || path .endsWith (".avi" )
35- || path .endsWith (".3gpp" ) || path .endsWith (".3gp" ) || path .startsWith (".mov" )) {
36- return FileTypeEnum .VIDEO ;
37- } else if (path .endsWith (".PNG" ) || path .endsWith (".png" ) || path .endsWith (".jpeg" )
38- || path .endsWith (".jpg" )
39- || path .endsWith (".webp" ) || path .endsWith (".WEBP" ) || path .endsWith (".JPEG" )
40- || path .endsWith (".bmp" )) {
35+ String fileExtension = MimeTypeMap .getFileExtensionFromUrl (path );
36+ String mimeType = MimeTypeMap .getSingleton ().getMimeTypeFromExtension (fileExtension );
37+
38+ if (TextUtils .isEmpty (mimeType )) {
4139 return FileTypeEnum .STATIC_IMAGE ;
42- } else if (path .endsWith (".gif" ) || path .endsWith (".GIF" )) {
40+ }
41+
42+ if (mimeType .contains ("video" )) {
43+ return FileTypeEnum .VIDEO ;
44+ }
45+
46+ if (mimeType .contains ("gif" )) {
4347 return FileTypeEnum .GIF ;
44- } else if (path .endsWith (".mp3" ) || path .endsWith (".amr" )
45- || path .endsWith (".aac" ) || path .endsWith (".war" )
46- || path .endsWith (".flac" ) || path .endsWith (".lamr" )) {
48+ }
49+
50+ if (mimeType .contains ("image" )) {
51+ return FileTypeEnum .STATIC_IMAGE ;
52+ }
53+
54+ if (mimeType .contains ("audio" )) {
4755 return FileTypeEnum .AUDIO ;
4856 }
4957
0 commit comments