react-native-audio-browser 0.2.0-next.50 → 0.2.0-next.52
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/android/build.gradle +15 -0
- package/android/src/cast/java/com/audiobrowser/cast/CastSupport.kt +215 -0
- package/android/src/main/AndroidManifest.xml +11 -0
- package/android/src/main/java/com/audiobrowser/AudioBrowser.kt +0 -4
- package/android/src/main/java/com/audiobrowser/RemoteOutputs.kt +47 -10
- package/android/src/main/java/com/audiobrowser/model/PlayerSetupOptions.kt +12 -3
- package/android/src/main/java/com/audiobrowser/player/EqualizerController.kt +4 -1
- package/android/src/main/java/com/audiobrowser/player/LocalEngine.kt +49 -0
- package/android/src/main/java/com/audiobrowser/player/Player.kt +170 -119
- package/android/src/main/java/com/audiobrowser/player/PlayerListener.kt +18 -13
- package/android/src/main/java/com/audiobrowser/player/TransformingDataSource.kt +10 -13
- package/android/src/main/java/com/audiobrowser/remote/RemoteItem.kt +64 -0
- package/android/src/main/java/com/audiobrowser/remote/RemoteOutputsController.kt +98 -0
- package/android/src/main/java/com/audiobrowser/remote/RemotePlayback.kt +42 -0
- package/android/src/main/java/com/audiobrowser/remote/RemoteQueue.kt +110 -0
- package/android/src/main/java/com/audiobrowser/remote/RemoteSwitchingPlayer.kt +696 -0
- package/android/src/main/java/com/audiobrowser/sonos/DeviceDescriptionParser.kt +113 -0
- package/android/src/main/java/com/audiobrowser/sonos/DidlLite.kt +39 -0
- package/android/src/main/java/com/audiobrowser/sonos/SoapClient.kt +59 -0
- package/android/src/main/java/com/audiobrowser/sonos/SoapEnvelopes.kt +92 -0
- package/android/src/main/java/com/audiobrowser/sonos/SoapResponseParser.kt +105 -0
- package/android/src/main/java/com/audiobrowser/sonos/SonosDiscoverer.kt +69 -0
- package/android/src/main/java/com/audiobrowser/sonos/SonosOutputs.kt +128 -0
- package/android/src/main/java/com/audiobrowser/sonos/SonosPlayer.kt +550 -0
- package/android/src/main/java/com/audiobrowser/sonos/SonosRemote.kt +99 -0
- package/android/src/main/java/com/audiobrowser/sonos/SonosRouteProviderService.kt +201 -0
- package/android/src/main/java/com/audiobrowser/sonos/SonosStreamUri.kt +15 -0
- package/android/src/main/java/com/audiobrowser/sonos/SonosTransport.kt +66 -0
- package/android/src/main/java/com/audiobrowser/sonos/SpeakerXml.kt +26 -0
- package/android/src/main/java/com/audiobrowser/sonos/SsdpDiscovery.kt +63 -0
- package/android/src/main/java/com/audiobrowser/sonos/SsdpMessages.kt +63 -0
- package/android/src/main/java/com/audiobrowser/sonos/ZoneGroupState.kt +68 -0
- package/android/src/main/java/com/audiobrowser/util/OutputMonitor.kt +2 -1
- package/android/src/main/java/com/audiobrowser/util/TrackFactory.kt +1 -1
- package/android/src/nocast/java/com/audiobrowser/cast/CastSupport.kt +18 -0
- package/android/src/test/java/com/audiobrowser/RemoteOutputsTest.kt +20 -3
- package/android/src/test/java/com/audiobrowser/model/PlayerSetupOptionsTest.kt +35 -0
- package/android/src/test/java/com/audiobrowser/player/EqualizerControllerTest.kt +12 -0
- package/android/src/test/java/com/audiobrowser/player/PlayerCastTest.kt +136 -0
- package/android/src/test/java/com/audiobrowser/player/PlayerSonosTest.kt +213 -0
- package/android/src/test/java/com/audiobrowser/remote/FakeRemote.kt +275 -0
- package/android/src/test/java/com/audiobrowser/remote/RemoteItemTest.kt +61 -0
- package/android/src/test/java/com/audiobrowser/remote/RemoteOutputsControllerTest.kt +77 -0
- package/android/src/test/java/com/audiobrowser/remote/RemoteQueueTest.kt +101 -0
- package/android/src/test/java/com/audiobrowser/remote/RemoteSwitchingPlayerTest.kt +815 -0
- package/android/src/test/java/com/audiobrowser/sonos/DeviceDescriptionParserTest.kt +203 -0
- package/android/src/test/java/com/audiobrowser/sonos/DidlLiteTest.kt +90 -0
- package/android/src/test/java/com/audiobrowser/sonos/SoapClientTest.kt +73 -0
- package/android/src/test/java/com/audiobrowser/sonos/SoapEnvelopesTest.kt +135 -0
- package/android/src/test/java/com/audiobrowser/sonos/SoapResponseParserTest.kt +170 -0
- package/android/src/test/java/com/audiobrowser/sonos/SonosDiscovererTest.kt +174 -0
- package/android/src/test/java/com/audiobrowser/sonos/SonosPlayerTest.kt +691 -0
- package/android/src/test/java/com/audiobrowser/sonos/SonosRemoteTest.kt +129 -0
- package/android/src/test/java/com/audiobrowser/sonos/SonosRoutesTest.kt +165 -0
- package/android/src/test/java/com/audiobrowser/sonos/SonosStreamUriTest.kt +64 -0
- package/android/src/test/java/com/audiobrowser/sonos/SonosTransportTest.kt +204 -0
- package/android/src/test/java/com/audiobrowser/sonos/SsdpMessagesTest.kt +99 -0
- package/android/src/test/java/com/audiobrowser/sonos/ZoneGroupStateTest.kt +139 -0
- package/android/src/test/java/com/audiobrowser/util/OutputMonitorTest.kt +12 -10
- package/android/src/test/resources/sonos/device_description.xml +78 -0
- package/android/src/testCast/java/com/audiobrowser/cast/CastEndsTest.kt +56 -0
- package/android/src/testCast/java/com/audiobrowser/cast/SendingMediaItemConverterTest.kt +79 -0
- package/lib/commonjs/features/player/setup.js +2 -0
- package/lib/commonjs/features/player/setup.js.map +1 -1
- package/lib/module/features/player/setup.js +2 -0
- package/lib/module/features/player/setup.js.map +1 -1
- package/lib/typescript/src/features/player/setup.d.ts +37 -7
- package/lib/typescript/src/features/player/setup.d.ts.map +1 -1
- package/lib/typescript/src/specs/audio-browser.nitro.d.ts +3 -3
- package/lib/typescript/src/specs/audio-browser.nitro.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JHybridAudioBrowserSpec.cpp +4 -0
- package/nitrogen/generated/android/c++/JNativeSetupPlayerOptions.hpp +7 -5
- package/nitrogen/generated/android/c++/JOutputType.hpp +3 -0
- package/nitrogen/generated/android/c++/JRemoteOutputsOptions.hpp +66 -0
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/audiobrowser/NativeSetupPlayerOptions.kt +3 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/audiobrowser/OutputType.kt +3 -2
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/audiobrowser/RemoteOutputsOptions.kt +61 -0
- package/nitrogen/generated/ios/AudioBrowser-Swift-Cxx-Bridge.hpp +18 -0
- package/nitrogen/generated/ios/AudioBrowser-Swift-Cxx-Umbrella.hpp +3 -0
- package/nitrogen/generated/ios/c++/HybridAudioBrowserSpecSwift.hpp +3 -0
- package/nitrogen/generated/ios/swift/NativeSetupPlayerOptions.swift +5 -12
- package/nitrogen/generated/ios/swift/OutputType.swift +4 -0
- package/nitrogen/generated/ios/swift/RemoteOutputsOptions.swift +78 -0
- package/nitrogen/generated/shared/c++/NativeSetupPlayerOptions.hpp +8 -5
- package/nitrogen/generated/shared/c++/OutputType.hpp +6 -2
- package/nitrogen/generated/shared/c++/RemoteOutputsOptions.hpp +92 -0
- package/package.json +3 -2
- package/src/features/player/setup.ts +38 -7
- package/src/specs/audio-browser.nitro.ts +4 -3
- package/website/guide/audio-output.md +185 -4
- package/website/guide/configuration.md +6 -0
package/android/build.gradle
CHANGED
|
@@ -56,6 +56,11 @@ def getExtOrIntegerDefault(name) {
|
|
|
56
56
|
|
|
57
57
|
def kotlin_version = getExtOrDefault("kotlinVersion") ?: "1.9.0"
|
|
58
58
|
|
|
59
|
+
// Google Cast is opt-in at build time (AudioBrowser_castEnabled=true in the app's
|
|
60
|
+
// gradle.properties, or rootProject.ext.castEnabled), so apps that don't cast don't ship
|
|
61
|
+
// Play Services' Cast framework.
|
|
62
|
+
def castEnabled = (getExtOrDefault("castEnabled") ?: "false").toString().toBoolean()
|
|
63
|
+
|
|
59
64
|
android {
|
|
60
65
|
namespace "com.audiobrowser"
|
|
61
66
|
|
|
@@ -144,6 +149,7 @@ android {
|
|
|
144
149
|
|
|
145
150
|
sourceSets {
|
|
146
151
|
main {
|
|
152
|
+
java.srcDirs += [castEnabled ? "src/cast/java" : "src/nocast/java"]
|
|
147
153
|
if (isNewArchitectureEnabled()) {
|
|
148
154
|
java.srcDirs += [
|
|
149
155
|
// React Codegen files
|
|
@@ -151,6 +157,9 @@ android {
|
|
|
151
157
|
]
|
|
152
158
|
}
|
|
153
159
|
}
|
|
160
|
+
test {
|
|
161
|
+
if (castEnabled) java.srcDirs += ["src/testCast/java"]
|
|
162
|
+
}
|
|
154
163
|
}
|
|
155
164
|
}
|
|
156
165
|
|
|
@@ -202,6 +211,10 @@ dependencies {
|
|
|
202
211
|
implementation("androidx.media3:media3-exoplayer-smoothstreaming:${media3Version}")
|
|
203
212
|
implementation("androidx.media3:media3-common:${media3Version}")
|
|
204
213
|
implementation("androidx.media3:media3-datasource-okhttp:${media3Version}")
|
|
214
|
+
if (castEnabled) {
|
|
215
|
+
implementation("androidx.media3:media3-cast:${media3Version}")
|
|
216
|
+
implementation("com.google.android.gms:play-services-cast-framework:22.3.1")
|
|
217
|
+
}
|
|
205
218
|
|
|
206
219
|
implementation "com.google.guava:guava:33.0.0-android"
|
|
207
220
|
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-guava:1.8.0"
|
|
@@ -230,6 +243,8 @@ dependencies {
|
|
|
230
243
|
mockitoAgent "org.mockito:mockito-core:${mockitoVersion}"
|
|
231
244
|
testImplementation 'org.jetbrains.kotlinx:kotlinx-coroutines-test:1.7.3'
|
|
232
245
|
testImplementation 'org.robolectric:robolectric:4.11.1'
|
|
246
|
+
// Stands in for a Sonos speaker in the UPnP round-trip tests.
|
|
247
|
+
testImplementation 'com.squareup.okhttp3:mockwebserver'
|
|
233
248
|
|
|
234
249
|
api 'com.jakewharton.timber:timber:5.0.1'
|
|
235
250
|
}
|
|
@@ -0,0 +1,215 @@
|
|
|
1
|
+
package com.audiobrowser.cast
|
|
2
|
+
|
|
3
|
+
import android.content.Context
|
|
4
|
+
import androidx.media3.cast.Cast
|
|
5
|
+
import androidx.media3.cast.CastParams
|
|
6
|
+
import androidx.media3.cast.DefaultMediaItemConverter
|
|
7
|
+
import androidx.media3.cast.MediaItemConverter
|
|
8
|
+
import androidx.media3.cast.RemoteCastPlayer
|
|
9
|
+
import androidx.media3.cast.SessionAvailabilityListener
|
|
10
|
+
import androidx.media3.common.MediaItem
|
|
11
|
+
import androidx.media3.common.PlaybackException
|
|
12
|
+
import com.audiobrowser.remote.RemotePlayback
|
|
13
|
+
import com.google.android.gms.cast.CastMediaControlIntent
|
|
14
|
+
import com.google.android.gms.cast.MediaQueueItem
|
|
15
|
+
import com.google.android.gms.cast.MediaStatus
|
|
16
|
+
import com.google.android.gms.cast.framework.CastSession
|
|
17
|
+
import com.google.android.gms.cast.framework.SessionManagerListener
|
|
18
|
+
import com.google.android.gms.cast.framework.media.RemoteMediaClient
|
|
19
|
+
import com.google.android.gms.common.ConnectionResult
|
|
20
|
+
import com.google.android.gms.common.GoogleApiAvailability
|
|
21
|
+
import timber.log.Timber
|
|
22
|
+
|
|
23
|
+
/** [receiverApplicationId], or the Default Media Receiver's when null. */
|
|
24
|
+
private fun receiverOrDefault(receiverApplicationId: String?) =
|
|
25
|
+
receiverApplicationId ?: CastMediaControlIntent.DEFAULT_MEDIA_RECEIVER_APPLICATION_ID
|
|
26
|
+
|
|
27
|
+
// Cast takes its receiver once per process.
|
|
28
|
+
private var initializedReceiver: String? = null
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* The MediaRouter control category of the routes that can run the receiver: the one Cast started
|
|
32
|
+
* with, else [receiverApplicationId].
|
|
33
|
+
*/
|
|
34
|
+
internal fun castRouteCategory(receiverApplicationId: String?): String? =
|
|
35
|
+
CastMediaControlIntent.categoryForCast(
|
|
36
|
+
initializedReceiver ?: receiverOrDefault(receiverApplicationId)
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Starts Cast with the receiver application (the Default Media Receiver when null) and builds its
|
|
41
|
+
* remote player, or returns null on a device without Google Play services.
|
|
42
|
+
*/
|
|
43
|
+
internal fun createCastRemote(context: Context, receiverApplicationId: String?): RemotePlayback? {
|
|
44
|
+
val availability = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(context)
|
|
45
|
+
if (availability != ConnectionResult.SUCCESS) {
|
|
46
|
+
Timber.w("Cast: Google Play services unavailable (%d), playing locally only", availability)
|
|
47
|
+
return null
|
|
48
|
+
}
|
|
49
|
+
val receiver = receiverOrDefault(receiverApplicationId)
|
|
50
|
+
val initialized = initializedReceiver
|
|
51
|
+
if (initialized == null) {
|
|
52
|
+
Cast.getSingletonInstance(context)
|
|
53
|
+
.initialize(CastParams.Builder().setReceiverApplicationId(receiver).build())
|
|
54
|
+
initializedReceiver = receiver
|
|
55
|
+
} else if (initialized != receiver) {
|
|
56
|
+
Timber.w("Cast: the receiver %s takes effect after a restart; %s stays", receiver, initialized)
|
|
57
|
+
}
|
|
58
|
+
val player =
|
|
59
|
+
RemoteCastPlayer.Builder(context)
|
|
60
|
+
.setMediaItemConverter(SendingMediaItemConverter())
|
|
61
|
+
.build()
|
|
62
|
+
return SdkCastRemote(Cast.getSingletonInstance(context), player)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
private class SdkCastRemote(private val cast: Cast, override val player: RemoteCastPlayer) :
|
|
66
|
+
RemotePlayback {
|
|
67
|
+
private var listener: RemotePlayback.Listener? = null
|
|
68
|
+
private var client: RemoteMediaClient? = null
|
|
69
|
+
|
|
70
|
+
private val ends = CastEnds()
|
|
71
|
+
|
|
72
|
+
private val statusCallback =
|
|
73
|
+
object : RemoteMediaClient.Callback() {
|
|
74
|
+
override fun onStatusUpdated() {
|
|
75
|
+
val status = client?.mediaStatus ?: return
|
|
76
|
+
if (status.playerState == MediaStatus.PLAYER_STATE_PLAYING) listener?.onPlaying()
|
|
77
|
+
when (ends.report(status.mediaInfo?.contentId, status.playerState, status.idleReason)) {
|
|
78
|
+
CastEnds.Report.ENDED -> listener?.onEnded()
|
|
79
|
+
CastEnds.Report.FAILED ->
|
|
80
|
+
listener?.onFailed(
|
|
81
|
+
PlaybackException(
|
|
82
|
+
"The Cast receiver failed to play the media",
|
|
83
|
+
null,
|
|
84
|
+
PlaybackException.ERROR_CODE_REMOTE_ERROR,
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
null -> Unit
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
private val sessions =
|
|
93
|
+
object : SessionManagerListener<CastSession> {
|
|
94
|
+
override fun onSessionStarted(session: CastSession, sessionId: String) = watch(session)
|
|
95
|
+
|
|
96
|
+
override fun onSessionResumed(session: CastSession, wasSuspended: Boolean) = watch(session)
|
|
97
|
+
|
|
98
|
+
override fun onSessionEnded(session: CastSession, error: Int) = watch(null)
|
|
99
|
+
|
|
100
|
+
override fun onSessionStarting(session: CastSession) = Unit
|
|
101
|
+
|
|
102
|
+
override fun onSessionStartFailed(session: CastSession, error: Int) = Unit
|
|
103
|
+
|
|
104
|
+
override fun onSessionEnding(session: CastSession) = Unit
|
|
105
|
+
|
|
106
|
+
override fun onSessionResuming(session: CastSession, sessionId: String) = Unit
|
|
107
|
+
|
|
108
|
+
override fun onSessionResumeFailed(session: CastSession, error: Int) = Unit
|
|
109
|
+
|
|
110
|
+
override fun onSessionSuspended(session: CastSession, reason: Int) = Unit
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
init {
|
|
114
|
+
cast.addSessionManagerListener(sessions)
|
|
115
|
+
watch(cast.currentCastSession)
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
private fun watch(session: CastSession?) {
|
|
119
|
+
ends.reset()
|
|
120
|
+
client?.unregisterCallback(statusCallback)
|
|
121
|
+
client = session?.remoteMediaClient
|
|
122
|
+
client?.registerCallback(statusCallback)
|
|
123
|
+
}
|
|
124
|
+
override val isSessionAvailable: Boolean
|
|
125
|
+
get() = player.isCastSessionAvailable
|
|
126
|
+
|
|
127
|
+
override fun setListener(listener: RemotePlayback.Listener?) {
|
|
128
|
+
this.listener = listener
|
|
129
|
+
player.setSessionAvailabilityListener(
|
|
130
|
+
listener?.let {
|
|
131
|
+
object : SessionAvailabilityListener {
|
|
132
|
+
override fun onCastSessionAvailable() = it.onSessionChanged()
|
|
133
|
+
|
|
134
|
+
override fun onCastSessionUnavailable() = it.onSessionChanged()
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
)
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
override fun release() {
|
|
141
|
+
cast.removeSessionManagerListener(sessions)
|
|
142
|
+
watch(null)
|
|
143
|
+
player.release()
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/**
|
|
148
|
+
* The end or failure of each load a receiver's media statuses report, once. A load is told by its
|
|
149
|
+
* content id, which [SendingMediaItemConverter] makes its own; a failed load's status carries no
|
|
150
|
+
* media, so it counts as the last load seen.
|
|
151
|
+
*/
|
|
152
|
+
internal class CastEnds {
|
|
153
|
+
enum class Report {
|
|
154
|
+
ENDED,
|
|
155
|
+
FAILED,
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
private var lastContentId: String? = null
|
|
159
|
+
private var reported: Pair<String?, Int>? = null
|
|
160
|
+
|
|
161
|
+
fun report(contentId: String?, playerState: Int, idleReason: Int): Report? {
|
|
162
|
+
contentId?.let { lastContentId = it }
|
|
163
|
+
val report =
|
|
164
|
+
when (idleReason.takeIf { playerState == MediaStatus.PLAYER_STATE_IDLE }) {
|
|
165
|
+
MediaStatus.IDLE_REASON_FINISHED -> Report.ENDED
|
|
166
|
+
MediaStatus.IDLE_REASON_ERROR -> Report.FAILED
|
|
167
|
+
else -> return null
|
|
168
|
+
}
|
|
169
|
+
val key = lastContentId to idleReason
|
|
170
|
+
if (key == reported) return null
|
|
171
|
+
reported = key
|
|
172
|
+
return report
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
fun reset() {
|
|
176
|
+
lastContentId = null
|
|
177
|
+
reported = null
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* Sends each item as it is, with a content id of its own: Media3's timeline tracker keys what it was
|
|
183
|
+
* sent by content id, and forgets an id when an item with it leaves the receiver's queue, so a
|
|
184
|
+
* station sent again would be forgotten with the last and show as an empty item.
|
|
185
|
+
*/
|
|
186
|
+
internal class SendingMediaItemConverter : MediaItemConverter {
|
|
187
|
+
private val default = DefaultMediaItemConverter()
|
|
188
|
+
private var sends = 0L
|
|
189
|
+
|
|
190
|
+
override fun toMediaQueueItem(mediaItem: MediaItem): MediaQueueItem =
|
|
191
|
+
default.toMediaQueueItem(
|
|
192
|
+
mediaItem.buildUpon().setMediaId("${mediaItem.mediaId}$SEND_SEPARATOR${sends++}").build()
|
|
193
|
+
)
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* The receiver's item as a media item, or [MediaItem.EMPTY] for one it reports without its media
|
|
197
|
+
* (an item it hasn't loaded), which the default converter throws on. The timeline tracker keeps
|
|
198
|
+
* an empty item's earlier data.
|
|
199
|
+
*/
|
|
200
|
+
override fun toMediaItem(mediaQueueItem: MediaQueueItem): MediaItem {
|
|
201
|
+
if (mediaQueueItem.media == null) return MediaItem.EMPTY
|
|
202
|
+
val item =
|
|
203
|
+
try {
|
|
204
|
+
default.toMediaItem(mediaQueueItem)
|
|
205
|
+
} catch (e: RuntimeException) {
|
|
206
|
+
Timber.w(e, "Cast: could not read a receiver queue item")
|
|
207
|
+
return MediaItem.EMPTY
|
|
208
|
+
}
|
|
209
|
+
return item.buildUpon().setMediaId(item.mediaId.substringBeforeLast(SEND_SEPARATOR)).build()
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private companion object {
|
|
213
|
+
const val SEND_SEPARATOR = "#cast-send-"
|
|
214
|
+
}
|
|
215
|
+
}
|
|
@@ -41,6 +41,17 @@
|
|
|
41
41
|
android:exported="true"
|
|
42
42
|
android:grantUriPermissions="false" />
|
|
43
43
|
|
|
44
|
+
<!-- Serves Sonos rooms to the system Output Switcher; enabled at setup with remoteOutputs.sonos -->
|
|
45
|
+
<service
|
|
46
|
+
android:name="com.audiobrowser.sonos.SonosRouteProviderService"
|
|
47
|
+
android:enabled="false"
|
|
48
|
+
android:exported="true">
|
|
49
|
+
<intent-filter>
|
|
50
|
+
<action android:name="android.media.MediaRouteProviderService" />
|
|
51
|
+
<action android:name="android.media.MediaRoute2ProviderService" />
|
|
52
|
+
</intent-filter>
|
|
53
|
+
</service>
|
|
54
|
+
|
|
44
55
|
<!-- Headless Task Service for background JS execution -->
|
|
45
56
|
<service android:name="com.audiobrowser.HeadlessTaskService" android:enabled="true" android:exported="false" />
|
|
46
57
|
<!-- Media button receiver for playback resumption -->
|
|
@@ -229,7 +229,6 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
229
229
|
private var updateOptions: PlayerUpdateOptions = PlayerUpdateOptions()
|
|
230
230
|
private var mediaBrowserFuture: ListenableFuture<MediaBrowser>? = null
|
|
231
231
|
private var setupOptions = PlayerSetupOptions()
|
|
232
|
-
private var remoteOutputs = false
|
|
233
232
|
// Written only on the main thread (ServiceConnection callbacks, dispose); read from main or,
|
|
234
233
|
// in a few places, straight from the JS thread. @Volatile gives those reads visibility — they
|
|
235
234
|
// must still tolerate staleness in both directions (a just-detached service, or null while
|
|
@@ -861,9 +860,6 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
861
860
|
override fun setupPlayer(options: NativeSetupPlayerOptions): Promise<Unit> {
|
|
862
861
|
return Promise.async(mainScope) {
|
|
863
862
|
setupOptions.update(options)
|
|
864
|
-
options.remoteOutputs?.let { remoteOutputs = it }
|
|
865
|
-
// Applied even when omitted, so a reloaded bundle that omits the option turns it off.
|
|
866
|
-
RemoteOutputs.setEnabled(context, remoteOutputs)
|
|
867
863
|
// The bundled runtime options and initial state are part of the atomic launch
|
|
868
864
|
// description: stage them here, apply them together with the engine below (or at
|
|
869
865
|
// service connect). Last-write-wins with their imperative counterparts.
|
|
@@ -17,16 +17,20 @@ import timber.log.Timber
|
|
|
17
17
|
/**
|
|
18
18
|
* Remote outputs: the speakers and TVs of media route providers, offered in the system Output
|
|
19
19
|
* Switcher next to the phone and Bluetooth, and the one selected there reported as the [Output].
|
|
20
|
-
* Only the selection is reported; rendering the audio there is the provider's job
|
|
20
|
+
* Only the selection is reported; rendering the audio there is the provider's job, or the Cast
|
|
21
|
+
* session's for a Cast device.
|
|
21
22
|
*
|
|
22
23
|
* Holds the process's one [MediaRouter] while enabled, on Android 11+ where the switcher exists. A
|
|
23
|
-
* provider's routes are offered when they declare [CATEGORY]
|
|
24
|
+
* provider's routes are offered when they declare [CATEGORY] or one of the categories the outputs
|
|
25
|
+
* are turned on with in a control filter.
|
|
24
26
|
*/
|
|
25
27
|
object RemoteOutputs {
|
|
26
28
|
/** The control category a media route provider's routes declare to be offered as outputs. */
|
|
27
29
|
const val CATEGORY = "com.audiobrowser.CATEGORY_REMOTE_OUTPUT"
|
|
28
30
|
|
|
29
|
-
private
|
|
31
|
+
private var types: Map<String, OutputType> = emptyMap()
|
|
32
|
+
|
|
33
|
+
private var selector = selectorFor(types)
|
|
30
34
|
|
|
31
35
|
// The global router holds routers weakly: let this one go and the system Output Switcher stops
|
|
32
36
|
// listing the category's routes, as the app's discovery preference empties on the next GC.
|
|
@@ -59,12 +63,28 @@ object RemoteOutputs {
|
|
|
59
63
|
update(router)
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
/**
|
|
66
|
+
/**
|
|
67
|
+
* Turns remote outputs on or off, and with them the routes of each control category in [types],
|
|
68
|
+
* reported as its output type. Idempotent.
|
|
69
|
+
*/
|
|
63
70
|
@MainThread
|
|
64
|
-
internal fun setEnabled(context: Context, enabled: Boolean) {
|
|
65
|
-
|
|
71
|
+
internal fun setEnabled(context: Context, enabled: Boolean, types: Map<String, OutputType>) {
|
|
72
|
+
val types = types.takeIf { enabled }.orEmpty()
|
|
73
|
+
if (!enabled) stop()
|
|
74
|
+
if (types != this.types) {
|
|
75
|
+
this.types = types
|
|
76
|
+
selector = selectorFor(types)
|
|
77
|
+
router?.let(::listen)
|
|
78
|
+
}
|
|
79
|
+
if (enabled) start(context)
|
|
66
80
|
}
|
|
67
81
|
|
|
82
|
+
private fun selectorFor(types: Map<String, OutputType>) =
|
|
83
|
+
MediaRouteSelector.Builder()
|
|
84
|
+
.addControlCategory(CATEGORY)
|
|
85
|
+
.apply { types.keys.forEach(::addControlCategory) }
|
|
86
|
+
.build()
|
|
87
|
+
|
|
68
88
|
/** Calls [listener] on the main thread whenever [current] changes. */
|
|
69
89
|
internal fun addListener(listener: () -> Unit) {
|
|
70
90
|
listeners.add(listener)
|
|
@@ -79,6 +99,11 @@ object RemoteOutputs {
|
|
|
79
99
|
warnWithoutTransferReceiver(context)
|
|
80
100
|
val router = MediaRouter.getInstance(context.applicationContext)
|
|
81
101
|
this.router = router
|
|
102
|
+
listen(router)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
private fun listen(router: MediaRouter) {
|
|
106
|
+
router.removeCallback(callback)
|
|
82
107
|
router.addCallback(selector, callback, MediaRouter.CALLBACK_FLAG_REQUEST_DISCOVERY)
|
|
83
108
|
update(router)
|
|
84
109
|
}
|
|
@@ -110,7 +135,7 @@ object RemoteOutputs {
|
|
|
110
135
|
|
|
111
136
|
private fun update(router: MediaRouter) {
|
|
112
137
|
val route = router.selectedRoute
|
|
113
|
-
setCurrent(remoteOutputOf(
|
|
138
|
+
setCurrent(remoteOutputOf(route.name, types, route::supportsControlCategory))
|
|
114
139
|
}
|
|
115
140
|
|
|
116
141
|
@VisibleForTesting
|
|
@@ -123,6 +148,18 @@ object RemoteOutputs {
|
|
|
123
148
|
}
|
|
124
149
|
}
|
|
125
150
|
|
|
126
|
-
/**
|
|
127
|
-
|
|
128
|
-
|
|
151
|
+
/**
|
|
152
|
+
* The [Output] a selected route stands for, its type that of the first category in [types] it
|
|
153
|
+
* [supports]: null for a route the remote outputs don't offer.
|
|
154
|
+
*/
|
|
155
|
+
internal fun remoteOutputOf(
|
|
156
|
+
name: String,
|
|
157
|
+
types: Map<String, OutputType>,
|
|
158
|
+
supports: (category: String) -> Boolean,
|
|
159
|
+
): Output? {
|
|
160
|
+
val type =
|
|
161
|
+
types.entries.firstOrNull { supports(it.key) }?.value
|
|
162
|
+
?: OutputType.REMOTE.takeIf { supports(RemoteOutputs.CATEGORY) }
|
|
163
|
+
?: return null
|
|
164
|
+
return Output(type = type, name = name, external = true)
|
|
165
|
+
}
|
|
@@ -5,6 +5,7 @@ import com.margelo.nitro.audiobrowser.AndroidAudioContentType
|
|
|
5
5
|
import com.margelo.nitro.audiobrowser.AndroidPlayerWakeMode
|
|
6
6
|
import com.margelo.nitro.audiobrowser.Func_std__shared_ptr_Promise_std__optional_NowPlayingUpdate____FormatNowPlayingParams as NowPlayingFormatter
|
|
7
7
|
import com.margelo.nitro.audiobrowser.NativeSetupPlayerOptions
|
|
8
|
+
import com.margelo.nitro.audiobrowser.RemoteOutputsOptions
|
|
8
9
|
import com.margelo.nitro.audiobrowser.Variant_Boolean_AndroidAudioOffloadSettings
|
|
9
10
|
import com.margelo.nitro.audiobrowser.Variant_Boolean_RetryConfig
|
|
10
11
|
|
|
@@ -62,6 +63,8 @@ data class PlayerSetupOptions(
|
|
|
62
63
|
// Optional JS formatter that customizes the now-playing title/subtitle from the track + live
|
|
63
64
|
// timed metadata. When null, the default mapping is used.
|
|
64
65
|
var nowPlayingMetadataFormatter: NowPlayingFormatter? = null,
|
|
66
|
+
// The remote outputs offered in the Output Switcher, or null for none: each setup sets it.
|
|
67
|
+
var remoteOutputs: RemoteOutputsOptions? = null,
|
|
65
68
|
) {
|
|
66
69
|
/**
|
|
67
70
|
* Whether automatic buffer management is enabled. True when rebufferBuffer is not explicitly set
|
|
@@ -71,11 +74,16 @@ data class PlayerSetupOptions(
|
|
|
71
74
|
get() = rebufferBuffer == null
|
|
72
75
|
|
|
73
76
|
/**
|
|
74
|
-
* A copy that equals another's when both build the same engine: without the now-playing options
|
|
75
|
-
* which apply without a rebuild. A formatter is a new object on every
|
|
77
|
+
* A copy that equals another's when both build the same engine: without the now-playing options
|
|
78
|
+
* and the remote outputs, which apply without a rebuild. A formatter is a new object on every
|
|
79
|
+
* setup call.
|
|
76
80
|
*/
|
|
77
81
|
fun engineOptions() =
|
|
78
|
-
copy(
|
|
82
|
+
copy(
|
|
83
|
+
autoUpdateNowPlayingMetadata = true,
|
|
84
|
+
nowPlayingMetadataFormatter = null,
|
|
85
|
+
remoteOutputs = null,
|
|
86
|
+
)
|
|
79
87
|
|
|
80
88
|
fun update(options: NativeSetupPlayerOptions) {
|
|
81
89
|
// Android-specific options
|
|
@@ -136,5 +144,6 @@ data class PlayerSetupOptions(
|
|
|
136
144
|
options.keepSessionAliveOnError?.let { keepSessionAliveOnError = it }
|
|
137
145
|
options.autoUpdateNowPlayingMetadata?.let { autoUpdateNowPlayingMetadata = it }
|
|
138
146
|
options.nowPlayingMetadataFormatter?.let { nowPlayingMetadataFormatter = it }
|
|
147
|
+
remoteOutputs = options.remoteOutputs
|
|
139
148
|
}
|
|
140
149
|
}
|
|
@@ -54,9 +54,12 @@ internal class EqualizerController(
|
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
56
|
* Reacts to an audio session change: a no-op for the same session, otherwise a fresh effect that
|
|
57
|
-
* picks up the outgoing one's settings.
|
|
57
|
+
* picks up the outgoing one's settings. An unset session (playback moved to a remote output)
|
|
58
|
+
* keeps the effect on the local session, where it applies again on the way back; an effect on
|
|
59
|
+
* session 0 would equalize the whole device's output instead.
|
|
58
60
|
*/
|
|
59
61
|
fun onAudioSessionChanged(newAudioSessionId: Int) {
|
|
62
|
+
if (newAudioSessionId == C.AUDIO_SESSION_ID_UNSET) return
|
|
60
63
|
val old = effect
|
|
61
64
|
if (old != null && old.audioSessionId == newAudioSessionId) return
|
|
62
65
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
package com.audiobrowser.player
|
|
2
|
+
|
|
3
|
+
import androidx.media3.exoplayer.ExoPlayer
|
|
4
|
+
import androidx.media3.exoplayer.source.ShuffleOrder
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The phone's engine for the work only it does: retries, reconnects and its shuffle order. While a
|
|
8
|
+
* remote output plays, none of it reaches the remote: each call does nothing.
|
|
9
|
+
*/
|
|
10
|
+
internal class LocalEngine(
|
|
11
|
+
private val engine: () -> ExoPlayer,
|
|
12
|
+
private val isRemote: () -> Boolean,
|
|
13
|
+
) {
|
|
14
|
+
private val playing: ExoPlayer?
|
|
15
|
+
get() = engine().takeIf { !isRemote() }
|
|
16
|
+
|
|
17
|
+
/** Whether the engine is what plays. */
|
|
18
|
+
val isActive: Boolean
|
|
19
|
+
get() = playing != null
|
|
20
|
+
|
|
21
|
+
/** Loads again what failed or stalled, from the live edge when [toLiveEdge]. */
|
|
22
|
+
fun retry(toLiveEdge: Boolean = false) {
|
|
23
|
+
val engine = playing ?: return
|
|
24
|
+
if (toLiveEdge) engine.seekToDefaultPosition()
|
|
25
|
+
engine.prepare()
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Reconnects a live stream at its edge: a stream with a live window seeks there; anything else
|
|
30
|
+
* connects again, which for a stream that can't seek is the edge. False while remote.
|
|
31
|
+
*/
|
|
32
|
+
fun reconnectAtLiveEdge(): Boolean {
|
|
33
|
+
val engine = playing ?: return false
|
|
34
|
+
if (engine.isCurrentMediaItemLive) {
|
|
35
|
+
engine.seekToDefaultPosition()
|
|
36
|
+
return true
|
|
37
|
+
}
|
|
38
|
+
// ExoPlayer.prepare() only re-prepares from STATE_IDLE, hence the raw stop() — not
|
|
39
|
+
// Player.stop(), which would drop the play intent this reconnect must preserve.
|
|
40
|
+
engine.stop()
|
|
41
|
+
engine.seekToDefaultPosition()
|
|
42
|
+
engine.prepare()
|
|
43
|
+
return true
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
fun setShuffleOrder(order: ShuffleOrder) {
|
|
47
|
+
playing?.setShuffleOrder(order)
|
|
48
|
+
}
|
|
49
|
+
}
|