option to force hls

This commit is contained in:
Bnyro 2022-11-16 18:42:57 +01:00
parent e403bd379a
commit 74651b7617
5 changed files with 44 additions and 31 deletions

View File

@ -81,6 +81,7 @@ object PreferenceKeys {
const val LIMIT_HLS = "limit_hls"
const val PROGRESSIVE_LOADING_INTERVAL_SIZE = "progressive_loading_interval"
const val ALTERNATIVE_PLAYER_LAYOUT = "alternative_player_layout"
const val USE_HLS_OVER_DASH = "use_hls"
/**
* Background mode

View File

@ -1084,16 +1084,6 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
val resolutions = mutableListOf<VideoResolution>()
// append hls to list if available
if (streams.hls != null) {
resolutions.add(
VideoResolution(
name = getString(R.string.hls),
adaptiveSourceUrl = streams.hls!!
)
)
}
val videoStreams = try {
// attempt to sort the qualities, catch if there was an error ih parsing
streams.videoStreams?.sortedBy {
@ -1129,6 +1119,15 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
)
}
}
if (resolutions.isEmpty()) {
return listOf(
VideoResolution(getString(R.string.hls), adaptiveSourceUrl = streams.hls)
)
}
resolutions.add(0, VideoResolution(getString(R.string.auto_quality), Int.MAX_VALUE))
return resolutions
}
@ -1175,13 +1174,21 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
trackSelector.setParameters(params)
}
val manifest = DashHelper.createManifest(streams)
if (!PreferenceHelper.getBoolean(PreferenceKeys.USE_HLS_OVER_DASH, false) &&
streams.videoStreams.orEmpty().isNotEmpty()
) {
val manifest = DashHelper.createManifest(streams)
// encode to base64
val encoded = Base64.encodeToString(manifest.toByteArray(), Base64.DEFAULT)
val mediaItem = "data:application/dash+xml;charset=utf-8;base64,$encoded"
// encode to base64
val encoded = Base64.encodeToString(manifest.toByteArray(), Base64.DEFAULT)
val mediaItem = "data:application/dash+xml;charset=utf-8;base64,$encoded"
this.setMediaSource(mediaItem.toUri(), MimeTypes.APPLICATION_MPD)
this.setMediaSource(mediaItem.toUri(), MimeTypes.APPLICATION_MPD)
} else if (streams.hls != null) {
setMediaSource(streams.hls.toUri(), MimeTypes.APPLICATION_M3U8)
} else {
Toast.makeText(context, R.string.unknown_error, Toast.LENGTH_SHORT).show()
}
}
private fun createExoPlayer() {
@ -1355,24 +1362,16 @@ class PlayerFragment : BaseFragment(), OnlinePlayerOptions {
val resolutions = getAvailableResolutions()
// Dialog for quality selection
val lastPosition = exoPlayer.currentPosition
BaseBottomSheet()
.setSimpleItems(
resolutions.map { it.name }
) { which ->
if (
resolutions[which].adaptiveSourceUrl != null
) {
// set the progressive media source
setMediaSource(resolutions[which].adaptiveSourceUrl!!.toUri(), MimeTypes.APPLICATION_M3U8)
} else {
val resolution = resolutions[which].resolution!!
val params = trackSelector.buildUponParameters()
.setMaxVideoSize(Int.MAX_VALUE, resolution)
.setMinVideoSize(Int.MAX_VALUE, resolution)
trackSelector.setParameters(params)
}
exoPlayer.seekTo(lastPosition)
val resolution = resolutions[which].resolution!!
val params = trackSelector.buildUponParameters()
.setMaxVideoSize(Int.MAX_VALUE, resolution)
.setMinVideoSize(Int.MAX_VALUE, resolution)
trackSelector.setParameters(params)
}
.show(childFragmentManager)
}

View File

@ -188,7 +188,7 @@
</string-array>
<string-array name="defres">
<item>@string/hls</item>
<item>@string/auto_quality</item>
<item>2160p</item>
<item>1440p</item>
<item>1080p</item>

View File

@ -208,7 +208,7 @@
<string name="auth_instance">Authentication instance</string>
<string name="auth_instance_summary">Use a different instance for authenticated calls.</string>
<string name="auth_instances">Choose an auth instance</string>
<string name="hls">Auto</string>
<string name="hls">HLS</string>
<string name="github">GitHub</string>
<string name="audio_video">Audio and video</string>
<string name="fullscreen_orientation">Fullscreen orientation</string>
@ -372,6 +372,9 @@
<string name="alternative_player_layout_summary">Show the related videos as a row above the comments instead of below.</string>
<string name="audio_track">Audio track</string>
<string name="default_audio_track">Default</string>
<string name="hls_instead_of_dash">Use HLS</string>
<string name="hls_instead_of_dash_summary">Use HLS instead of DASH (will be slower, not recommended)</string>
<string name="auto_quality">Auto</string>
<!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string>

View File

@ -46,6 +46,7 @@
</PreferenceCategory>
<PreferenceCategory app:title="@string/quality">
<ListPreference
@ -53,6 +54,7 @@
app:defaultValue="webm"
app:entries="@array/playerVideoFormat"
app:entryValues="@array/playerVideoFormatValues"
app:isPreferenceVisible="false"
app:key="player_video_format"
app:title="@string/playerVideoFormat"
app:useSimpleSummaryProvider="true" />
@ -62,10 +64,18 @@
app:defaultValue="all"
app:entries="@array/playerAudioFormat"
app:entryValues="@array/playerAudioFormatValues"
app:isPreferenceVisible="false"
app:key="player_audio_format"
app:title="@string/playerAudioFormat"
app:useSimpleSummaryProvider="true" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_list"
android:summary="@string/hls_instead_of_dash_summary"
android:title="@string/hls_instead_of_dash"
app:key="use_hls" />
<SwitchPreferenceCompat
android:defaultValue="false"
android:icon="@drawable/ic_play_filled"