mirror of
https://github.com/recloudstream/cloudstream.git
synced 2024-08-15 01:53:11 +00:00
Fixed MPV return intent
This commit is contained in:
parent
723c554bc8
commit
3f658a375e
2 changed files with 33 additions and 7 deletions
|
@ -155,8 +155,8 @@ object CommonActivity {
|
||||||
val resultCode = result.resultCode
|
val resultCode = result.resultCode
|
||||||
val data = result.data
|
val data = result.data
|
||||||
if (resultCode == AppCompatActivity.RESULT_OK && data != null && resumeApp.position != null && resumeApp.duration != null) {
|
if (resultCode == AppCompatActivity.RESULT_OK && data != null && resumeApp.position != null && resumeApp.duration != null) {
|
||||||
val pos = data.getLongExtra(resumeApp.position, -1L)
|
val pos = resumeApp.getPosition(data)
|
||||||
val dur = data.getLongExtra(resumeApp.duration, -1L)
|
val dur = resumeApp.getDuration(data)
|
||||||
if (dur > 0L && pos > 0L)
|
if (dur > 0L && pos > 0L)
|
||||||
DataStoreHelper.setViewPos(getKey(resumeApp.lastId), pos, dur)
|
DataStoreHelper.setViewPos(getKey(resumeApp.lastId), pos, dur)
|
||||||
removeKey(resumeApp.lastId)
|
removeKey(resumeApp.lastId)
|
||||||
|
|
|
@ -115,13 +115,15 @@ val VLC_COMPONENT = ComponentName(VLC_PACKAGE, "$VLC_PACKAGE.gui.video.VideoPlay
|
||||||
val MPV_COMPONENT = ComponentName(MPV_PACKAGE, "$MPV_PACKAGE.MPVActivity")
|
val MPV_COMPONENT = ComponentName(MPV_PACKAGE, "$MPV_PACKAGE.MPVActivity")
|
||||||
|
|
||||||
//TODO REFACTOR AF
|
//TODO REFACTOR AF
|
||||||
data class ResultResume(
|
open class ResultResume(
|
||||||
val packageString: String,
|
val packageString: String,
|
||||||
val action: String = Intent.ACTION_VIEW,
|
val action: String = Intent.ACTION_VIEW,
|
||||||
val position: String? = null,
|
val position: String? = null,
|
||||||
val duration: String? = null,
|
val duration: String? = null,
|
||||||
var launcher: ActivityResultLauncher<Intent>? = null,
|
var launcher: ActivityResultLauncher<Intent>? = null,
|
||||||
) {
|
) {
|
||||||
|
val defaultTime = -1L
|
||||||
|
|
||||||
val lastId get() = "${packageString}_last_open_id"
|
val lastId get() = "${packageString}_last_open_id"
|
||||||
suspend fun launch(id: Int?, callback: suspend Intent.() -> Unit) {
|
suspend fun launch(id: Int?, callback: suspend Intent.() -> Unit) {
|
||||||
val intent = Intent(action)
|
val intent = Intent(action)
|
||||||
|
@ -135,21 +137,45 @@ data class ResultResume(
|
||||||
callback.invoke(intent)
|
callback.invoke(intent)
|
||||||
launcher?.launch(intent)
|
launcher?.launch(intent)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
open fun getPosition(intent: Intent?): Long {
|
||||||
|
return defaultTime
|
||||||
|
}
|
||||||
|
|
||||||
|
open fun getDuration(intent: Intent?): Long {
|
||||||
|
return defaultTime
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
val VLC = ResultResume(
|
val VLC = object : ResultResume(
|
||||||
VLC_PACKAGE,
|
VLC_PACKAGE,
|
||||||
"org.videolan.vlc.player.result",
|
"org.videolan.vlc.player.result",
|
||||||
"extra_position",
|
"extra_position",
|
||||||
"extra_duration",
|
"extra_duration",
|
||||||
)
|
) {
|
||||||
|
override fun getPosition(intent: Intent?): Long {
|
||||||
|
return intent?.getLongExtra(this.position, defaultTime) ?: defaultTime
|
||||||
|
}
|
||||||
|
|
||||||
val MPV = ResultResume(
|
override fun getDuration(intent: Intent?): Long {
|
||||||
|
return intent?.getLongExtra(this.duration, defaultTime) ?: defaultTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
val MPV = object : ResultResume(
|
||||||
MPV_PACKAGE,
|
MPV_PACKAGE,
|
||||||
//"is.xyz.mpv.MPVActivity.result", // resume not working :pensive:
|
//"is.xyz.mpv.MPVActivity.result", // resume not working :pensive:
|
||||||
position = "position",
|
position = "position",
|
||||||
duration = "duration",
|
duration = "duration",
|
||||||
)
|
) {
|
||||||
|
override fun getPosition(intent: Intent?): Long {
|
||||||
|
return intent?.getIntExtra(this.position, defaultTime.toInt())?.toLong() ?: defaultTime
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getDuration(intent: Intent?): Long {
|
||||||
|
return intent?.getIntExtra(this.duration, defaultTime.toInt())?.toLong() ?: defaultTime
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
val WEB_VIDEO = ResultResume(WEB_VIDEO_CAST_PACKAGE)
|
val WEB_VIDEO = ResultResume(WEB_VIDEO_CAST_PACKAGE)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue