Fix mpv external subtitles (#155)

* Fix external subtitles + new libmpv build

* Fix unable to go back to 1x speed
This commit is contained in:
Jarne Demeulemeester 2022-08-30 23:41:55 +02:00 committed by GitHub
parent 6ed2f2ff7b
commit b9874db1e1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 12 additions and 34 deletions

Binary file not shown.

View file

@ -23,11 +23,6 @@
-keepnames class dev.jdtech.jellyfin.models.PlayerItem
-keepnames class dev.jdtech.jellyfin.models.DownloadSeriesMetadata
# Keep all mpvlib methods because proguard removes some which makes the app crash
-keep class is.xyz.libmpv.MPVLib {
*;
}
# ProGuard thinks all SettingsFragments are unused
-keep class dev.jdtech.jellyfin.fragments.SettingsLanguageFragment
-keep class dev.jdtech.jellyfin.fragments.SettingsAppearanceFragment

View file

@ -1,7 +1,6 @@
package dev.jdtech.jellyfin.mpv
import `is`.xyz.libmpv.MPVLib
import android.annotation.SuppressLint
import `is`.xyz.mpv.MPVLib
import android.app.Application
import android.content.Context
import android.content.res.AssetManager
@ -273,7 +272,6 @@ class MPVPlayer(
}
}
@SuppressLint("SwitchIntDef")
override fun event(@MPVLib.Event eventId: Int) {
handler.post {
when (eventId) {
@ -311,14 +309,11 @@ class MPVPlayer(
}
}
}
else -> Unit
}
}
}
override fun eventEndFile(@MPVLib.Reason reason: Int, @MPVLib.Error error: Int) {
// Nothing to do...
}
private fun setPlayerStateAndNotifyIfChanged(
playWhenReady: Boolean = getPlayWhenReady(),
@Player.PlayWhenReadyChangeReason playWhenReadyChangeReason: Int = Player.PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST,
@ -358,33 +353,17 @@ class MPVPlayer(
* Select a [Track] or disable a [TrackType] in the current player.
*
* @param trackType The [TrackType]
* @param isExternal If track is external or embed in media
* @param index Index to select or [C.INDEX_UNSET] to disable [TrackType]
* @param id Id to select or [C.INDEX_UNSET] to disable [TrackType]
* @return true if the track is or was already selected
*/
fun selectTrack(
@TrackType trackType: String,
isExternal: Boolean = false,
index: Int
id: Int
): Boolean {
if (index != C.INDEX_UNSET) {
Timber.i("${currentMpvTracks.size}")
currentMpvTracks.firstOrNull {
it.type == trackType && (if (isExternal) it.title else "${it.ffIndex}") == "$index"
}.let { track ->
if (track != null) {
Timber.i("selected track ${track.ffIndex} ${track.type}")
if (!track.selected) {
MPVLib.setPropertyInt(trackType, track.id)
}
} else {
return false
}
}
if (id != C.INDEX_UNSET) {
MPVLib.setPropertyInt(trackType, id)
} else {
if (currentMpvTracks.indexOfFirst { it.type == trackType && it.selected } != C.INDEX_UNSET) {
MPVLib.setPropertyString(trackType, "no")
}
MPVLib.setPropertyString(trackType, "no")
}
return true
}

View file

@ -1,11 +1,13 @@
package dev.jdtech.jellyfin.viewmodels
import android.app.Application
import android.net.Uri
import androidx.lifecycle.LifecycleCoroutineScope
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import com.google.android.exoplayer2.util.MimeTypes
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.jdtech.jellyfin.R
import dev.jdtech.jellyfin.database.DownloadDatabaseDao
import dev.jdtech.jellyfin.models.ExternalSubtitle
import dev.jdtech.jellyfin.models.PlayerItem
@ -26,6 +28,7 @@ import javax.inject.Inject
@HiltViewModel
class PlayerViewModel @Inject internal constructor(
private val application: Application,
private val repository: JellyfinRepository,
private val downloadDatabase: DownloadDatabaseDao
) : ViewModel() {
@ -182,7 +185,7 @@ class PlayerViewModel @Inject internal constructor(
externalSubtitles.add(
ExternalSubtitle(
mediaStream.title.orEmpty(),
mediaStream.title ?: application.getString(R.string.external),
mediaStream.language.orEmpty(),
Uri.parse(repository.getBaseUrl() + deliveryUrl),
when (mediaStream.codec) {

View file

@ -133,4 +133,5 @@
<string name="dynamic_colors_summary">Use Material You Dynamic colors (only available on Android 12+)</string>
<string name="subtitles">Subtitles</string>
<string name="subtitles_summary">Customize subtitles appearance</string>
<string name="external">External</string>
</resources>