add loading interval size option

This commit is contained in:
Bnyro 2022-10-01 10:52:06 +02:00
parent ca86cb1768
commit dc5a7d02d0
5 changed files with 53 additions and 5 deletions

View File

@ -78,6 +78,7 @@ object PreferenceKeys {
const val PLAYER_RESIZE_MODE = "player_resize_mode"
const val SB_SKIP_MANUALLY = "sb_skip_manually_key"
const val LIMIT_HLS = "limit_hls"
const val PROGRESSIVE_LOADING_INTERVAL_SIZE = "progressive_loading_interval"
/**
* Background mode

View File

@ -167,6 +167,7 @@ class PlayerFragment : BaseFragment() {
private var skipButtonsEnabled = false
private var pipEnabled = true
private var skipSegmentsManually = false
private var progressiveLoadingIntervalSize = "64"
/**
* for autoplay
@ -339,6 +340,11 @@ class PlayerFragment : BaseFragment() {
PreferenceKeys.SB_SKIP_MANUALLY,
false
)
progressiveLoadingIntervalSize = PreferenceHelper.getString(
PreferenceKeys.PROGRESSIVE_LOADING_INTERVAL_SIZE,
"64"
)
}
@SuppressLint("ClickableViewAccessibility")
@ -467,7 +473,7 @@ class PlayerFragment : BaseFragment() {
videosNameArray[which] == "LBRY HLS"
) {
// set the progressive media source
setProgressiveMediaSource(videosUrlArray[which])
setHLSMediaSource(videosUrlArray[which])
} else {
val videoUri = videosUrlArray[which]
val audioUrl =
@ -1211,24 +1217,35 @@ class PlayerFragment : BaseFragment() {
videoUri: Uri,
audioUrl: String
) {
val checkIntervalSize = when (progressiveLoadingIntervalSize) {
"default" -> ProgressiveMediaSource.DEFAULT_LOADING_CHECK_INTERVAL_BYTES
else -> progressiveLoadingIntervalSize.toInt() * 1024
}
val dataSourceFactory: DataSource.Factory =
DefaultHttpDataSource.Factory()
val videoItem: MediaItem = MediaItem.Builder()
.setUri(videoUri)
.setSubtitleConfigurations(subtitle)
.build()
val videoSource: MediaSource =
DefaultMediaSourceFactory(dataSourceFactory)
ProgressiveMediaSource.Factory(dataSourceFactory)
.setContinueLoadingCheckIntervalBytes(checkIntervalSize)
.createMediaSource(videoItem)
val audioSource: MediaSource =
ProgressiveMediaSource.Factory(dataSourceFactory)
.setContinueLoadingCheckIntervalBytes(checkIntervalSize)
.createMediaSource(fromUri(audioUrl))
val mergeSource: MediaSource =
MergingMediaSource(videoSource, audioSource)
exoPlayer.setMediaSource(mergeSource)
}
private fun setProgressiveMediaSource(uri: Uri) {
private fun setHLSMediaSource(uri: Uri) {
val mediaItem: MediaItem = MediaItem.Builder()
.setUri(uri)
.setSubtitleConfigurations(subtitle)
@ -1317,7 +1334,7 @@ class PlayerFragment : BaseFragment() {
// if default resolution isn't set or available, use hls if available
if (streams.hls != null) {
setProgressiveMediaSource(Uri.parse(streams.hls))
setHLSMediaSource(Uri.parse(streams.hls))
return
}

View File

@ -408,4 +408,22 @@
<item>512</item>
</string-array>
<string-array name="loadingInterval">
<item>1KiB</item>
<item>16KiB</item>
<item>64KiB</item>
<item>128KiB</item>
<item>256KiB</item>
<item>@string/default_load_interval</item>
</string-array>
<string-array name="loadingIntervalValues">
<item>1</item>
<item>16</item>
<item>64</item>
<item>128</item>
<item>256</item>
<item>default</item>
</string-array>
</resources>

View File

@ -334,6 +334,9 @@
<string name="select_at_least_one">Please select at least one item</string>
<string name="change_region">Trending seems to be unavailable for the current region. Please select another in the settings.</string>
<string name="limit_hls">Limit HLS to 1080p</string>
<string name="progressive_load_interval">Progressive load interval size</string>
<string name="progressive_load_interval_summary">A lower value may speed up initial video loading.</string>
<string name="default_load_interval">Default</string>
<!-- Notification channel strings -->
<string name="download_channel_name">Download Service</string>

View File

@ -72,6 +72,15 @@
android:title="@string/limit_hls"
app:key="limit_hls" />
<ListPreference
android:icon="@drawable/ic_loading"
app:defaultValue="64"
app:entries="@array/loadingInterval"
app:entryValues="@array/loadingIntervalValues"
app:key="progressive_loading_interval"
app:summary="@string/progressive_load_interval_summary"
app:title="@string/progressive_load_interval" />
</PreferenceCategory>
<PreferenceCategory app:title="@string/background_mode">