-
-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Don't close file descriptors after using them. * move some things around * fix secondary-sub type
- Loading branch information
1 parent
ef408cb
commit 48678e9
Showing
5 changed files
with
78 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerUtils.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package live.mehiz.mpvkt.ui.player | ||
|
||
import android.content.Context | ||
import android.net.Uri | ||
import android.os.ParcelFileDescriptor | ||
import android.util.Log | ||
import `is`.xyz.mpv.Utils | ||
|
||
internal fun Uri.openContentFd(context: Context): String? { | ||
return context.contentResolver.openFileDescriptor(this, "r")?.detachFd()?.let { | ||
Utils.findRealPath(it)?.also { _ -> | ||
ParcelFileDescriptor.adoptFd(it).close() | ||
} ?: "fd://$it" | ||
} | ||
} | ||
|
||
internal fun Uri.resolveUri(context: Context): String? { | ||
val filepath = when (scheme) { | ||
"file" -> path | ||
"content" -> openContentFd(context) | ||
"data" -> "data://$schemeSpecificPart" | ||
in Utils.PROTOCOLS -> toString() | ||
else -> null | ||
} | ||
|
||
if (filepath == null) Log.e(TAG, "unknown scheme: $scheme") | ||
return filepath | ||
} | ||
|
||
internal val videoExtensions = listOf( | ||
"264", "265", "3g2", "3ga", "3gp", "3gp2", "3gpp", "3gpp2", "3iv", "amr", "asf", | ||
"asx", "av1", "avc", "avf", "avi", "bdm", "bdmv", "clpi", "cpi", "divx", "dv", "evo", | ||
"evob", "f4v", "flc", "fli", "flic", "flv", "gxf", "h264", "h265", "hdmov", "hdv", | ||
"hevc", "lrv", "m1u", "m1v", "m2t", "m2ts", "m2v", "m4u", "m4v", "mkv", "mod", "moov", | ||
"mov", "mp2", "mp2v", "mp4", "mp4v", "mpe", "mpeg", "mpeg2", "mpeg4", "mpg", "mpg4", | ||
"mpl", "mpls", "mpv", "mpv2", "mts", "mtv", "mxf", "mxu", "nsv", "nut", "ogg", "ogm", | ||
"ogv", "ogx", "qt", "qtvr", "rm", "rmj", "rmm", "rms", "rmvb", "rmx", "rv", "rvx", | ||
"sdp", "tod", "trp", "ts", "tsa", "tsv", "tts", "vc1", "vfw", "vob", "vro", "webm", | ||
"wm", "wmv", "wmx", "x264", "x265", "xvid", "y4m", "yuv", | ||
) | ||
|
||
internal val audioExtensions = listOf( | ||
"3ga", "3ga2", "a52", "aac", "ac3", "adt", "adts", "aif", "aifc", "aiff", "alac", | ||
"amr", "ape", "au", "awb", "dsf", "dts", "dts-hd", "dtshd", "eac3", "f4a", "flac", | ||
"lpcm", "m1a", "m2a", "m4a", "mk3d", "mka", "mlp", "mp+", "mp1", "mp2", "mp3", "mpa", | ||
"mpc", "mpga", "mpp", "oga", "ogg", "opus", "pcm", "ra", "ram", "rax", "shn", "snd", | ||
"spx", "tak", "thd", "thd+ac3", "true-hd", "truehd", "tta", "wav", "weba", "wma", "wv", | ||
"wvp", | ||
) | ||
|
||
internal val imageExtensions = listOf( | ||
"apng", "bmp", "exr", "gif", "j2c", "j2k", "jfif", "jp2", "jpc", "jpe", "jpeg", "jpg", | ||
"jpg2", "png", "tga", "tif", "tiff", "webp", | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters