Skip to content

Commit

Permalink
[Feature] Support MOV Video Format (#398)
Browse files Browse the repository at this point in the history
  • Loading branch information
leonlatsch authored Jan 13, 2025
1 parent 4ba58a4 commit 5e1f2ea
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,12 @@ enum class PhotoType(
GIF(3, "image/gif"),
MP4(4, "video/mp4"),
MPEG(5, "video/mpeg"),
WEBM(6, "video/webm");
WEBM(6, "video/webm"),
MOV(7, "video/quicktime");

val isVideo: Boolean
get() = when (value) {
4, 5, 6 -> true
4, 5, 6, 7 -> true
else -> false
}

Expand All @@ -52,6 +53,17 @@ enum class PhotoType(
* Used in converters.
*/
fun fromValue(value: Int) = values().first { it.value == value }

fun fromMimeType(mimeType: String?): PhotoType = when (mimeType) {
PNG.mimeType -> PNG
JPEG.mimeType -> JPEG
GIF.mimeType -> GIF
MP4.mimeType -> MP4
MPEG.mimeType -> MPEG
WEBM.mimeType -> WEBM
MOV.mimeType -> MOV
else -> UNDEFINED
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -97,15 +97,10 @@ class PhotoRepository @Inject constructor(
* Returns re created uuid
*/
suspend fun safeImportPhoto(sourceUri: Uri): String {
val type = when (app.contentResolver.getType(sourceUri)) {
PhotoType.PNG.mimeType -> PhotoType.PNG
PhotoType.JPEG.mimeType -> PhotoType.JPEG
PhotoType.GIF.mimeType -> PhotoType.GIF
PhotoType.MP4.mimeType -> PhotoType.MP4
PhotoType.MPEG.mimeType -> PhotoType.MPEG
PhotoType.WEBM.mimeType -> PhotoType.WEBM
else -> return String.empty
}
val mimeType = app.contentResolver.getType(sourceUri)
val type = PhotoType.fromMimeType(mimeType)

if (type == PhotoType.UNDEFINED) return String.empty

val fileName =
getFileName(app.contentResolver, sourceUri) ?: UUID.randomUUID().toString()
Expand Down

0 comments on commit 5e1f2ea

Please sign in to comment.