@@ -54,6 +54,12 @@ class ExternalPlayerActivity : FragmentActivity() {
5454 private const val API_MX_SUBS = " subs"
5555 private const val API_MX_SUBS_NAME = " subs.name"
5656 private const val API_MX_SUBS_FILENAME = " subs.filename"
57+ private const val API_MX_RESULT_ID = " com.mxtech.intent.result.VIEW"
58+ private const val API_MX_RESULT_END_BY = " end_by"
59+ private const val API_MX_RESULT_END_BY_PLAYBACK_COMPLETION = " playback_completion"
60+
61+ // https://mpv-android.github.io/mpv-android/intent.html
62+ private const val API_MPV_RESULT_ID = " is.xyz.mpv.MPVActivity.result"
5763
5864 // https://wiki.videolan.org/Android_Player_Intents/
5965 private const val API_VLC_SUBTITLES = " subtitles_location"
@@ -65,6 +71,7 @@ class ExternalPlayerActivity : FragmentActivity() {
6571 private const val API_VIMU_RESUME = " forceresume"
6672 private const val API_VIMU_RESULT_ID = " net.gtvbox.videoplayer.result"
6773 private const val API_VIMU_RESULT_ERROR = 4
74+ private const val API_VIMU_RESULT_PLAYBACK_COMPLETED = 1 ;
6875
6976 // The extra keys used by various video players to read the end position
7077 private val resultPositionExtras = arrayOf(API_MX_RESULT_POSITION , API_VLC_RESULT_POSITION )
@@ -199,8 +206,16 @@ class ExternalPlayerActivity : FragmentActivity() {
199206 else null
200207 }
201208
209+ val playbackCompleted = when (result?.action) {
210+ API_MX_RESULT_ID -> extras.getString(API_MX_RESULT_END_BY ) == API_MX_RESULT_END_BY_PLAYBACK_COMPLETION
211+ API_MPV_RESULT_ID -> endPosition == null // in MPV playback is completed when 'position' extra is absent
212+ API_VIMU_RESULT_ID -> result?.resultCode == API_VIMU_RESULT_PLAYBACK_COMPLETED
213+ // in VLC is not possible to understand if playback is completed from resulting Intent
214+ else -> null
215+ }
216+
202217 val runtime = (mediaSource.runTimeTicks ? : item.runTimeTicks)?.ticks
203- val shouldPlayNext = runtime != null && endPosition != null && endPosition >= (runtime * 0.9 )
218+ val shouldPlayNext = (playbackCompleted) || ( runtime != null && endPosition != null && endPosition >= (runtime * 0.9 ) )
204219
205220 lifecycleScope.launch {
206221 runCatching {
@@ -209,7 +224,7 @@ class ExternalPlayerActivity : FragmentActivity() {
209224 PlaybackStopInfo (
210225 itemId = item.id,
211226 mediaSourceId = mediaSource.id,
212- positionTicks = endPosition?.inWholeTicks,
227+ positionTicks = if (playbackCompleted) runtime?.inWholeTicks else endPosition?.inWholeTicks,
213228 failed = false ,
214229 )
215230 )
0 commit comments