fix(android): revert x-rincon-mp3radio Sonos URI -- plain https for music tracks
android / Build + lint + test (push) Successful in 4m13s

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
2026-06-03 21:31:31 -04:00
parent 487d1bd430
commit 8a1203c4a1
3 changed files with 6 additions and 57 deletions
@@ -12,7 +12,6 @@ import okhttp3.HttpUrl
class AVTransportClient(
private val soap: SoapClient,
private val controlUrl: HttpUrl,
private val applySonosUriFix: Boolean = false,
) {
suspend fun setAVTransportURI(uri: String, metadata: String = "") {
soap.call(
@@ -45,8 +44,7 @@ class AVTransportClient(
*/
suspend fun setAVTransportURIWithMetadata(uri: String, mime: String, title: String) {
val safeTitle = title.ifBlank { "Minstrel" }
val effectiveUri = maybeTransformForSonos(uri)
setAVTransportURI(effectiveUri, buildDidlLite(effectiveUri, mime, safeTitle))
setAVTransportURI(uri, buildDidlLite(uri, mime, safeTitle))
}
/**
@@ -56,15 +54,14 @@ class AVTransportClient(
*/
suspend fun setNextAVTransportURI(uri: String, mime: String, title: String) {
val safeTitle = title.ifBlank { "Minstrel" }
val effectiveUri = maybeTransformForSonos(uri)
soap.call(
controlUrl = controlUrl,
serviceType = SERVICE_TYPE,
action = "SetNextAVTransportURI",
args = mapOf(
"InstanceID" to "0",
"NextURI" to effectiveUri,
"NextURIMetaData" to buildDidlLite(effectiveUri, mime, safeTitle),
"NextURI" to uri,
"NextURIMetaData" to buildDidlLite(uri, mime, safeTitle),
),
)
}
@@ -140,24 +137,6 @@ class AVTransportClient(
return TransportInfo(state)
}
/**
* Sonos firmware 6.4.2+ silently refuses plain http(s):// URIs in
* SetAVTransportURI -- the SOAP call returns 200 OK but the URI never
* loads. The documented fix (from SoCo et al.) is to replace the
* scheme with x-rincon-mp3radio:// for Sonos targets. Generic UPnP
* renderers (Yamaha, Bose, generic DLNA) reject this scheme, so the
* transform is conditional on the manufacturer.
*
* The transformed URI goes both in the SOAP CurrentURI / NextURI arg
* AND inside the DIDL-Lite `<res>` element so the two stay consistent.
*/
private fun maybeTransformForSonos(uri: String): String {
if (!applySonosUriFix) return uri
return uri
.replaceFirst("https://", "x-rincon-mp3radio://")
.replaceFirst("http://", "x-rincon-mp3radio://")
}
private fun buildDidlLite(uri: String, mime: String, title: String): String {
val safeTitle = title.ifBlank { "Minstrel" }
return buildString {
@@ -90,11 +90,9 @@ class UpnpDiscoveryController @Inject constructor(
*/
fun transportFor(routeId: String): AVTransportClient? {
val route = routesInternal.value.firstOrNull { it.id == routeId } ?: return null
val isSonos = route.manufacturer.contains("Sonos", ignoreCase = true)
return AVTransportClient(
loggingSoapClient(okHttp, route.name),
route.avTransportControlUrl,
applySonosUriFix = isSonos,
)
}