Merge pull request #1873 from Bnyro/dash

Fix some issues caused by the DASH implementation
This commit is contained in:
Bnyro 2022-11-17 11:09:23 +01:00 committed by GitHub
commit 3036e8bf5f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1079,6 +1079,11 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
exoPlayer.setMediaItem(mediaItem) exoPlayer.setMediaItem(mediaItem)
} }
private fun String?.qualityToInt(): Int {
this ?: return 0
return this.toString().split("p").first().toInt()
}
private fun getAvailableResolutions(): List<VideoResolution> { private fun getAvailableResolutions(): List<VideoResolution> {
if (!this::streams.isInitialized) return listOf() if (!this::streams.isInitialized) return listOf()
@ -1095,12 +1100,27 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
} }
for (vid in videoStreams) { for (vid in videoStreams) {
if (resolutions.any {
it.resolution == vid.quality.qualityToInt()
} || vid.url == null
) {
continue
}
resolutions.add(
VideoResolution(
name = "${vid.quality.qualityToInt()}p",
resolution = vid.quality.qualityToInt()
)
)
/*
// append quality to list if it has the preferred format (e.g. MPEG) // append quality to list if it has the preferred format (e.g. MPEG)
val preferredMimeType = "video/${PlayerHelper.videoFormatPreference}" val preferredMimeType = "video/${PlayerHelper.videoFormatPreference}"
if (vid.url != null && vid.mimeType == preferredMimeType) { if (vid.url != null && vid.mimeType == preferredMimeType) {
// avoid duplicated resolutions // avoid duplicated resolutions
if (resolutions.any { if (resolutions.any {
it.resolution == vid.quality.toString().split("p").first().toInt() it.resolution == vid.quality.qualityToInt()
} }
) { ) {
continue continue
@ -1108,19 +1128,12 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
resolutions.add( resolutions.add(
VideoResolution( VideoResolution(
name = vid.quality!!, name = "${vid.quality.qualityToInt()}p",
resolution = vid.quality.toString().split("p").first().toInt() resolution = vid.quality.qualityToInt()
) )
) )
} else if (vid.quality.equals("LBRY") && vid.format.equals("MP4")) { }
resolutions.add( */
VideoResolution(
name = "LBRY MP4",
adaptiveSourceUrl = vid.url,
resolution = Int.MAX_VALUE
)
)
}
} }
if (resolutions.isEmpty()) { if (resolutions.isEmpty()) {
@ -1129,7 +1142,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
) )
} }
resolutions.add(0, VideoResolution(getString(R.string.auto_quality), Int.MAX_VALUE)) resolutions.add(0, VideoResolution(getString(R.string.auto_quality), null))
return resolutions return resolutions
} }
@ -1168,14 +1181,18 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
) )
} }
private fun setPlayerResolution(resolution: Int?) {
val params = trackSelector.buildUponParameters()
when (resolution) {
null -> params.setMaxVideoSize(Int.MAX_VALUE, Int.MAX_VALUE).setMinVideoSize(0, 0)
else -> params.setMaxVideoSize(Int.MAX_VALUE, resolution).setMinVideoSize(Int.MIN_VALUE, resolution)
}
trackSelector.setParameters(params)
}
private fun setStreamSource(streams: Streams) { private fun setStreamSource(streams: Streams) {
val defaultResolution = PlayerHelper.getDefaultResolution(requireContext()).replace("p", "") val defaultResolution = PlayerHelper.getDefaultResolution(requireContext()).replace("p", "")
if (defaultResolution != "") { if (defaultResolution != "") setPlayerResolution(defaultResolution.toInt())
val params = trackSelector.buildUponParameters()
.setMaxVideoSize(Int.MAX_VALUE, defaultResolution.toInt())
.setMinVideoSize(Int.MAX_VALUE, defaultResolution.toInt())
trackSelector.setParameters(params)
}
if (!PreferenceHelper.getBoolean(PreferenceKeys.USE_HLS_OVER_DASH, false) && if (!PreferenceHelper.getBoolean(PreferenceKeys.USE_HLS_OVER_DASH, false) &&
streams.videoStreams.orEmpty().isNotEmpty() streams.videoStreams.orEmpty().isNotEmpty()
@ -1357,12 +1374,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
.setSimpleItems( .setSimpleItems(
resolutions.map { it.name } resolutions.map { it.name }
) { which -> ) { which ->
val resolution = resolutions[which].resolution!! setPlayerResolution(resolutions[which].resolution)
val params = trackSelector.buildUponParameters()
.setMaxVideoSize(Int.MAX_VALUE, resolution)
.setMinVideoSize(Int.MAX_VALUE, resolution)
trackSelector.setParameters(params)
} }
.show(childFragmentManager) .show(childFragmentManager)
} }
@ -1379,7 +1391,7 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
BaseBottomSheet() BaseBottomSheet()
.setSimpleItems(audioLanguages) { index -> .setSimpleItems(audioLanguages) { index ->
val audioStreams = audioGroups.values.elementAt(index) val audioStreams = audioGroups.values.elementAt(index)
val lang = audioStreams.first().audioTrackId!!.substring(0, 2) val lang = audioStreams.firstOrNull()?.audioTrackId?.substring(0, 2)
val newParams = trackSelector.buildUponParameters() val newParams = trackSelector.buildUponParameters()
.setPreferredAudioLanguage(lang) .setPreferredAudioLanguage(lang)
trackSelector.setParameters(newParams) trackSelector.setParameters(newParams)