diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2d43bf6..3c24e29 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -34,7 +34,7 @@ android:launchMode="singleTask" android:supportsPictureInPicture="true" android:resizeableActivity="true" - android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize|keyboardHidden|keyboard" + android:configChanges="orientation|screenLayout|screenSize|smallestScreenSize|keyboardHidden|keyboard|uiMode" android:theme="@style/Theme.MpvKt"> diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt index 7605e6c..c44c8b3 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt @@ -137,6 +137,12 @@ class PlayerActivity : AppCompatActivity() { } } + private fun setupIntents(intent: Intent) { + val title = intent.getStringExtra("title") + if (title?.isNotBlank() == true) viewModel.fileName = intent.getStringExtra("title") ?: "" + player.timePos = intent.getIntExtra("position", 0) / 1000 + } + private fun parsePathFromIntent(intent: Intent): String? { val filepath: String? = when (intent.action) { Intent.ACTION_VIEW -> intent.data?.let { resolveUri(it) } @@ -226,6 +232,7 @@ class PlayerActivity : AppCompatActivity() { viewModel.loadChapters() viewModel.loadTracks() viewModel.getDecoder() + setupIntents(intent) } MPVLib.mpvEventId.MPV_EVENT_SEEK -> { @@ -233,11 +240,28 @@ class PlayerActivity : AppCompatActivity() { } MPVLib.mpvEventId.MPV_EVENT_END_FILE -> { - onDestroy() + endPlayback(EndPlaybackReason.PlaybackCompleted) } } } + override fun finish() { + endPlayback(EndPlaybackReason.ExternalAction) + } + + private fun endPlayback(reason: EndPlaybackReason) { + if (!intent.getBooleanExtra("return_result", false)) { + super.finish() + return + } + val returnIntent = Intent() + returnIntent.putExtra("end_by", reason.value) + player.timePos?.let { returnIntent.putExtra("position", it * 1000) } + player.duration?.let { returnIntent.putExtra("duration", it * 1000) } + setResult(RESULT_OK, returnIntent) + super.finish() + } + internal fun efEvent(err: String?) { } diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerEnums.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerEnums.kt index a9d50ab..cac343c 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerEnums.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerEnums.kt @@ -50,3 +50,8 @@ enum class Sheets { ; } +enum class EndPlaybackReason(val value: String) { + ExternalAction("external_action"), + PlaybackCompleted("playback_completion"), + Error("error"), +} diff --git a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/Seekbar.kt b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/Seekbar.kt index 3392847..bdf0e91 100644 --- a/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/Seekbar.kt +++ b/app/src/main/java/live/mehiz/mpvkt/ui/player/controls/components/Seekbar.kt @@ -6,7 +6,6 @@ import androidx.compose.foundation.layout.Arrangement import androidx.compose.foundation.layout.Row import androidx.compose.foundation.layout.fillMaxHeight import androidx.compose.foundation.layout.height -import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.wrapContentHeight import androidx.compose.material.ripple.rememberRipple import androidx.compose.material3.MaterialTheme @@ -94,9 +93,8 @@ fun VideoTimer( ) } -fun Chapter.toSegment(): Segment { - return Segment(this.title ?: "", this.time.toFloat()) -} +// Seeker doesn't like the first chapter's time being bigger than 0 +fun Chapter.toSegment() = Segment(title ?: time.toString(), if(index != 0) time.toFloat() else 0f) @Preview @Composable