Fixed opening files from file manager :)

This commit is contained in:
Blatzar 2022-05-19 22:27:14 +02:00
parent 34763d4b5e
commit b4b06b2389
2 changed files with 63 additions and 42 deletions

View file

@ -669,7 +669,8 @@ class CS3IPlayer : IPlayer {
Log.i(TAG, "Rendered first frame")
val invalid = exoPlayer?.duration?.let { duration ->
duration < 20000L
// Only errors short playback when not playing downloaded files
duration < 20_000L && currentDownloadedFile == null
} ?: false
if (invalid) {
releasePlayer(saveTime = false)

View file

@ -4,14 +4,11 @@ import android.os.Bundle
import android.util.Log
import android.view.KeyEvent
import androidx.appcompat.app.AppCompatActivity
import com.hippo.unifile.UniFile
import com.lagradost.cloudstream3.CommonActivity
import com.lagradost.cloudstream3.R
import com.lagradost.cloudstream3.mvvm.logError
import com.lagradost.cloudstream3.utils.AppUtils
import com.lagradost.cloudstream3.utils.AppUtils.getUri
import com.lagradost.cloudstream3.utils.ExtractorUri
import com.lagradost.cloudstream3.utils.UIHelper.navigate
import java.io.File
const val DTAG = "PlayerActivity"
@ -45,49 +42,72 @@ class DownloadedPlayerActivity : AppCompatActivity() {
super.onCreate(savedInstanceState)
CommonActivity.init(this)
setContentView(R.layout.empty_layout)
val data = intent.data
if (data == null) {
finish()
return
}
val uri = getUri(intent.data)
if (uri == null) {
finish()
return
}
val path = uri.path
// Because it doesn't get the path when it's downloaded, I have no idea
val realPath = if (File(
intent.data?.path?.removePrefix("/file") ?: "NONE"
).exists()
) intent.data?.path?.removePrefix("/file") else path
if (realPath == null) {
finish()
return
}
val name = try {
File(realPath).name
} catch (e: Exception) {
"NULL"
}
val tryUri = try {
AppUtils.getVideoContentUri(this, realPath) ?: uri
} catch (e: Exception) {
logError(e)
uri
}
setContentView(R.layout.empty_layout)
Log.i(DTAG, "navigating")
//TODO add relative path for subs
this.navigate(
R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
DownloadFileGenerator(listOf(ExtractorUri(uri = tryUri, name = name)))
if (data.scheme == "content") {
val name = UniFile.fromUri(this, data).name
this.navigate(
R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
DownloadFileGenerator(
listOf(
ExtractorUri(
uri = data,
name = name ?: getString(R.string.downloaded_file)
)
)
)
)
)
)
}
// Legacy code, seems to work perfectly fine without it
// } else {
// val uri = getUri(intent.data)
// if (uri == null) {
// finish()
// return
// }
// val path = uri.path
// // Because it doesn't get the path when it's downloaded, I have no idea
// val realPath = if (File(
// intent.data?.path?.removePrefix("/file") ?: "NONE"
// ).exists()
// ) intent.data?.path?.removePrefix("/file") else path
//
// if (realPath == null) {
// finish()
// return
// }
//
// val name = try {
// File(realPath).name
// } catch (e: Exception) {
// "NULL"
// }
//
// val tryUri = try {
// AppUtils.getVideoContentUri(this, realPath) ?: uri
// } catch (e: Exception) {
// logError(e)
// uri
// }
//
// setContentView(R.layout.empty_layout)
// Log.i(DTAG, "navigating")
//
// //TODO add relative path for subs
// this.navigate(
// R.id.global_to_navigation_player, GeneratorPlayer.newInstance(
// DownloadFileGenerator(listOf(ExtractorUri(uri = tryUri, name = name)))
// )
// )
// }
}
}