feat: choice of codec in network settings / bugfix: nullsafe fix

This commit is contained in:
nomadics9 2024-07-21 00:42:35 +03:00
parent 21ae815223
commit 8482df9733
7 changed files with 25 additions and 6 deletions

View file

@ -353,14 +353,14 @@ class PlayerActivity : BasePlayerActivity() {
private var selectedIndex = 1 // Default to "Original" (index 1)
private fun showQualitySelectionDialog() {
val originalResolution = viewModel.getoriginalResolution() // TODO: Rework getting originalResolution
val originalResolution = viewModel.getoriginalResolution() ?: 0// TODO: Rework getting originalResolution
val qualityEntries = resources.getStringArray(CoreR.array.quality_entries).toList()
val qualityValues = resources.getStringArray(CoreR.array.quality_values).toList()
val qualities = qualityEntries.toMutableList()
val closestQuality = VideoQuality.entries
.filter { it != VideoQuality.Auto && it != VideoQuality.Original }
.minByOrNull { kotlin.math.abs(it.height*it.width - originalResolution!!) }
.minByOrNull { kotlin.math.abs(it.height*it.width - originalResolution) }
if (closestQuality != null) {
qualities[1] = "${qualities[1]} (${closestQuality})"

View file

@ -55,4 +55,8 @@
<item>480p</item>
<item>360p</item>
</string-array>
<string-array name="codecs">
<item>h264</item>
<item>hevc</item>
</string-array>
</resources>

View file

@ -139,6 +139,7 @@
<string name="settings_request_timeout">Request timeout (ms)</string>
<string name="settings_connect_timeout">Connect timeout (ms)</string>
<string name="settings_socket_timeout">Socket timeout (ms)</string>
<string name="settings_quality_codec">Transcoding Codec</string>
<string name="users">Users</string>
<string name="add_user">Add user</string>
<string name="pref_player_mpv_hwdec">Hardware decoding</string>

View file

@ -15,4 +15,11 @@
app:key="pref_network_socket_timeout"
app:title="@string/settings_socket_timeout"
app:useSimpleSummaryProvider="true" />
<ListPreference
app:defaultValue="h264"
app:key="pref_network_codec"
app:title="@string/settings_quality_codec"
app:useSimpleSummaryProvider="true"
app:entries="@array/codecs"
app:entryValues="@array/codecs" />
</PreferenceScreen>

View file

@ -641,7 +641,7 @@ class JellyfinRepositoryImpl(
context = context,
protocol = MediaStreamProtocol.HLS,
audioCodec = "aac",
videoCodec = "h264",
videoCodec = appPreferences.transcodeCodec!!,
type = DlnaProfileType.VIDEO,
conditions =
listOf(
@ -715,7 +715,7 @@ class JellyfinRepositoryImpl(
playSessionId = playSessionId,
videoBitRate = videoBitrate,
audioBitRate = 128000,
videoCodec = "h264",
videoCodec = appPreferences.transcodeCodec,
audioCodec = "aac",
container = container,
maxHeight = maxHeight,
@ -745,7 +745,7 @@ class JellyfinRepositoryImpl(
videoBitRate = videoBitrate,
enableAdaptiveBitrateStreaming = false,
audioBitRate = 128000,
videoCodec = "h264",
videoCodec = appPreferences.transcodeCodec,
audioCodec = "aac",
startTimeTicks = 0,
copyTimestamps = true,
@ -762,7 +762,7 @@ class JellyfinRepositoryImpl(
mediaSourceId = mediaSourceId,
playSessionId = playSessionId,
enableAdaptiveBitrateStreaming = true,
videoCodec = "h264",
videoCodec = appPreferences.transcodeCodec,
audioCodec = "aac",
startTimeTicks = 0,
copyTimestamps = true,

View file

@ -103,6 +103,11 @@ constructor(
Constants.NETWORK_DEFAULT_SOCKET_TIMEOUT.toString(),
)!!.toLongOrNull() ?: Constants.NETWORK_DEFAULT_SOCKET_TIMEOUT
val transcodeCodec get() = sharedPreferences.getString(
Constants.PREF_NETWORK_CODEC,
Constants.NETWORK_DEFAULT_CODEC,
)
// Cache
val imageCache get() = sharedPreferences.getBoolean(
Constants.PREF_IMAGE_CACHE,

View file

@ -40,6 +40,7 @@ object Constants {
const val PREF_NETWORK_REQUEST_TIMEOUT = "pref_network_request_timeout"
const val PREF_NETWORK_CONNECT_TIMEOUT = "pref_network_connect_timeout"
const val PREF_NETWORK_SOCKET_TIMEOUT = "pref_network_socket_timeout"
const val PREF_NETWORK_CODEC = "pref_network_codec"
const val PREF_DOWNLOADS_MOBILE_DATA = "pref_downloads_mobile_data"
const val PREF_DOWNLOADS_ROAMING = "pref_downloads_roaming"
const val PREF_DOWNLOADS_QUALITY = "pref_downloads_quality"
@ -60,6 +61,7 @@ object Constants {
const val NETWORK_DEFAULT_REQUEST_TIMEOUT = 30_000L
const val NETWORK_DEFAULT_CONNECT_TIMEOUT = 6_000L
const val NETWORK_DEFAULT_SOCKET_TIMEOUT = 10_000L
const val NETWORK_DEFAULT_CODEC = "h264"
// sorting
// This values must correspond to a SortString from [SortBy]