Add option to disable subtitle in mpv (#110)
* add empty subtitle track * toggle selected variable * does this work * Revert "toggle selected variable" This reverts commit 87589f1d34e741205674e66855b53d79a1f70adb. * this should work * this should work 2.0 * remove empty track if there are no subtitle tracks
This commit is contained in:
parent
2f808750f6
commit
92e4b8eafc
3 changed files with 25 additions and 1 deletions
|
@ -43,6 +43,8 @@ class TrackSelectionDialogFragment(
|
|||
trackNames = viewModel.currentSubtitleTracks.map { track ->
|
||||
if (track.title.isEmpty()) {
|
||||
"${track.lang} - ${track.codec}"
|
||||
} else if (track.title.isNotEmpty() && track.lang.isEmpty() && track.codec.isEmpty()) {
|
||||
track.title
|
||||
} else {
|
||||
"${track.title} - ${track.lang} - ${track.codec}"
|
||||
}
|
||||
|
@ -52,7 +54,7 @@ class TrackSelectionDialogFragment(
|
|||
builder.setTitle(getString(R.string.select_subtile_track))
|
||||
.setSingleChoiceItems(
|
||||
trackNames.toTypedArray(),
|
||||
viewModel.currentSubtitleTracks.indexOfFirst { it.selected }) { dialog, which ->
|
||||
viewModel.currentSubtitleTracks.indexOfFirst { if (viewModel.disableSubtitle) it.ffIndex == -1 else it.selected }) { dialog, which ->
|
||||
viewModel.switchToTrack(
|
||||
TrackType.SUBTITLE,
|
||||
viewModel.currentSubtitleTracks[which]
|
||||
|
|
|
@ -1470,6 +1470,22 @@ class MPVPlayer(
|
|||
var indexCurrentAudio: Int = C.INDEX_UNSET
|
||||
var indexCurrentText: Int = C.INDEX_UNSET
|
||||
try {
|
||||
val emptyTrack = Track(
|
||||
id = -1,
|
||||
type = TrackType.SUBTITLE,
|
||||
mimeType = MimeTypes.BASE_TYPE_TEXT,
|
||||
title = "None",
|
||||
lang = "",
|
||||
external = false,
|
||||
selected = false,
|
||||
externalFilename = null,
|
||||
ffIndex = -1,
|
||||
codec = "",
|
||||
width = null,
|
||||
height = null
|
||||
)
|
||||
tracks.add(emptyTrack)
|
||||
trackListText.add(emptyTrack.toFormat())
|
||||
val currentTrackList = JSONArray(trackList)
|
||||
for (index in 0 until currentTrackList.length()) {
|
||||
val currentTrack = Track.fromJSON(currentTrackList.getJSONObject(index))
|
||||
|
@ -1499,6 +1515,10 @@ class MPVPlayer(
|
|||
else -> continue
|
||||
}
|
||||
}
|
||||
if (trackListText.size == 1 && trackListText[0].id == emptyTrack.id.toString()) {
|
||||
tracks.remove(emptyTrack)
|
||||
trackListText.removeFirst()
|
||||
}
|
||||
val trackGroups = mutableListOf<TrackGroup>()
|
||||
val trackSelections = mutableListOf<TrackSelection>()
|
||||
if (trackListVideo.isNotEmpty()) {
|
||||
|
|
|
@ -59,6 +59,7 @@ constructor(
|
|||
private var playbackPosition: Long = 0
|
||||
|
||||
var playbackSpeed: Float = 1f
|
||||
var disableSubtitle: Boolean = false
|
||||
|
||||
private val sp = PreferenceManager.getDefaultSharedPreferences(application)
|
||||
|
||||
|
@ -249,6 +250,7 @@ constructor(
|
|||
fun switchToTrack(trackType: String, track: MPVPlayer.Companion.Track) {
|
||||
if (player is MPVPlayer) {
|
||||
player.selectTrack(trackType, isExternal = false, index = track.ffIndex)
|
||||
disableSubtitle = track.ffIndex == -1
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue