Fixed a URL formatting issue that could cause non-downsampled media to

not play on the Android client.
This commit is contained in:
casey langen 2017-12-25 21:21:16 -08:00
parent e9d0461d70
commit 86e18d015a

View File

@ -4,6 +4,7 @@ import android.content.Context
import android.content.SharedPreferences import android.content.SharedPreferences
import android.database.ContentObserver import android.database.ContentObserver
import android.media.AudioManager import android.media.AudioManager
import android.net.Uri
import android.os.Handler import android.os.Handler
import android.os.Looper import android.os.Looper
import android.provider.Settings import android.provider.Settings
@ -510,30 +511,29 @@ class StreamingPlaybackService(context: Context) : IPlaybackService {
if (Strings.notEmpty(externalId)) { if (Strings.notEmpty(externalId)) {
val ssl = prefs.getBoolean(Prefs.Key.SSL_ENABLED, Prefs.Default.SSL_ENABLED) val ssl = prefs.getBoolean(Prefs.Key.SSL_ENABLED, Prefs.Default.SSL_ENABLED)
val protocol = if (ssl) "https" else "http" val protocol = if (ssl) "https" else "http"
val port = prefs.getInt(Prefs.Key.AUDIO_PORT, Prefs.Default.AUDIO_PORT)
val host = prefs.getString(Prefs.Key.ADDRESS, Prefs.Default.ADDRESS)
val remoteUri = Uri.Builder()
.scheme(protocol)
.encodedAuthority("$host:$port")
.appendPath("audio")
.appendPath("external_id")
.appendPath(externalId)
/* transcoding bitrate, if selected by the user */ /* transcoding bitrate, if selected by the user */
var bitrateQueryParam = ""
val bitrateIndex = prefs.getInt( val bitrateIndex = prefs.getInt(
Prefs.Key.TRANSCODER_BITRATE_INDEX, Prefs.Key.TRANSCODER_BITRATE_INDEX,
Prefs.Default.TRANSCODER_BITRATE_INDEX) Prefs.Default.TRANSCODER_BITRATE_INDEX)
if (bitrateIndex > 0) { if (bitrateIndex > 0) {
val r = Application.instance!!.resources val r = Application.instance!!.resources
val bitrate = r.getStringArray(R.array.transcode_bitrate_array)[bitrateIndex]
bitrateQueryParam = String.format( remoteUri.appendQueryParameter("bitrate", bitrate)
Locale.ENGLISH,
"?bitrate=%s",
r.getStringArray(R.array.transcode_bitrate_array)[bitrateIndex])
} }
return String.format( remoteUri.appendQueryParameter("format", "mp3");
Locale.ENGLISH, return remoteUri.build().toString()
"%s://%s:%d/audio/external_id/%s%s&format=mp3",
protocol,
prefs.getString(Prefs.Key.ADDRESS, Prefs.Default.ADDRESS),
prefs.getInt(Prefs.Key.AUDIO_PORT, Prefs.Default.AUDIO_PORT),
URLEncoder.encode(externalId),
bitrateQueryParam)
} }
} }
return null return null