Allow for transcoder format selection in musikdroid settings screen.

This commit is contained in:
casey langen 2019-12-31 16:46:31 -08:00
parent 64636cdce4
commit 1838ddb772
6 changed files with 72 additions and 24 deletions

View File

@ -526,6 +526,11 @@ class StreamingPlaybackService(context: Context) : IPlaybackService {
val externalId = track.externalId
if (externalId.isNotEmpty()) {
val getUrlParam: (Int, String, Int) -> String = { arrayId, prefKey, defaultIndex ->
val index = prefs.getInt(prefKey, defaultIndex)
Application.instance.resources.getStringArray(arrayId)[index]
}
val ssl = prefs.getBoolean(Prefs.Key.SSL_ENABLED, Prefs.Default.SSL_ENABLED)
val protocol = if (ssl) "https" else "http"
val port = prefs.getInt(Prefs.Key.AUDIO_PORT, Prefs.Default.AUDIO_PORT)
@ -549,7 +554,11 @@ class StreamingPlaybackService(context: Context) : IPlaybackService {
remoteUri.appendQueryParameter("bitrate", bitrate)
}
remoteUri.appendQueryParameter("format", "mp3")
remoteUri.appendQueryParameter("format", getUrlParam(
R.array.transcode_format_array,
Prefs.Key.TRANSCODER_FORMAT_INDEX,
Prefs.Default.TRANSCODER_FORMAT_INDEX))
return remoteUri.build().toString()
}
}

View File

