forked from recloudstream/cloudstream
vlc stuff
This commit is contained in:
parent
1e83d21db4
commit
0b95d6ad33
1 changed files with 57 additions and 28 deletions
|
@ -6,6 +6,7 @@ import android.net.Uri
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.widget.Toast
|
import android.widget.Toast
|
||||||
import androidx.core.content.FileProvider
|
import androidx.core.content.FileProvider
|
||||||
|
import androidx.core.net.toUri
|
||||||
import androidx.lifecycle.LiveData
|
import androidx.lifecycle.LiveData
|
||||||
import androidx.lifecycle.MutableLiveData
|
import androidx.lifecycle.MutableLiveData
|
||||||
import androidx.lifecycle.ViewModel
|
import androidx.lifecycle.ViewModel
|
||||||
|
@ -954,7 +955,15 @@ class ResultViewModel2 : ViewModel() {
|
||||||
return LinkLoadingResult(sortUrls(links), sortSubs(subs))
|
return LinkLoadingResult(sortUrls(links), sortSubs(subs))
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun playWithVlc(act: Activity?, data: LinkLoadingResult, id: Int) = ioSafe {
|
// https://wiki.videolan.org/Android_Player_Intents/
|
||||||
|
private fun playWithVlc(
|
||||||
|
act: Activity?,
|
||||||
|
data: LinkLoadingResult,
|
||||||
|
id: Int,
|
||||||
|
resume: Boolean = true,
|
||||||
|
// if it is only a single link then resume works correctly
|
||||||
|
singleFile: Boolean? = true
|
||||||
|
) = ioSafe {
|
||||||
if (act == null) return@ioSafe
|
if (act == null) return@ioSafe
|
||||||
if (data.links.isEmpty()) {
|
if (data.links.isEmpty()) {
|
||||||
showToast(act, R.string.no_links_found_toast, Toast.LENGTH_SHORT)
|
showToast(act, R.string.no_links_found_toast, Toast.LENGTH_SHORT)
|
||||||
|
@ -966,21 +975,6 @@ class ResultViewModel2 : ViewModel() {
|
||||||
if (act.checkWrite()) return@ioSafe
|
if (act.checkWrite()) return@ioSafe
|
||||||
}
|
}
|
||||||
|
|
||||||
val outputDir = act.cacheDir
|
|
||||||
val outputFile = withContext(Dispatchers.IO) {
|
|
||||||
File.createTempFile("mirrorlist", ".m3u8", outputDir)
|
|
||||||
}
|
|
||||||
var text = "#EXTM3U"
|
|
||||||
|
|
||||||
// With subtitles it doesn't work for no reason :(
|
|
||||||
// for (sub in data.subs) {
|
|
||||||
// text += "\n#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"subs\",NAME=\"${sub.name}\",DEFAULT=NO,AUTOSELECT=NO,FORCED=NO,LANGUAGE=\"${sub.name}\",URI=\"${sub.url}\""
|
|
||||||
// }
|
|
||||||
for (link in data.links) {
|
|
||||||
text += "\n#EXTINF:, ${link.name}\n${link.url}"
|
|
||||||
}
|
|
||||||
outputFile.writeText(text)
|
|
||||||
|
|
||||||
val vlcIntent = Intent(VLC_INTENT_ACTION_RESULT)
|
val vlcIntent = Intent(VLC_INTENT_ACTION_RESULT)
|
||||||
|
|
||||||
vlcIntent.setPackage(VLC_PACKAGE)
|
vlcIntent.setPackage(VLC_PACKAGE)
|
||||||
|
@ -988,24 +982,59 @@ class ResultViewModel2 : ViewModel() {
|
||||||
vlcIntent.addFlags(Intent.FLAG_GRANT_PREFIX_URI_PERMISSION)
|
vlcIntent.addFlags(Intent.FLAG_GRANT_PREFIX_URI_PERMISSION)
|
||||||
vlcIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
vlcIntent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION)
|
||||||
vlcIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
vlcIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION)
|
||||||
|
val outputDir = act.cacheDir
|
||||||
|
|
||||||
vlcIntent.setDataAndType(
|
if (singleFile ?: (data.links.size == 1)) {
|
||||||
FileProvider.getUriForFile(
|
vlcIntent.setDataAndType(data.links.first().url.toUri(), "video/*")
|
||||||
act,
|
} else {
|
||||||
act.applicationContext.packageName + ".provider",
|
val outputFile = File.createTempFile("mirrorlist", ".m3u8", outputDir)
|
||||||
outputFile
|
|
||||||
), "video/*"
|
|
||||||
)
|
|
||||||
|
|
||||||
val startId = VLC_FROM_PROGRESS
|
var text = "#EXTM3U"
|
||||||
|
|
||||||
val position = when (startId) {
|
// With subtitles it doesn't work for no reason :(
|
||||||
VLC_FROM_START -> 1
|
// for (sub in data.subs) {
|
||||||
VLC_FROM_PROGRESS -> 0
|
// text += "\n#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID=\"subs\",NAME=\"${sub.name}\",DEFAULT=NO,AUTOSELECT=NO,FORCED=NO,LANGUAGE=\"${sub.name}\",URI=\"${sub.url}\""
|
||||||
else -> 0
|
// }
|
||||||
|
for (link in data.links) {
|
||||||
|
text += "\n#EXTINF:, ${link.name}\n${link.url}"
|
||||||
|
}
|
||||||
|
outputFile.writeText(text)
|
||||||
|
|
||||||
|
vlcIntent.setDataAndType(
|
||||||
|
FileProvider.getUriForFile(
|
||||||
|
act,
|
||||||
|
act.applicationContext.packageName + ".provider",
|
||||||
|
outputFile
|
||||||
|
), "video/*"
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val position = if (resume) {
|
||||||
|
getViewPos(id)?.position ?: 0L
|
||||||
|
} else {
|
||||||
|
1L
|
||||||
|
}
|
||||||
|
vlcIntent.putExtra("from_start", !resume)
|
||||||
vlcIntent.putExtra("position", position)
|
vlcIntent.putExtra("position", position)
|
||||||
|
//vlcIntent.putExtra("subtitles_location", data.subs.first().url)
|
||||||
|
/*for (s in data.subs) {
|
||||||
|
if (s.origin == SubtitleOrigin.URL) {
|
||||||
|
try {
|
||||||
|
val txt = app.get(s.url, s.headers).text
|
||||||
|
val subtitleFile = File.createTempFile("subtitle1", ".srt", outputDir)
|
||||||
|
subtitleFile.writeText(txt)
|
||||||
|
println("Subtitles::::::${subtitleFile.path}")
|
||||||
|
vlcIntent.putExtra("subtitles_location", FileProvider.getUriForFile(
|
||||||
|
act,
|
||||||
|
act.applicationContext.packageName + ".provider",
|
||||||
|
subtitleFile
|
||||||
|
))
|
||||||
|
break
|
||||||
|
} catch (t : Throwable) {
|
||||||
|
logError(t)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
vlcIntent.component = VLC_COMPONENT
|
vlcIntent.component = VLC_COMPONENT
|
||||||
act.setKey(VLC_LAST_ID_KEY, id)
|
act.setKey(VLC_LAST_ID_KEY, id)
|
||||||
|
|
Loading…
Reference in a new issue