From b4b06b2389afdba6e6fae45f63993987463176f2 Mon Sep 17 00:00:00 2001 From: Blatzar <46196380+Blatzar@users.noreply.github.com> Date: Thu, 19 May 2022 22:27:14 +0200 Subject: [PATCH] Fixed opening files from file manager :) --- .../cloudstream3/ui/player/CS3IPlayer.kt | 3 +- .../ui/player/DownloadedPlayerActivity.kt | 102 +++++++++++------- 2 files changed, 63 insertions(+), 42 deletions(-) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt index 708bf06c..4d659034 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/CS3IPlayer.kt @@ -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) diff --git a/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt b/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt index b5edf225..6c7318e1 100644 --- a/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt +++ b/app/src/main/java/com/lagradost/cloudstream3/ui/player/DownloadedPlayerActivity.kt @@ -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))) +// ) +// ) +// } } } \ No newline at end of file