@ -44,6 +44,7 @@ class SettingsActivity : BaseActivity() {
private lateinit var certCheckbox: CheckBox
private lateinit var transferCheckbox: CheckBox
private lateinit var bitrateSpinner: Spinner
private lateinit var formatSpinner: Spinner
private lateinit var cacheSpinner: Spinner
private lateinit var titleEllipsisSpinner: Spinner
private lateinit var playback: PlaybackMixin
@ -105,6 +106,13 @@ class SettingsActivity : BaseActivity() {
override val transitionType: Transition
get() = Transition.Vertical
private fun rebindSpinner(spinner: Spinner, arrayResourceId: Int, key: String, defaultIndex: Int) {
val items = ArrayAdapter.createFromResource(this, arrayResourceId, android.R.layout.simple_spinner_item)
items.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
spinner.adapter = items
spinner.setSelection(prefs.getInt(key, defaultIndex))
}
private fun rebindUi() {
/* connection info */
addressText.setTextAndMoveCursorToEnd(prefs.getString(Keys.ADDRESS) ?: Defaults.ADDRESS)
@ -118,33 +126,32 @@ class SettingsActivity : BaseActivity() {
passwordText.setTextAndMoveCursorToEnd(prefs.getString(Keys.PASSWORD) ?: Defaults.PASSWORD)
/* bitrate */
val bitrates = ArrayAdapter.createFromResource(
this, R.array.transcode_bitrate_array, android.R.layout.simple_spinner_item)
rebindSpinner(
bitrateSpinner,
R.array.transcode_bitrate_array,
Keys.TRANSCODER_BITRATE_INDEX,
Defaults.TRANSCODER_BITRATE_INDEX)
bitrates.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
bitrateSpinner.adapter = bitrates
bitrateSpinner.setSelection(prefs.getInt(
Keys.TRANSCODER_BITRATE_INDEX, Defaults.TRANSCODER_BITRATE_INDEX))
/* format */
rebindSpinner(
formatSpinner,
R.array.transcode_format_array,
Keys.TRANSCODER_FORMAT_INDEX,
Defaults.TRANSCODER_FORMAT_INDEX)
/* disk cache */
val cacheSizes = ArrayAdapter.createFromResource(
this, R.array.disk_cache_array, android.R.layout.simple_spinner_item)
cacheSizes.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
cacheSpinner.adapter = cacheSizes
cacheSpinner.setSelection(prefs.getInt(
Keys.DISK_CACHE_SIZE_INDEX, Defaults.DISK_CACHE_SIZE_INDEX))
rebindSpinner(
cacheSpinner,
R.array.disk_cache_array,
Keys.DISK_CACHE_SIZE_INDEX,
Defaults.DISK_CACHE_SIZE_INDEX)
/* title ellipsis mode */
val ellipsisModes = ArrayAdapter.createFromResource(
this, R.array.title_ellipsis_mode_array, android.R.layout.simple_spinner_item)
ellipsisModes.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
titleEllipsisSpinner.adapter = ellipsisModes
titleEllipsisSpinner.setSelection(prefs.getInt(
Keys.TITLE_ELLIPSIS_MODE_INDEX, Defaults.TITLE_ELLIPSIS_SIZE_INDEX))
rebindSpinner(
titleEllipsisSpinner,
R.array.title_ellipsis_mode_array,
Keys.TITLE_ELLIPSIS_MODE_INDEX,
Defaults.TITLE_ELLIPSIS_SIZE_INDEX)
/* advanced */
transferCheckbox.isChecked = prefs.getBoolean(
@ -203,6 +210,7 @@ class SettingsActivity : BaseActivity() {
this.albumArtCheckbox = findViewById(R.id.album_art_checkbox)
this.softwareVolume = findViewById(R.id.software_volume)
this.bitrateSpinner = findViewById(R.id.transcoder_bitrate_spinner)
this.formatSpinner = findViewById(R.id.transcoder_format_spinner)
this.cacheSpinner = findViewById(R.id.streaming_disk_cache_spinner)
this.titleEllipsisSpinner = findViewById(R.id.title_ellipsis_mode_spinner)
this.sslCheckbox = findViewById(R.id.ssl_checkbox)
@ -279,6 +287,7 @@ class SettingsActivity : BaseActivity() {
.putBoolean(Keys.CERT_VALIDATION_DISABLED, certCheckbox.isChecked)
.putBoolean(Keys.TRANSFER_TO_SERVER_ON_HEADSET_DISCONNECT, transferCheckbox.isChecked)
.putInt(Keys.TRANSCODER_BITRATE_INDEX, bitrateSpinner.selectedItemPosition)
.putInt(Keys.TRANSCODER_FORMAT_INDEX, formatSpinner.selectedItemPosition)
.putInt(Keys.DISK_CACHE_SIZE_INDEX, cacheSpinner.selectedItemPosition)
.putInt(Keys.TITLE_ELLIPSIS_MODE_INDEX, titleEllipsisSpinner.selectedItemPosition)
.apply()

View File

@ -12,6 +12,7 @@ class Prefs {
const val SSL_ENABLED = "ssl_enabled"
const val CERT_VALIDATION_DISABLED = "cert_validation_disabled"
const val TRANSCODER_BITRATE_INDEX = "transcoder_bitrate_index"
const val TRANSCODER_FORMAT_INDEX = "transcoder_format_index"
const val DISK_CACHE_SIZE_INDEX = "disk_cache_size_index"
const val TITLE_ELLIPSIS_MODE_INDEX = "title_ellipsis_mode_index"
const val UPDATE_DIALOG_SUPPRESSED_VERSION = "update_dialog_suppressed_version"
@ -30,6 +31,7 @@ class Prefs {
const val SSL_ENABLED = false
const val CERT_VALIDATION_DISABLED = false
const val TRANSCODER_BITRATE_INDEX = 0
const val TRANSCODER_FORMAT_INDEX = 0
const val TRANSFER_TO_SERVER_ON_HEADSET_DISCONNECT = false
const val DISK_CACHE_SIZE_INDEX = 2
const val TITLE_ELLIPSIS_SIZE_INDEX = 1

View File

@ -151,6 +151,23 @@
android:layout_width="0dp"
android:layout_height="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginRight="8dp"
android:text="@string/settings_transcoder_format"/>
<Spinner
android:id="@+id/transcoder_format_spinner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="24dp"/>
<View
android:layout_width="0dp"
android:layout_height="16dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"

View File

@ -98,7 +98,8 @@
<string name="main_switch_to_streaming_title">switch to streaming mode?</string>
<string name="main_switch_to_streaming_message">playing offline tracks requires you to switch from remote mode to streaming mode.\n\ndo you want to switch now?</string>
<string name="settings_playback_mode">playback mode:</string>
<string name="settings_transcoder_bitrate">streaming downsampler bitrate:</string>
<string name="settings_transcoder_bitrate">streaming transcoder bitrate:</string>
<string name="settings_transcoder_format">streaming transcoder format:</string>
<string name="settings_cache_size">streaming disk cache size:</string>
<string name="settings_advanced">advanced:</string>
<string name="settings_use_ssl">use ssl for server connections</string>

View File

@ -0,0 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="transcode_format_array">
<item>mp3</item>
<item>opus</item>
<item>ogg</item>
<item>flac</item>
<item>aac</item>
</string-array>
</resources>