react-native-audio-browser 0.2.0-next.90 → 0.2.0-next.91
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/src/main/java/com/audiobrowser/AudioBrowser.kt +4 -0
- package/android/src/main/java/com/audiobrowser/RemoteOutputs.kt +60 -1
- package/android/src/main/java/com/audiobrowser/browser/TrackLoadHandler.kt +2 -1
- package/android/src/main/java/com/audiobrowser/player/AutomaticBufferManager.kt +80 -7
- package/android/src/main/java/com/audiobrowser/player/MediaSessionCallback.kt +10 -2
- package/android/src/main/java/com/audiobrowser/sonos/SonosRouteProviderService.kt +13 -10
- package/android/src/test/java/com/audiobrowser/RemoteOutputRoutesTest.kt +29 -0
- package/android/src/test/java/com/audiobrowser/RemoteOutputsTest.kt +46 -4
- package/android/src/test/java/com/audiobrowser/browser/TrackLoadHandlerTest.kt +1 -0
- package/android/src/test/java/com/audiobrowser/player/AutomaticBufferManagerTest.kt +208 -0
- package/android/src/test/java/com/audiobrowser/player/HandleTrackLoadSeekTest.kt +70 -9
- package/android/src/test/java/com/audiobrowser/player/RetryMaskingTest.kt +3 -1
- package/android/src/test/java/com/audiobrowser/sonos/SonosRoutesTest.kt +32 -0
- package/ios/Model/NitroTypeStubs.swift +1 -0
- package/ios/TrackSelector.swift +6 -1
- package/lib/typescript/src/types/browser.d.ts +6 -0
- package/lib/typescript/src/types/browser.d.ts.map +1 -1
- package/nitrogen/generated/android/c++/JTrackLoadEvent.hpp +7 -3
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/audiobrowser/TrackLoadEvent.kt +9 -4
- package/nitrogen/generated/ios/swift/TrackLoadEvent.swift +20 -2
- package/nitrogen/generated/shared/c++/TrackLoadEvent.hpp +7 -2
- package/package.json +2 -1
- package/src/types/browser.ts +6 -0
- package/website/guide/audio-output.md +27 -2
- package/website/guide/browser.md +2 -2
|
@@ -592,6 +592,7 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
592
592
|
track,
|
|
593
593
|
player.tracks,
|
|
594
594
|
index.toDouble(),
|
|
595
|
+
startPosition = null,
|
|
595
596
|
intercepted = {},
|
|
596
597
|
defaultBehavior = {
|
|
597
598
|
player.skipTo(index)
|
|
@@ -614,6 +615,7 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
614
615
|
track,
|
|
615
616
|
tracks,
|
|
616
617
|
startIndex.toDouble(),
|
|
618
|
+
startPosition = null,
|
|
617
619
|
intercepted = {},
|
|
618
620
|
defaultBehavior = {
|
|
619
621
|
// The Player itself: this class's overrides block on main, where this runs.
|
|
@@ -629,6 +631,7 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
629
631
|
track,
|
|
630
632
|
arrayOf(track),
|
|
631
633
|
0.0,
|
|
634
|
+
startPosition = null,
|
|
632
635
|
intercepted = {},
|
|
633
636
|
defaultBehavior = { player.load(track) },
|
|
634
637
|
)
|
|
@@ -645,6 +648,7 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
645
648
|
track,
|
|
646
649
|
arrayOf(track),
|
|
647
650
|
0.0,
|
|
651
|
+
startPosition = null,
|
|
648
652
|
intercepted = {},
|
|
649
653
|
defaultBehavior = { player.load(track) },
|
|
650
654
|
)
|
|
@@ -2,12 +2,17 @@ package com.audiobrowser
|
|
|
2
2
|
|
|
3
3
|
import android.content.ComponentName
|
|
4
4
|
import android.content.Context
|
|
5
|
+
import android.content.IntentFilter
|
|
5
6
|
import android.content.pm.PackageManager
|
|
7
|
+
import android.os.Handler
|
|
8
|
+
import android.os.Looper
|
|
6
9
|
import androidx.annotation.MainThread
|
|
7
10
|
import androidx.annotation.VisibleForTesting
|
|
11
|
+
import androidx.mediarouter.media.MediaRouteDescriptor
|
|
8
12
|
import androidx.mediarouter.media.MediaRouteSelector
|
|
9
13
|
import androidx.mediarouter.media.MediaRouter
|
|
10
14
|
import androidx.mediarouter.media.MediaTransferReceiver
|
|
15
|
+
import com.audiobrowser.sonos.SonosOutputs
|
|
11
16
|
import com.audiobrowser.util.OutputSwitcher
|
|
12
17
|
import com.margelo.nitro.audiobrowser.Output
|
|
13
18
|
import com.margelo.nitro.audiobrowser.OutputType
|
|
@@ -26,8 +31,30 @@ object RemoteOutputs {
|
|
|
26
31
|
/** The control category a media route provider's routes declare to be offered as outputs. */
|
|
27
32
|
const val CATEGORY = "com.audiobrowser.CATEGORY_REMOTE_OUTPUT"
|
|
28
33
|
|
|
34
|
+
/**
|
|
35
|
+
* A descriptor for a route offered as a remote output, in [CATEGORY] and each of [categories],
|
|
36
|
+
* visible from Android 14 only to this app: another app on the library would list it too, and
|
|
37
|
+
* selecting it there would leave that app's playback local.
|
|
38
|
+
*/
|
|
39
|
+
@JvmStatic
|
|
40
|
+
fun routeDescriptorBuilder(
|
|
41
|
+
id: String,
|
|
42
|
+
name: String,
|
|
43
|
+
vararg categories: String,
|
|
44
|
+
): MediaRouteDescriptor.Builder =
|
|
45
|
+
MediaRouteDescriptor.Builder(id, name)
|
|
46
|
+
.addControlFilter(
|
|
47
|
+
IntentFilter().apply {
|
|
48
|
+
addCategory(CATEGORY)
|
|
49
|
+
categories.forEach(::addCategory)
|
|
50
|
+
}
|
|
51
|
+
)
|
|
52
|
+
.setVisibilityRestricted(emptySet())
|
|
53
|
+
|
|
29
54
|
private var types: Map<String, OutputType> = emptyMap()
|
|
30
55
|
|
|
56
|
+
private val mainHandler = Handler(Looper.getMainLooper())
|
|
57
|
+
|
|
31
58
|
private var selector = selectorFor(types)
|
|
32
59
|
|
|
33
60
|
// MediaRouter holds routers weakly: let this one go and the Output Switcher stops listing the
|
|
@@ -36,6 +63,8 @@ object RemoteOutputs {
|
|
|
36
63
|
|
|
37
64
|
private val listeners = CopyOnWriteArraySet<() -> Unit>()
|
|
38
65
|
|
|
66
|
+
private val onSonosSelectionChanged: () -> Unit = { router?.let(::update) }
|
|
67
|
+
|
|
39
68
|
/** The selected remote output, or null while playback stays local. Read from any thread. */
|
|
40
69
|
@Volatile
|
|
41
70
|
internal var current: Output? = null
|
|
@@ -97,6 +126,7 @@ object RemoteOutputs {
|
|
|
97
126
|
warnWithoutTransferReceiver(context)
|
|
98
127
|
val router = MediaRouter.getInstance(context.applicationContext)
|
|
99
128
|
this.router = router
|
|
129
|
+
SonosOutputs.addListener(onSonosSelectionChanged)
|
|
100
130
|
listen(router)
|
|
101
131
|
}
|
|
102
132
|
|
|
@@ -109,6 +139,7 @@ object RemoteOutputs {
|
|
|
109
139
|
private fun stop() {
|
|
110
140
|
val router = router ?: return
|
|
111
141
|
router.removeCallback(callback)
|
|
142
|
+
SonosOutputs.removeListener(onSonosSelectionChanged)
|
|
112
143
|
if (router.selectedRoute.matchesSelector(selector)) {
|
|
113
144
|
router.unselect(MediaRouter.UNSELECT_REASON_STOPPED)
|
|
114
145
|
}
|
|
@@ -133,7 +164,22 @@ object RemoteOutputs {
|
|
|
133
164
|
|
|
134
165
|
private fun update(router: MediaRouter) {
|
|
135
166
|
val route = router.selectedRoute
|
|
136
|
-
|
|
167
|
+
val sonosSelected = SonosOutputs.selected != null
|
|
168
|
+
setCurrent(remoteOutputOf(route.name, types, sonosSelected, route::supportsControlCategory))
|
|
169
|
+
// Posted: this runs inside the router's callbacks, which unselect would re-enter.
|
|
170
|
+
if (isUnservedSonosRoute(sonosSelected, route::supportsControlCategory)) {
|
|
171
|
+
mainHandler.post(::releaseUnservedSonosRoute)
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
// Unselecting ends the system's session on another app's provider, which plays nothing of ours
|
|
176
|
+
// but keeps the switcher offering Stop casting.
|
|
177
|
+
private fun releaseUnservedSonosRoute() {
|
|
178
|
+
val router = router ?: return
|
|
179
|
+
val route = router.selectedRoute
|
|
180
|
+
if (!isUnservedSonosRoute(SonosOutputs.selected != null, route::supportsControlCategory)) return
|
|
181
|
+
Timber.d("RemoteOutputs: releasing %s, which another app's provider serves", route.name)
|
|
182
|
+
router.unselect(MediaRouter.UNSELECT_REASON_STOPPED)
|
|
137
183
|
}
|
|
138
184
|
|
|
139
185
|
@VisibleForTesting
|
|
@@ -149,15 +195,28 @@ object RemoteOutputs {
|
|
|
149
195
|
/**
|
|
150
196
|
* The [Output] a selected route stands for, typed by the first category in [types] it [supports],
|
|
151
197
|
* else [OutputType.REMOTE] for [RemoteOutputs.CATEGORY]; null for a route the outputs don't offer.
|
|
198
|
+
* A Sonos room's route [another app's provider serves][isUnservedSonosRoute] is not an output.
|
|
152
199
|
*/
|
|
153
200
|
internal fun remoteOutputOf(
|
|
154
201
|
name: String,
|
|
155
202
|
types: Map<String, OutputType>,
|
|
203
|
+
sonosSelected: Boolean,
|
|
156
204
|
supports: (category: String) -> Boolean,
|
|
157
205
|
): Output? {
|
|
206
|
+
if (isUnservedSonosRoute(sonosSelected, supports)) return null
|
|
158
207
|
val type =
|
|
159
208
|
types.entries.firstOrNull { supports(it.key) }?.value
|
|
160
209
|
?: OutputType.REMOTE.takeIf { supports(RemoteOutputs.CATEGORY) }
|
|
161
210
|
?: return null
|
|
162
211
|
return Output(type = type, name = name, external = true)
|
|
163
212
|
}
|
|
213
|
+
|
|
214
|
+
/**
|
|
215
|
+
* Whether a selected route is a Sonos room's that this app's provider doesn't serve, as it has no
|
|
216
|
+
* room selected: another app on the library publishes the same rooms, and selecting one of its
|
|
217
|
+
* routes leaves playback here. Holds even while this app has Sonos turned off.
|
|
218
|
+
*/
|
|
219
|
+
internal fun isUnservedSonosRoute(
|
|
220
|
+
sonosSelected: Boolean,
|
|
221
|
+
supports: (category: String) -> Boolean,
|
|
222
|
+
): Boolean = supports(SonosOutputs.CATEGORY) && !sonosSelected
|
|
@@ -19,11 +19,12 @@ suspend fun <T> handleTrackLoad(
|
|
|
19
19
|
track: Track,
|
|
20
20
|
queue: Array<Track>,
|
|
21
21
|
startIndex: Double,
|
|
22
|
+
startPosition: Double?,
|
|
22
23
|
intercepted: suspend () -> T,
|
|
23
24
|
defaultBehavior: suspend () -> T,
|
|
24
25
|
): T {
|
|
25
26
|
if (handler != null) {
|
|
26
|
-
val event = TrackLoadEvent(track, queue, startIndex)
|
|
27
|
+
val event = TrackLoadEvent(track, queue, startIndex, startPosition)
|
|
27
28
|
try {
|
|
28
29
|
handler(event).awaitNested()
|
|
29
30
|
} catch (e: CancellationException) {
|
|
@@ -1,19 +1,28 @@
|
|
|
1
1
|
package com.audiobrowser.player
|
|
2
2
|
|
|
3
|
+
import android.os.SystemClock
|
|
3
4
|
import androidx.media3.common.Player
|
|
4
5
|
import androidx.media3.exoplayer.ExoPlayer
|
|
5
6
|
import androidx.media3.exoplayer.analytics.AnalyticsListener
|
|
7
|
+
import androidx.media3.exoplayer.source.LoadEventInfo
|
|
8
|
+
import androidx.media3.exoplayer.source.MediaLoadData
|
|
9
|
+
import java.io.IOException
|
|
6
10
|
import timber.log.Timber
|
|
7
11
|
|
|
8
12
|
/**
|
|
9
|
-
* Raises [DynamicLoadControl]'s `bufferForPlaybackAfterRebufferMs` after each
|
|
13
|
+
* Raises [DynamicLoadControl]'s `bufferForPlaybackAfterRebufferMs` after each underrun, to what the
|
|
10
14
|
* measured drain rate says would last [targetPlaybackDurationMs]. The threshold only rises, up to
|
|
11
15
|
* [maxRebufferBufferMs], until a playlist change or a seek to another item resets it to
|
|
12
16
|
* [defaultConfig].
|
|
17
|
+
*
|
|
18
|
+
* An underrun is a rebuffer while every load delivers, however slowly: a connection that stays open
|
|
19
|
+
* and stalls counts. A rebuffer while media3 retries a failed load in place does not, nor does a
|
|
20
|
+
* reconnect's first buffering, which starts from idle.
|
|
13
21
|
*/
|
|
14
22
|
class AutomaticBufferManager(
|
|
15
23
|
private val loadControl: DynamicLoadControl,
|
|
16
24
|
private val defaultConfig: BufferConfig = BufferConfig(),
|
|
25
|
+
private val clock: () -> Long = SystemClock::elapsedRealtime,
|
|
17
26
|
) : AnalyticsListener, Player.Listener {
|
|
18
27
|
|
|
19
28
|
private var exoPlayer: ExoPlayer? = null
|
|
@@ -21,6 +30,16 @@ class AutomaticBufferManager(
|
|
|
21
30
|
private var wasReady = false
|
|
22
31
|
private var rebufferCount = 0
|
|
23
32
|
|
|
33
|
+
/** When each of the current item's loads last failed or retried, until it completes. */
|
|
34
|
+
private val failingLoads = mutableMapOf<Long, Long>()
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* How long a load counts as failing after its last error or retry: longer than one attempt can
|
|
38
|
+
* take to fail, a connect and then a read, each with an 8 s timeout. A progressive load that
|
|
39
|
+
* recovers never completes until its file ends.
|
|
40
|
+
*/
|
|
41
|
+
private val failingLoadWindowMs = 20_000L
|
|
42
|
+
|
|
24
43
|
private var playbackStartTimeMs: Long = 0
|
|
25
44
|
private var bufferAtPlaybackStartMs: Long = 0
|
|
26
45
|
private var bufferingStartTimeMs: Long = 0
|
|
@@ -68,16 +87,18 @@ class AutomaticBufferManager(
|
|
|
68
87
|
when (playbackState) {
|
|
69
88
|
Player.STATE_BUFFERING -> {
|
|
70
89
|
if (wasReady) {
|
|
71
|
-
onRebuffer()
|
|
90
|
+
if (loadsFailing()) onFailedLoadRebuffer() else onRebuffer()
|
|
72
91
|
}
|
|
73
92
|
if (bufferingStartTimeMs == 0L) {
|
|
74
|
-
bufferingStartTimeMs =
|
|
93
|
+
bufferingStartTimeMs = clock()
|
|
75
94
|
Timber.d("STATE_BUFFERING entered - starting buffer timer")
|
|
76
95
|
}
|
|
77
96
|
}
|
|
78
97
|
Player.STATE_READY -> {
|
|
98
|
+
// Playing again: the loads that failed deliver.
|
|
99
|
+
failingLoads.clear()
|
|
79
100
|
if (!wasReady) {
|
|
80
|
-
playbackStartTimeMs =
|
|
101
|
+
playbackStartTimeMs = clock()
|
|
81
102
|
bufferAtPlaybackStartMs = exoPlayer?.totalBufferedDuration ?: 0
|
|
82
103
|
lastBufferLogTimeMs = playbackStartTimeMs
|
|
83
104
|
|
|
@@ -104,6 +125,49 @@ class AutomaticBufferManager(
|
|
|
104
125
|
}
|
|
105
126
|
}
|
|
106
127
|
|
|
128
|
+
override fun onLoadError(
|
|
129
|
+
eventTime: AnalyticsListener.EventTime,
|
|
130
|
+
loadEventInfo: LoadEventInfo,
|
|
131
|
+
mediaLoadData: MediaLoadData,
|
|
132
|
+
error: IOException,
|
|
133
|
+
wasCanceled: Boolean,
|
|
134
|
+
) {
|
|
135
|
+
// A preload of the next item failing does not starve this one. A canceled load counts too:
|
|
136
|
+
// media3 cancels the load of an HLS variant it excludes, and loads another.
|
|
137
|
+
if (eventTime.windowIndex != eventTime.currentWindowIndex) return
|
|
138
|
+
failingLoads[loadEventInfo.loadTaskId] = clock()
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
override fun onLoadStarted(
|
|
142
|
+
eventTime: AnalyticsListener.EventTime,
|
|
143
|
+
loadEventInfo: LoadEventInfo,
|
|
144
|
+
mediaLoadData: MediaLoadData,
|
|
145
|
+
retryCount: Int,
|
|
146
|
+
) {
|
|
147
|
+
if (loadEventInfo.loadTaskId in failingLoads) failingLoads[loadEventInfo.loadTaskId] = clock()
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
private fun loadsFailing(): Boolean {
|
|
151
|
+
val now = clock()
|
|
152
|
+
return failingLoads.values.any { now - it < failingLoadWindowMs }
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
override fun onLoadCompleted(
|
|
156
|
+
eventTime: AnalyticsListener.EventTime,
|
|
157
|
+
loadEventInfo: LoadEventInfo,
|
|
158
|
+
mediaLoadData: MediaLoadData,
|
|
159
|
+
) {
|
|
160
|
+
failingLoads -= loadEventInfo.loadTaskId
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
override fun onLoadCanceled(
|
|
164
|
+
eventTime: AnalyticsListener.EventTime,
|
|
165
|
+
loadEventInfo: LoadEventInfo,
|
|
166
|
+
mediaLoadData: MediaLoadData,
|
|
167
|
+
) {
|
|
168
|
+
failingLoads -= loadEventInfo.loadTaskId
|
|
169
|
+
}
|
|
170
|
+
|
|
107
171
|
override fun onIsPlayingChanged(
|
|
108
172
|
eventTime: androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime,
|
|
109
173
|
isPlaying: Boolean,
|
|
@@ -121,7 +185,7 @@ class AutomaticBufferManager(
|
|
|
121
185
|
override fun run() {
|
|
122
186
|
if (wasReady && exoPlayer?.isPlaying == true) {
|
|
123
187
|
val bufferedMs = exoPlayer?.totalBufferedDuration ?: 0
|
|
124
|
-
val playedMs =
|
|
188
|
+
val playedMs = clock() - playbackStartTimeMs
|
|
125
189
|
val config = loadControl.getBufferConfig()
|
|
126
190
|
Timber.d(
|
|
127
191
|
"Buffer status: %dms buffered, played %dms (rebuffer threshold: %dms)",
|
|
@@ -160,9 +224,14 @@ class AutomaticBufferManager(
|
|
|
160
224
|
|
|
161
225
|
// region Buffer adjustment logic
|
|
162
226
|
|
|
227
|
+
private fun onFailedLoadRebuffer() {
|
|
228
|
+
Timber.d("Rebuffer while a failed load retries, threshold kept")
|
|
229
|
+
restartMeasurement()
|
|
230
|
+
}
|
|
231
|
+
|
|
163
232
|
private fun onRebuffer() {
|
|
164
233
|
rebufferCount++
|
|
165
|
-
val now =
|
|
234
|
+
val now = clock()
|
|
166
235
|
val playbackDurationMs = if (playbackStartTimeMs > 0) now - playbackStartTimeMs else 0
|
|
167
236
|
|
|
168
237
|
Timber.d(
|
|
@@ -189,7 +258,11 @@ class AutomaticBufferManager(
|
|
|
189
258
|
Timber.d("Skipping adjustment - insufficient timing data")
|
|
190
259
|
}
|
|
191
260
|
|
|
192
|
-
|
|
261
|
+
restartMeasurement()
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
/** The next rebuffer counts only after STATE_READY records a fresh start. */
|
|
265
|
+
private fun restartMeasurement() {
|
|
193
266
|
wasReady = false
|
|
194
267
|
playbackStartTimeMs = 0
|
|
195
268
|
bufferAtPlaybackStartMs = 0
|
|
@@ -2,6 +2,7 @@ package com.audiobrowser.player
|
|
|
2
2
|
|
|
3
3
|
import android.os.Bundle
|
|
4
4
|
import androidx.core.content.ContextCompat
|
|
5
|
+
import androidx.media3.common.C
|
|
5
6
|
import androidx.media3.common.MediaItem
|
|
6
7
|
import androidx.media3.common.MediaMetadata
|
|
7
8
|
import androidx.media3.common.Rating
|
|
@@ -805,6 +806,8 @@ class MediaSessionCallback(private val player: Player) :
|
|
|
805
806
|
)
|
|
806
807
|
}
|
|
807
808
|
|
|
809
|
+
val startPosition = startPositionMs.takeIf { it != C.TIME_UNSET }?.let { it / 1000.0 }
|
|
810
|
+
|
|
808
811
|
return scope.future {
|
|
809
812
|
val audioBrowser = player.awaitBrowser()
|
|
810
813
|
|
|
@@ -847,6 +850,7 @@ class MediaSessionCallback(private val player: Player) :
|
|
|
847
850
|
track,
|
|
848
851
|
queueTracks,
|
|
849
852
|
index.toDouble(),
|
|
853
|
+
startPosition,
|
|
850
854
|
::currentPlayerState,
|
|
851
855
|
) {
|
|
852
856
|
val existingItems = queueTracks.map { TrackFactory.toMedia3(it) }
|
|
@@ -860,13 +864,17 @@ class MediaSessionCallback(private val player: Player) :
|
|
|
860
864
|
browserManager.resolveMediaItemsForPlayback(mediaItems, startIndex, startPositionMs)
|
|
861
865
|
|
|
862
866
|
val tracks = result.mediaItems.map { TrackFactory.fromMedia3(it) }.toTypedArray()
|
|
863
|
-
|
|
867
|
+
// setQueue reads an unset index as "keep the current one". Media3 still gets it unset on the
|
|
868
|
+
// default branch, where it means a reset.
|
|
869
|
+
val handlerIndex = result.startIndex.takeIf { it != C.INDEX_UNSET } ?: 0
|
|
870
|
+
val selectedTrack = tracks.getOrElse(handlerIndex) { tracks.first() }
|
|
864
871
|
|
|
865
872
|
handleTrackLoad(
|
|
866
873
|
audioBrowser.configuration.handleTrackLoad,
|
|
867
874
|
selectedTrack,
|
|
868
875
|
tracks,
|
|
869
|
-
|
|
876
|
+
handlerIndex.toDouble(),
|
|
877
|
+
startPosition,
|
|
870
878
|
::currentPlayerState,
|
|
871
879
|
) {
|
|
872
880
|
// Only on handleTrackLoad's default branch: a consumer that handles the load owns the
|
|
@@ -1,10 +1,8 @@
|
|
|
1
1
|
package com.audiobrowser.sonos
|
|
2
2
|
|
|
3
3
|
import android.content.Context
|
|
4
|
-
import android.content.IntentFilter
|
|
5
4
|
import android.net.wifi.WifiManager
|
|
6
5
|
import androidx.annotation.VisibleForTesting
|
|
7
|
-
import androidx.mediarouter.media.MediaRouteDescriptor
|
|
8
6
|
import androidx.mediarouter.media.MediaRouteDiscoveryRequest
|
|
9
7
|
import androidx.mediarouter.media.MediaRouteProvider
|
|
10
8
|
import androidx.mediarouter.media.MediaRouteProviderDescriptor
|
|
@@ -86,7 +84,18 @@ internal class SonosRouteProvider(context: Context) : MediaRouteProvider(context
|
|
|
86
84
|
scope.cancel()
|
|
87
85
|
}
|
|
88
86
|
|
|
89
|
-
|
|
87
|
+
/**
|
|
88
|
+
* Serves only this app's own sessions: [SonosOutputs.selected] moves this app's playback, so
|
|
89
|
+
* another app's session would play this app's queue in its place.
|
|
90
|
+
*/
|
|
91
|
+
override fun onCreateRouteController(
|
|
92
|
+
routeId: String,
|
|
93
|
+
options: RouteControllerOptions,
|
|
94
|
+
): RouteController? {
|
|
95
|
+
if (options.clientPackageName != context.packageName) {
|
|
96
|
+
Timber.d("Sonos: refusing a session for %s", options.clientPackageName)
|
|
97
|
+
return null
|
|
98
|
+
}
|
|
90
99
|
val room = rooms.firstOrNull { it.id == routeId } ?: return null
|
|
91
100
|
return SonosRouteController(room)
|
|
92
101
|
}
|
|
@@ -158,17 +167,11 @@ internal fun sonosRouteDescriptors(
|
|
|
158
167
|
selectedId: String?,
|
|
159
168
|
volumeOf: (String) -> Int?,
|
|
160
169
|
): MediaRouteProviderDescriptor {
|
|
161
|
-
val filter =
|
|
162
|
-
IntentFilter().apply {
|
|
163
|
-
addCategory(RemoteOutputs.CATEGORY)
|
|
164
|
-
addCategory(SonosOutputs.CATEGORY)
|
|
165
|
-
}
|
|
166
170
|
val builder = MediaRouteProviderDescriptor.Builder()
|
|
167
171
|
for (room in rooms) {
|
|
168
172
|
builder.addRoute(
|
|
169
|
-
|
|
173
|
+
RemoteOutputs.routeDescriptorBuilder(room.id, room.name, SonosOutputs.CATEGORY)
|
|
170
174
|
.setDescription("Sonos")
|
|
171
|
-
.addControlFilter(filter)
|
|
172
175
|
.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
|
|
173
176
|
.setDeviceType(MediaRouter.RouteInfo.DEVICE_TYPE_SPEAKER)
|
|
174
177
|
.setVolumeHandling(MediaRouter.RouteInfo.PLAYBACK_VOLUME_VARIABLE)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package com.audiobrowser
|
|
2
|
+
|
|
3
|
+
import org.junit.Assert.assertEquals
|
|
4
|
+
import org.junit.Assert.assertFalse
|
|
5
|
+
import org.junit.Assert.assertTrue
|
|
6
|
+
import org.junit.Test
|
|
7
|
+
import org.junit.runner.RunWith
|
|
8
|
+
import org.robolectric.RobolectricTestRunner
|
|
9
|
+
|
|
10
|
+
@RunWith(RobolectricTestRunner::class)
|
|
11
|
+
class RemoteOutputRoutesTest {
|
|
12
|
+
@Test
|
|
13
|
+
fun `a remote output's route is in the category and visible only to this app`() {
|
|
14
|
+
val route = RemoteOutputs.routeDescriptorBuilder("speaker", "Speaker").build()
|
|
15
|
+
|
|
16
|
+
assertTrue(route.controlFilters.single().hasCategory(RemoteOutputs.CATEGORY))
|
|
17
|
+
assertFalse(route.isVisibilityPublic)
|
|
18
|
+
assertEquals(emptySet<String>(), route.allowedPackages)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
@Test
|
|
22
|
+
fun `a remote output's route carries the further categories given`() {
|
|
23
|
+
val route = RemoteOutputs.routeDescriptorBuilder("speaker", "Speaker", "other").build()
|
|
24
|
+
|
|
25
|
+
val filter = route.controlFilters.single()
|
|
26
|
+
assertTrue(filter.hasCategory(RemoteOutputs.CATEGORY))
|
|
27
|
+
assertTrue(filter.hasCategory("other"))
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -1,16 +1,19 @@
|
|
|
1
1
|
package com.audiobrowser
|
|
2
2
|
|
|
3
|
+
import com.audiobrowser.sonos.SonosOutputs
|
|
3
4
|
import com.margelo.nitro.audiobrowser.Output
|
|
4
5
|
import com.margelo.nitro.audiobrowser.OutputType
|
|
5
6
|
import org.junit.Assert.assertEquals
|
|
7
|
+
import org.junit.Assert.assertFalse
|
|
6
8
|
import org.junit.Assert.assertNull
|
|
9
|
+
import org.junit.Assert.assertTrue
|
|
7
10
|
import org.junit.Test
|
|
8
11
|
|
|
9
12
|
class RemoteOutputsTest {
|
|
10
|
-
private val types = mapOf("cast" to OutputType.CAST,
|
|
13
|
+
private val types = mapOf("cast" to OutputType.CAST, SonosOutputs.CATEGORY to OutputType.SONOS)
|
|
11
14
|
|
|
12
|
-
private fun outputOf(name: String, vararg categories: String) =
|
|
13
|
-
remoteOutputOf(name, types) { it in categories }
|
|
15
|
+
private fun outputOf(name: String, vararg categories: String, sonosSelected: Boolean = true) =
|
|
16
|
+
remoteOutputOf(name, types, sonosSelected) { it in categories }
|
|
14
17
|
|
|
15
18
|
@Test
|
|
16
19
|
fun `a selected route in the category is a remote output`() {
|
|
@@ -33,7 +36,46 @@ class RemoteOutputsTest {
|
|
|
33
36
|
)
|
|
34
37
|
assertEquals(
|
|
35
38
|
Output(type = OutputType.SONOS, name = "Dining Room", external = true),
|
|
36
|
-
outputOf("Dining Room", RemoteOutputs.CATEGORY,
|
|
39
|
+
outputOf("Dining Room", RemoteOutputs.CATEGORY, SonosOutputs.CATEGORY),
|
|
40
|
+
)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
@Test
|
|
44
|
+
fun `a Sonos route while this app's provider has no room selected stays local`() {
|
|
45
|
+
assertNull(
|
|
46
|
+
outputOf("Dining Room", RemoteOutputs.CATEGORY, SonosOutputs.CATEGORY, sonosSelected = false)
|
|
47
|
+
)
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
@Test
|
|
51
|
+
fun `a Sonos route with Sonos off here and no room selected stays local`() {
|
|
52
|
+
assertNull(
|
|
53
|
+
remoteOutputOf("Dining Room", mapOf("cast" to OutputType.CAST), sonosSelected = false) {
|
|
54
|
+
it == RemoteOutputs.CATEGORY || it == SonosOutputs.CATEGORY
|
|
55
|
+
}
|
|
56
|
+
)
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
@Test
|
|
60
|
+
fun `a Sonos route is unserved while this app's provider has no room selected`() {
|
|
61
|
+
assertTrue(isUnservedSonosRoute(sonosSelected = false) { it == SonosOutputs.CATEGORY })
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@Test
|
|
65
|
+
fun `a Sonos route while this app's provider has a room selected, and any other route, are served`() {
|
|
66
|
+
assertFalse(isUnservedSonosRoute(sonosSelected = true) { it == SonosOutputs.CATEGORY })
|
|
67
|
+
assertFalse(isUnservedSonosRoute(sonosSelected = false) { it == RemoteOutputs.CATEGORY })
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
@Test
|
|
71
|
+
fun `other routes are remote outputs while no Sonos room is selected`() {
|
|
72
|
+
assertEquals(
|
|
73
|
+
Output(type = OutputType.CAST, name = "Living room TV", external = true),
|
|
74
|
+
outputOf("Living room TV", "cast", sonosSelected = false),
|
|
75
|
+
)
|
|
76
|
+
assertEquals(
|
|
77
|
+
Output(type = OutputType.REMOTE, name = "Kitchen", external = true),
|
|
78
|
+
outputOf("Kitchen", RemoteOutputs.CATEGORY, sonosSelected = false),
|
|
37
79
|
)
|
|
38
80
|
}
|
|
39
81
|
}
|
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
package com.audiobrowser.player
|
|
2
|
+
|
|
3
|
+
import android.net.Uri
|
|
4
|
+
import androidx.media3.common.C
|
|
5
|
+
import androidx.media3.common.Player as MediaPlayer
|
|
6
|
+
import androidx.media3.common.Timeline
|
|
7
|
+
import androidx.media3.datasource.DataSpec
|
|
8
|
+
import androidx.media3.exoplayer.ExoPlayer
|
|
9
|
+
import androidx.media3.exoplayer.analytics.AnalyticsListener
|
|
10
|
+
import androidx.media3.exoplayer.source.LoadEventInfo
|
|
11
|
+
import androidx.media3.exoplayer.source.MediaLoadData
|
|
12
|
+
import java.io.IOException
|
|
13
|
+
import org.junit.Assert.assertEquals
|
|
14
|
+
import org.junit.Test
|
|
15
|
+
import org.junit.runner.RunWith
|
|
16
|
+
import org.mockito.Mockito.mock
|
|
17
|
+
import org.mockito.Mockito.`when`
|
|
18
|
+
import org.robolectric.RobolectricTestRunner
|
|
19
|
+
|
|
20
|
+
@RunWith(RobolectricTestRunner::class)
|
|
21
|
+
class AutomaticBufferManagerTest {
|
|
22
|
+
|
|
23
|
+
private val fastStart =
|
|
24
|
+
BufferConfig(bufferForPlaybackMs = 500, bufferForPlaybackAfterRebufferMs = 1000)
|
|
25
|
+
private val loadControl = DynamicLoadControl(fastStart)
|
|
26
|
+
private var nowMs = 3_600_000L
|
|
27
|
+
private val engine = mock(ExoPlayer::class.java)
|
|
28
|
+
private val manager =
|
|
29
|
+
AutomaticBufferManager(loadControl, fastStart, clock = { nowMs }).also { it.attach(engine) }
|
|
30
|
+
|
|
31
|
+
private val threshold: Int
|
|
32
|
+
get() = loadControl.getBufferConfig().bufferForPlaybackAfterRebufferMs
|
|
33
|
+
|
|
34
|
+
/** Ready with [bufferedMs] buffered, then [playedMs] of playback. */
|
|
35
|
+
private fun play(bufferedMs: Long = 2_000, playedMs: Long = 20_000) {
|
|
36
|
+
`when`(engine.totalBufferedDuration).thenReturn(bufferedMs)
|
|
37
|
+
manager.onPlaybackStateChanged(MediaPlayer.STATE_READY)
|
|
38
|
+
nowMs += playedMs
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
private fun state(state: Int) = manager.onPlaybackStateChanged(state)
|
|
42
|
+
|
|
43
|
+
private fun eventTime(windowIndex: Int = 0) =
|
|
44
|
+
AnalyticsListener.EventTime(
|
|
45
|
+
nowMs,
|
|
46
|
+
Timeline.EMPTY,
|
|
47
|
+
windowIndex,
|
|
48
|
+
null,
|
|
49
|
+
0,
|
|
50
|
+
Timeline.EMPTY,
|
|
51
|
+
/* currentWindowIndex= */ 0,
|
|
52
|
+
null,
|
|
53
|
+
0,
|
|
54
|
+
0,
|
|
55
|
+
)
|
|
56
|
+
|
|
57
|
+
private fun load(taskId: Long) =
|
|
58
|
+
LoadEventInfo(taskId, DataSpec(Uri.parse("https://example.com/a")), nowMs)
|
|
59
|
+
|
|
60
|
+
private val data = MediaLoadData(C.DATA_TYPE_MEDIA)
|
|
61
|
+
|
|
62
|
+
private fun loadFailed(taskId: Long = 1, windowIndex: Int = 0, canceled: Boolean = false) =
|
|
63
|
+
manager.onLoadError(eventTime(windowIndex), load(taskId), data, IOException(), canceled)
|
|
64
|
+
|
|
65
|
+
private fun loadCompleted(taskId: Long = 1) =
|
|
66
|
+
manager.onLoadCompleted(eventTime(), load(taskId), data)
|
|
67
|
+
|
|
68
|
+
@Test
|
|
69
|
+
fun `an underrun raises the threshold to what the drain rate says lasts a minute`() {
|
|
70
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
71
|
+
// 2 s drained over 20 s: 100 ms a second, 6 s for a minute.
|
|
72
|
+
play(bufferedMs = 2_000, playedMs = 20_000)
|
|
73
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
74
|
+
assertEquals(6_000, threshold)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
@Test
|
|
78
|
+
fun `a reconnect's first buffering is not a rebuffer`() {
|
|
79
|
+
play()
|
|
80
|
+
state(MediaPlayer.STATE_IDLE)
|
|
81
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
82
|
+
play()
|
|
83
|
+
assertEquals(1_000, threshold)
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@Test
|
|
87
|
+
fun `a clean close of a stream with an end is not a rebuffer`() {
|
|
88
|
+
play()
|
|
89
|
+
state(MediaPlayer.STATE_ENDED)
|
|
90
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
91
|
+
play()
|
|
92
|
+
assertEquals(1_000, threshold)
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
@Test
|
|
96
|
+
fun `a buffering while a failed load retries in place keeps the threshold`() {
|
|
97
|
+
play()
|
|
98
|
+
loadFailed()
|
|
99
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
100
|
+
assertEquals(1_000, threshold)
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
@Test
|
|
104
|
+
fun `the drain is measured afresh once the failed load recovers`() {
|
|
105
|
+
play()
|
|
106
|
+
loadFailed()
|
|
107
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
108
|
+
// 4 s drained over 20 s: 12 s for a minute, at most 8 s.
|
|
109
|
+
play(bufferedMs = 4_000)
|
|
110
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
111
|
+
assertEquals(8_000, threshold)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
@Test
|
|
115
|
+
fun `a failed load that completed leaves the next underrun counted`() {
|
|
116
|
+
play()
|
|
117
|
+
loadFailed()
|
|
118
|
+
loadCompleted()
|
|
119
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
120
|
+
assertEquals(6_000, threshold)
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
@Test
|
|
124
|
+
fun `a failed preload of the next item leaves the underrun counted`() {
|
|
125
|
+
play()
|
|
126
|
+
loadFailed(windowIndex = 1)
|
|
127
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
128
|
+
assertEquals(6_000, threshold)
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
@Test
|
|
132
|
+
fun `a load that recovered without completing stops counting as failing`() {
|
|
133
|
+
play()
|
|
134
|
+
loadFailed()
|
|
135
|
+
// A progressive load that recovers in place completes only at the end of its file.
|
|
136
|
+
nowMs += 20_000
|
|
137
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
138
|
+
// 2 s drained over 40 s: 3 s for a minute.
|
|
139
|
+
assertEquals(3_000, threshold)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
@Test
|
|
143
|
+
fun `a load that starts without failing does not count as failing`() {
|
|
144
|
+
play()
|
|
145
|
+
manager.onLoadStarted(eventTime(), load(2), data, 0)
|
|
146
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
147
|
+
assertEquals(6_000, threshold)
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
@Test
|
|
151
|
+
fun `a load that keeps failing counts until its last error is old`() {
|
|
152
|
+
play()
|
|
153
|
+
loadFailed()
|
|
154
|
+
nowMs += 15_000
|
|
155
|
+
loadFailed()
|
|
156
|
+
nowMs += 15_000
|
|
157
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
158
|
+
assertEquals(1_000, threshold)
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
@Test
|
|
162
|
+
fun `a failed load media3 cancels still counts as failing`() {
|
|
163
|
+
play()
|
|
164
|
+
// An HLS variant media3 excludes: its load is canceled, and the next variant's starts.
|
|
165
|
+
loadFailed(canceled = true)
|
|
166
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
167
|
+
assertEquals(1_000, threshold)
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
@Test
|
|
171
|
+
fun `each retry of a failing load keeps it failing`() {
|
|
172
|
+
play()
|
|
173
|
+
loadFailed()
|
|
174
|
+
nowMs += 15_000
|
|
175
|
+
manager.onLoadStarted(eventTime(), load(1), data, 1)
|
|
176
|
+
nowMs += 15_000
|
|
177
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
178
|
+
assertEquals(1_000, threshold)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
@Test
|
|
182
|
+
fun `playing again forgets the failed loads`() {
|
|
183
|
+
play()
|
|
184
|
+
loadFailed()
|
|
185
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
186
|
+
// 2 s drained over 5 s: 24 s for a minute, at most 8 s.
|
|
187
|
+
play(playedMs = 5_000)
|
|
188
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
189
|
+
assertEquals(8_000, threshold)
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
@Test
|
|
193
|
+
fun `a canceled load no longer counts as failing`() {
|
|
194
|
+
play()
|
|
195
|
+
loadFailed()
|
|
196
|
+
manager.onLoadCanceled(eventTime(), load(1), data)
|
|
197
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
198
|
+
assertEquals(6_000, threshold)
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
@Test
|
|
202
|
+
fun `reset restores the fast start`() {
|
|
203
|
+
play()
|
|
204
|
+
state(MediaPlayer.STATE_BUFFERING)
|
|
205
|
+
manager.reset()
|
|
206
|
+
assertEquals(fastStart, loadControl.getBufferConfig())
|
|
207
|
+
}
|
|
208
|
+
}
|
|
@@ -22,6 +22,8 @@ import java.time.Duration
|
|
|
22
22
|
import java.util.concurrent.TimeUnit
|
|
23
23
|
import org.junit.After
|
|
24
24
|
import org.junit.Assert.assertEquals
|
|
25
|
+
import org.junit.Assert.assertNotNull
|
|
26
|
+
import org.junit.Assert.assertNull
|
|
25
27
|
import org.junit.Assert.fail
|
|
26
28
|
import org.junit.Rule
|
|
27
29
|
import org.junit.Test
|
|
@@ -36,7 +38,10 @@ import org.robolectric.Shadows.shadowOf
|
|
|
36
38
|
import org.robolectric.annotation.Config
|
|
37
39
|
import org.robolectric.shadows.ShadowSystemClock
|
|
38
40
|
|
|
39
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* A controller's set of media items reaches handleTrackLoad with the position it asked for, and
|
|
43
|
+
* keeps where the handler left the player.
|
|
44
|
+
*/
|
|
40
45
|
@RunWith(RobolectricTestRunner::class)
|
|
41
46
|
@Config(sdk = [28])
|
|
42
47
|
class HandleTrackLoadSeekTest {
|
|
@@ -57,13 +62,13 @@ class HandleTrackLoadSeekTest {
|
|
|
57
62
|
service.destroy()
|
|
58
63
|
}
|
|
59
64
|
|
|
60
|
-
private fun handlingTrackLoadWith(onLoad: (
|
|
65
|
+
private fun handlingTrackLoadWith(onLoad: (TrackLoadEvent) -> Unit) {
|
|
61
66
|
// JS runs the handler's player calls on the main thread before its promise settles.
|
|
62
67
|
val handler: (TrackLoadEvent) -> Promise<Promise<Unit>> = { event ->
|
|
63
68
|
val inner = JsPromise<Unit>()
|
|
64
69
|
val outer = JsPromise<Promise<Unit>>()
|
|
65
70
|
Handler(Looper.getMainLooper()).post {
|
|
66
|
-
onLoad(event
|
|
71
|
+
onLoad(event)
|
|
67
72
|
setsAfterHandler = 0
|
|
68
73
|
inner.resolve(Unit)
|
|
69
74
|
outer.resolve(inner.promise)
|
|
@@ -105,10 +110,10 @@ class HandleTrackLoadSeekTest {
|
|
|
105
110
|
}
|
|
106
111
|
|
|
107
112
|
/**
|
|
108
|
-
* As a controller starts a track
|
|
109
|
-
* media3 has set the items the callback returned, after the handler.
|
|
113
|
+
* As a controller starts a track, at [positionMs] when given; without one media3 passes no index
|
|
114
|
+
* or position. Returns once media3 has set the items the callback returned, after the handler.
|
|
110
115
|
*/
|
|
111
|
-
private fun setFromController(track: Track) {
|
|
116
|
+
private fun setFromController(track: Track, positionMs: Long? = null) {
|
|
112
117
|
player.exoPlayer.addListener(
|
|
113
118
|
object : MediaPlayer.Listener {
|
|
114
119
|
override fun onTimelineChanged(timeline: Timeline, reason: Int) {
|
|
@@ -122,7 +127,9 @@ class HandleTrackLoadSeekTest {
|
|
|
122
127
|
MediaController.Builder(RuntimeEnvironment.getApplication(), service.get().session.token)
|
|
123
128
|
.buildAsync()
|
|
124
129
|
idleUntil("the controller to connect") { future.isDone }
|
|
125
|
-
|
|
130
|
+
val item = TrackFactory.toMedia3(track)
|
|
131
|
+
if (positionMs == null) future.get().setMediaItem(item)
|
|
132
|
+
else future.get().setMediaItem(item, positionMs)
|
|
126
133
|
idleUntil("media3 to set the items") { (setsAfterHandler ?: 0) >= 1 }
|
|
127
134
|
}
|
|
128
135
|
|
|
@@ -143,7 +150,7 @@ class HandleTrackLoadSeekTest {
|
|
|
143
150
|
fun `a load then a seek in the handler holds the seek`() {
|
|
144
151
|
val track = silentTrack(Duration.ofMinutes(2))
|
|
145
152
|
handlingTrackLoadWith {
|
|
146
|
-
player.load(it)
|
|
153
|
+
player.load(it.track)
|
|
147
154
|
player.seekTo(60, TimeUnit.SECONDS)
|
|
148
155
|
}
|
|
149
156
|
|
|
@@ -155,13 +162,67 @@ class HandleTrackLoadSeekTest {
|
|
|
155
162
|
@Test
|
|
156
163
|
fun `a setQueue at a position in the handler holds the position`() {
|
|
157
164
|
val track = silentTrack(Duration.ofMinutes(2))
|
|
158
|
-
handlingTrackLoadWith { player.setQueue(arrayOf(it), 0, 60_000) }
|
|
165
|
+
handlingTrackLoadWith { player.setQueue(arrayOf(it.track), 0, 60_000) }
|
|
159
166
|
|
|
160
167
|
setFromController(track)
|
|
161
168
|
|
|
162
169
|
assertEquals(60_000L, player.exoPlayer.currentPosition)
|
|
163
170
|
}
|
|
164
171
|
|
|
172
|
+
@Test
|
|
173
|
+
fun `a controller's start position reaches the handler in seconds`() {
|
|
174
|
+
var startPosition: Double? = null
|
|
175
|
+
handlingTrackLoadWith {
|
|
176
|
+
startPosition = it.startPosition
|
|
177
|
+
player.load(it.track)
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
setFromController(silentTrack(Duration.ofMinutes(2)), positionMs = 45_500)
|
|
181
|
+
|
|
182
|
+
assertEquals(45.5, startPosition)
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
@Test
|
|
186
|
+
fun `a controller that asks for no position leaves the start position absent`() {
|
|
187
|
+
var event: TrackLoadEvent? = null
|
|
188
|
+
handlingTrackLoadWith {
|
|
189
|
+
event = it
|
|
190
|
+
player.load(it.track)
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
setFromController(silentTrack(Duration.ofMinutes(2)))
|
|
194
|
+
|
|
195
|
+
assertNotNull(event)
|
|
196
|
+
assertNull(event?.startPosition)
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
@Test
|
|
200
|
+
fun `a controller that resets the position gives the handler the first index`() {
|
|
201
|
+
var startIndex: Double? = null
|
|
202
|
+
handlingTrackLoadWith {
|
|
203
|
+
startIndex = it.startIndex
|
|
204
|
+
player.load(it.track)
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
setFromController(silentTrack(Duration.ofMinutes(2)))
|
|
208
|
+
|
|
209
|
+
assertEquals(0.0, startIndex)
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
@Test
|
|
213
|
+
fun `a handler that seeks to the start position starts playback there`() {
|
|
214
|
+
handlingTrackLoadWith {
|
|
215
|
+
player.load(it.track)
|
|
216
|
+
it.startPosition?.let { position ->
|
|
217
|
+
player.seekTo((position * 1000).toLong(), TimeUnit.MILLISECONDS)
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
setFromController(silentTrack(Duration.ofMinutes(2)), positionMs = 45_000)
|
|
222
|
+
|
|
223
|
+
assertEquals(45_000L, player.exoPlayer.currentPosition)
|
|
224
|
+
}
|
|
225
|
+
|
|
165
226
|
@Test
|
|
166
227
|
fun `an ended track a handler leaves is set again at its start`() {
|
|
167
228
|
val track = silentTrack(Duration.ofMillis(500))
|
|
@@ -82,7 +82,9 @@ class RetryMaskingTest {
|
|
|
82
82
|
|
|
83
83
|
@Test
|
|
84
84
|
fun `the loop reconnects, and its idle engine and error reach no surface`() {
|
|
85
|
-
|
|
85
|
+
// The clock outruns a connection's real I/O: a slow one would bring a give-up into the test.
|
|
86
|
+
val noGiveUp = Duration.ofHours(1).toMillis()
|
|
87
|
+
play("http://127.0.0.1:${server.localPort}/live.mp3", RetryPolicy.Infinite(noGiveUp, noGiveUp))
|
|
86
88
|
var held = 0
|
|
87
89
|
stepUntil("the loop holding the idle engine a while") {
|
|
88
90
|
if (player.exoPlayer.playbackState == MediaPlayer.STATE_IDLE) {
|
|
@@ -3,6 +3,7 @@ package com.audiobrowser.sonos
|
|
|
3
3
|
import android.Manifest
|
|
4
4
|
import android.content.ComponentName
|
|
5
5
|
import android.content.pm.PackageManager
|
|
6
|
+
import androidx.mediarouter.media.MediaRouteProvider
|
|
6
7
|
import androidx.mediarouter.media.MediaRouter
|
|
7
8
|
import com.audiobrowser.RemoteOutputs
|
|
8
9
|
import org.junit.After
|
|
@@ -57,6 +58,16 @@ class SonosRoutesTest {
|
|
|
57
58
|
}
|
|
58
59
|
}
|
|
59
60
|
|
|
61
|
+
@Test
|
|
62
|
+
fun `publishes the rooms with restricted visibility`() {
|
|
63
|
+
val routes = sonosRouteDescriptors(listOf(dining, living), null) { null }.routes
|
|
64
|
+
|
|
65
|
+
for (route in routes) {
|
|
66
|
+
assertFalse(route.isVisibilityPublic)
|
|
67
|
+
assertEquals(emptySet<String>(), route.allowedPackages)
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
60
71
|
@Test
|
|
61
72
|
fun `reports the selected room connected, and only that one`() {
|
|
62
73
|
val routes = sonosRouteDescriptors(listOf(dining, living), "RINCON_C") { null }.routes
|
|
@@ -91,6 +102,27 @@ class SonosRoutesTest {
|
|
|
91
102
|
provider.release()
|
|
92
103
|
}
|
|
93
104
|
|
|
105
|
+
@Test
|
|
106
|
+
fun `serves a session for this app, and refuses one for another app`() {
|
|
107
|
+
val context = RuntimeEnvironment.getApplication()
|
|
108
|
+
SonosOutputs.select(living)
|
|
109
|
+
val provider = SonosRouteProvider(context)
|
|
110
|
+
SonosOutputs.unselect(living)
|
|
111
|
+
|
|
112
|
+
fun controllerFor(packageName: String) =
|
|
113
|
+
provider.onCreateRouteController(
|
|
114
|
+
"RINCON_C",
|
|
115
|
+
MediaRouteProvider.RouteControllerOptions.Builder()
|
|
116
|
+
.setClientPackageName(packageName)
|
|
117
|
+
.build(),
|
|
118
|
+
)
|
|
119
|
+
|
|
120
|
+
assertNull(controllerFor("com.example.other"))
|
|
121
|
+
controllerFor(context.packageName)!!.onSelect()
|
|
122
|
+
assertEquals(living, SonosOutputs.selected)
|
|
123
|
+
provider.release()
|
|
124
|
+
}
|
|
125
|
+
|
|
94
126
|
@Test
|
|
95
127
|
fun `a late unselect of a room left behind keeps the room selected since`() {
|
|
96
128
|
SonosOutputs.select(dining)
|
package/ios/TrackSelector.swift
CHANGED
|
@@ -67,7 +67,12 @@ class TrackSelector {
|
|
|
67
67
|
return .none
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
let event = TrackLoadEvent(
|
|
70
|
+
let event = TrackLoadEvent(
|
|
71
|
+
track: track,
|
|
72
|
+
queue: playback.queue,
|
|
73
|
+
startIndex: Double(playback.index),
|
|
74
|
+
startPosition: nil,
|
|
75
|
+
)
|
|
71
76
|
if await browserManager.awaitTrackLoadHandler(event: event) {
|
|
72
77
|
return .intercepted
|
|
73
78
|
}
|
|
@@ -11,6 +11,12 @@ export interface TrackLoadEvent {
|
|
|
11
11
|
queue: Track[];
|
|
12
12
|
/** The index of the track in the queue */
|
|
13
13
|
startIndex: number;
|
|
14
|
+
/**
|
|
15
|
+
* Where an Android media controller asked playback to start, in seconds: the
|
|
16
|
+
* player's current position when it asked to keep it, absent when it asked to
|
|
17
|
+
* reset or sent none.
|
|
18
|
+
*/
|
|
19
|
+
startPosition?: number;
|
|
14
20
|
}
|
|
15
21
|
/**
|
|
16
22
|
* Callback for handling track load events.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../../src/types/browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,oBAAoB,CAAA;AACzD,OAAO,KAAK,EAAE,aAAa,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAE9D;;;GAGG;AACH,MAAM,WAAW,cAAc;IAC7B,oCAAoC;IACpC,KAAK,EAAE,KAAK,CAAA;IACZ,mCAAmC;IACnC,KAAK,EAAE,KAAK,EAAE,CAAA;IACd,0CAA0C;IAC1C,UAAU,EAAE,MAAM,CAAA;
|
|
1
|
+
{"version":3,"file":"browser.d.ts","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;;;;;;;GAyBG;AACH,MAAM,MAAM,6BAA6B,GAAG,CAC1C,MAAM,EAAE,2BAA2B,KAChC,wBAAwB,GAAG,SAAS,CAAA;AAEzC;;;GAGG;AACH,MAAM,MAAM,wBAAwB,GAAG,CAAC,KAAK,EAAE,KAAK,KAAK,MAAM,GAAG,SAAS,CAAA;AAE3E,+EAA+E;AAC/E,MAAM,MAAM,qBAAqB,GAAG,MAAM,MAAM,CAAA"}
|
|
@@ -62,6 +62,8 @@ namespace margelo::nitro::audiobrowser {
|
|
|
62
62
|
jni::local_ref<jni::JArrayClass<JTrack>> queue = this->getFieldValue(fieldQueue);
|
|
63
63
|
static const auto fieldStartIndex = clazz->getField<double>("startIndex");
|
|
64
64
|
double startIndex = this->getFieldValue(fieldStartIndex);
|
|
65
|
+
static const auto fieldStartPosition = clazz->getField<jni::JDouble>("startPosition");
|
|
66
|
+
jni::local_ref<jni::JDouble> startPosition = this->getFieldValue(fieldStartPosition);
|
|
65
67
|
return TrackLoadEvent(
|
|
66
68
|
track->toCpp(),
|
|
67
69
|
[&](auto&& __input) {
|
|
@@ -74,7 +76,8 @@ namespace margelo::nitro::audiobrowser {
|
|
|
74
76
|
}
|
|
75
77
|
return __vector;
|
|
76
78
|
}(queue),
|
|
77
|
-
startIndex
|
|
79
|
+
startIndex,
|
|
80
|
+
startPosition != nullptr ? std::make_optional(startPosition->value()) : std::nullopt
|
|
78
81
|
);
|
|
79
82
|
}
|
|
80
83
|
|
|
@@ -84,7 +87,7 @@ namespace margelo::nitro::audiobrowser {
|
|
|
84
87
|
*/
|
|
85
88
|
[[maybe_unused]]
|
|
86
89
|
static jni::local_ref<JTrackLoadEvent::javaobject> fromCpp(const TrackLoadEvent& value) {
|
|
87
|
-
using JSignature = JTrackLoadEvent(jni::alias_ref<JTrack>, jni::alias_ref<jni::JArrayClass<JTrack>>, double);
|
|
90
|
+
using JSignature = JTrackLoadEvent(jni::alias_ref<JTrack>, jni::alias_ref<jni::JArrayClass<JTrack>>, double, jni::alias_ref<jni::JDouble>);
|
|
88
91
|
static const auto clazz = javaClassStatic();
|
|
89
92
|
static const auto create = clazz->getStaticMethod<JSignature>("fromCpp");
|
|
90
93
|
return create(
|
|
@@ -100,7 +103,8 @@ namespace margelo::nitro::audiobrowser {
|
|
|
100
103
|
}
|
|
101
104
|
return __array;
|
|
102
105
|
}(value.queue),
|
|
103
|
-
value.startIndex
|
|
106
|
+
value.startIndex,
|
|
107
|
+
value.startPosition.has_value() ? jni::JDouble::valueOf(value.startPosition.value()) : nullptr
|
|
104
108
|
);
|
|
105
109
|
}
|
|
106
110
|
};
|
|
@@ -26,7 +26,10 @@ data class TrackLoadEvent(
|
|
|
26
26
|
val queue: Array<Track>,
|
|
27
27
|
@DoNotStrip
|
|
28
28
|
@Keep
|
|
29
|
-
val startIndex: Double
|
|
29
|
+
val startIndex: Double,
|
|
30
|
+
@DoNotStrip
|
|
31
|
+
@Keep
|
|
32
|
+
val startPosition: Double?
|
|
30
33
|
) {
|
|
31
34
|
/* primary constructor */
|
|
32
35
|
|
|
@@ -36,13 +39,15 @@ data class TrackLoadEvent(
|
|
|
36
39
|
return Objects.deepEquals(this.track, other.track)
|
|
37
40
|
&& Objects.deepEquals(this.queue, other.queue)
|
|
38
41
|
&& Objects.deepEquals(this.startIndex, other.startIndex)
|
|
42
|
+
&& Objects.deepEquals(this.startPosition, other.startPosition)
|
|
39
43
|
}
|
|
40
44
|
|
|
41
45
|
override fun hashCode(): Int {
|
|
42
46
|
return arrayOf<Any?>(
|
|
43
47
|
track,
|
|
44
48
|
queue,
|
|
45
|
-
startIndex
|
|
49
|
+
startIndex,
|
|
50
|
+
startPosition
|
|
46
51
|
).contentDeepHashCode()
|
|
47
52
|
}
|
|
48
53
|
|
|
@@ -54,8 +59,8 @@ data class TrackLoadEvent(
|
|
|
54
59
|
@Keep
|
|
55
60
|
@Suppress("unused")
|
|
56
61
|
@JvmStatic
|
|
57
|
-
private fun fromCpp(track: Track, queue: Array<Track>, startIndex: Double): TrackLoadEvent {
|
|
58
|
-
return TrackLoadEvent(track, queue, startIndex)
|
|
62
|
+
private fun fromCpp(track: Track, queue: Array<Track>, startIndex: Double, startPosition: Double?): TrackLoadEvent {
|
|
63
|
+
return TrackLoadEvent(track, queue, startIndex, startPosition)
|
|
59
64
|
}
|
|
60
65
|
}
|
|
61
66
|
}
|
|
@@ -18,14 +18,20 @@ public extension TrackLoadEvent {
|
|
|
18
18
|
/**
|
|
19
19
|
* Create a new instance of `TrackLoadEvent`.
|
|
20
20
|
*/
|
|
21
|
-
init(track: Track, queue: [Track], startIndex: Double) {
|
|
21
|
+
init(track: Track, queue: [Track], startIndex: Double, startPosition: Double?) {
|
|
22
22
|
self.init(track, { () -> bridge.std__vector_Track_ in
|
|
23
23
|
var __vector = bridge.create_std__vector_Track_(queue.count)
|
|
24
24
|
for __item in queue {
|
|
25
25
|
__vector.push_back(__item)
|
|
26
26
|
}
|
|
27
27
|
return __vector
|
|
28
|
-
}(), startIndex)
|
|
28
|
+
}(), startIndex, { () -> bridge.std__optional_double_ in
|
|
29
|
+
if let __unwrappedValue = startPosition {
|
|
30
|
+
return bridge.create_std__optional_double_(__unwrappedValue)
|
|
31
|
+
} else {
|
|
32
|
+
return .init()
|
|
33
|
+
}
|
|
34
|
+
}())
|
|
29
35
|
}
|
|
30
36
|
|
|
31
37
|
@inline(__always)
|
|
@@ -42,4 +48,16 @@ public extension TrackLoadEvent {
|
|
|
42
48
|
var startIndex: Double {
|
|
43
49
|
return self.__startIndex
|
|
44
50
|
}
|
|
51
|
+
|
|
52
|
+
@inline(__always)
|
|
53
|
+
var startPosition: Double? {
|
|
54
|
+
return { () -> Double? in
|
|
55
|
+
if bridge.has_value_std__optional_double_(self.__startPosition) {
|
|
56
|
+
let __unwrapped = bridge.get_std__optional_double_(self.__startPosition)
|
|
57
|
+
return __unwrapped
|
|
58
|
+
} else {
|
|
59
|
+
return nil
|
|
60
|
+
}
|
|
61
|
+
}()
|
|
62
|
+
}
|
|
45
63
|
}
|
|
@@ -33,6 +33,7 @@ namespace margelo::nitro::audiobrowser { struct Track; }
|
|
|
33
33
|
|
|
34
34
|
#include "Track.hpp"
|
|
35
35
|
#include <vector>
|
|
36
|
+
#include <optional>
|
|
36
37
|
|
|
37
38
|
namespace margelo::nitro::audiobrowser {
|
|
38
39
|
|
|
@@ -44,10 +45,11 @@ namespace margelo::nitro::audiobrowser {
|
|
|
44
45
|
Track track SWIFT_PRIVATE;
|
|
45
46
|
std::vector<Track> queue SWIFT_PRIVATE;
|
|
46
47
|
double startIndex SWIFT_PRIVATE;
|
|
48
|
+
std::optional<double> startPosition SWIFT_PRIVATE;
|
|
47
49
|
|
|
48
50
|
public:
|
|
49
51
|
TrackLoadEvent() = default;
|
|
50
|
-
explicit TrackLoadEvent(Track track, std::vector<Track> queue, double startIndex): track(track), queue(queue), startIndex(startIndex) {}
|
|
52
|
+
explicit TrackLoadEvent(Track track, std::vector<Track> queue, double startIndex, std::optional<double> startPosition): track(track), queue(queue), startIndex(startIndex), startPosition(startPosition) {}
|
|
51
53
|
|
|
52
54
|
public:
|
|
53
55
|
friend bool operator==(const TrackLoadEvent& lhs, const TrackLoadEvent& rhs) = default;
|
|
@@ -65,7 +67,8 @@ namespace margelo::nitro {
|
|
|
65
67
|
return margelo::nitro::audiobrowser::TrackLoadEvent(
|
|
66
68
|
JSIConverter<margelo::nitro::audiobrowser::Track>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "track"))),
|
|
67
69
|
JSIConverter<std::vector<margelo::nitro::audiobrowser::Track>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "queue"))),
|
|
68
|
-
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startIndex")))
|
|
70
|
+
JSIConverter<double>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startIndex"))),
|
|
71
|
+
JSIConverter<std::optional<double>>::fromJSI(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startPosition")))
|
|
69
72
|
);
|
|
70
73
|
}
|
|
71
74
|
static inline jsi::Value toJSI(jsi::Runtime& runtime, const margelo::nitro::audiobrowser::TrackLoadEvent& arg) {
|
|
@@ -73,6 +76,7 @@ namespace margelo::nitro {
|
|
|
73
76
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "track"), JSIConverter<margelo::nitro::audiobrowser::Track>::toJSI(runtime, arg.track));
|
|
74
77
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "queue"), JSIConverter<std::vector<margelo::nitro::audiobrowser::Track>>::toJSI(runtime, arg.queue));
|
|
75
78
|
obj.setProperty(runtime, PropNameIDCache::get(runtime, "startIndex"), JSIConverter<double>::toJSI(runtime, arg.startIndex));
|
|
79
|
+
obj.setProperty(runtime, PropNameIDCache::get(runtime, "startPosition"), JSIConverter<std::optional<double>>::toJSI(runtime, arg.startPosition));
|
|
76
80
|
return obj;
|
|
77
81
|
}
|
|
78
82
|
static inline bool canConvert(jsi::Runtime& runtime, const jsi::Value& value) {
|
|
@@ -86,6 +90,7 @@ namespace margelo::nitro {
|
|
|
86
90
|
if (!JSIConverter<margelo::nitro::audiobrowser::Track>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "track")))) return false;
|
|
87
91
|
if (!JSIConverter<std::vector<margelo::nitro::audiobrowser::Track>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "queue")))) return false;
|
|
88
92
|
if (!JSIConverter<double>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startIndex")))) return false;
|
|
93
|
+
if (!JSIConverter<std::optional<double>>::canConvert(runtime, obj.getProperty(runtime, PropNameIDCache::get(runtime, "startPosition")))) return false;
|
|
89
94
|
return true;
|
|
90
95
|
}
|
|
91
96
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-audio-browser",
|
|
3
|
-
"version": "0.2.0-next.
|
|
3
|
+
"version": "0.2.0-next.91",
|
|
4
4
|
"description": "react-native-audio-browser is a react native package built with Nitro",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"react-native",
|
|
@@ -70,6 +70,7 @@
|
|
|
70
70
|
"ios:test": "swift test --disable-sandbox",
|
|
71
71
|
"lint": "oxlint --fix",
|
|
72
72
|
"release": "semantic-release",
|
|
73
|
+
"stream-cases": "node scripts/stream-cases/index.ts",
|
|
73
74
|
"stream-server": "node scripts/stream-server/index.ts",
|
|
74
75
|
"test": "vitest run",
|
|
75
76
|
"types": "tsc --noEmit",
|
package/src/types/browser.ts
CHANGED
|
@@ -12,6 +12,12 @@ export interface TrackLoadEvent {
|
|
|
12
12
|
queue: Track[]
|
|
13
13
|
/** The index of the track in the queue */
|
|
14
14
|
startIndex: number
|
|
15
|
+
/**
|
|
16
|
+
* Where an Android media controller asked playback to start, in seconds: the
|
|
17
|
+
* player's current position when it asked to keep it, absent when it asked to
|
|
18
|
+
* reset or sent none.
|
|
19
|
+
*/
|
|
20
|
+
startPosition?: number
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
/**
|
|
@@ -114,6 +114,25 @@ Kotlin), in its control filters. Only the
|
|
|
114
114
|
selection is reported: the library keeps playing locally, and rendering the
|
|
115
115
|
audio on the speaker is the provider's job.
|
|
116
116
|
|
|
117
|
+
`RemoteOutputs.routeDescriptorBuilder(id, name)` starts a route's descriptor
|
|
118
|
+
in the category and visible only to the app, from Android 14. Another app on the
|
|
119
|
+
library would otherwise list the route too, and report it as its output while
|
|
120
|
+
its own playback stays on the phone:
|
|
121
|
+
|
|
122
|
+
```kotlin
|
|
123
|
+
val speaker =
|
|
124
|
+
RemoteOutputs.routeDescriptorBuilder("kitchen", "Kitchen")
|
|
125
|
+
.setPlaybackType(MediaRouter.RouteInfo.PLAYBACK_TYPE_REMOTE)
|
|
126
|
+
.setDeviceType(MediaRouter.RouteInfo.DEVICE_TYPE_SPEAKER)
|
|
127
|
+
.setEnabled(true)
|
|
128
|
+
.build()
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
Before Android 14 every app lists the route regardless. A provider that serves
|
|
132
|
+
only its own app returns `null` from `onCreateRouteController(routeId, options)`
|
|
133
|
+
when `options.clientPackageName` is another package, as the library's Sonos
|
|
134
|
+
provider does: the other app's switch then fails.
|
|
135
|
+
|
|
117
136
|
### Google Cast (Android)
|
|
118
137
|
|
|
119
138
|
With `remoteOutputs: { cast: true }`, selecting a Cast device in the switcher
|
|
@@ -291,8 +310,14 @@ Cast and Sonos play the queue the same way:
|
|
|
291
310
|
Playing again loads the item there anew.
|
|
292
311
|
|
|
293
312
|
The library's Sonos route provider service is exported, as the Output Switcher
|
|
294
|
-
needs to bind it: another app on the phone can bind it too
|
|
295
|
-
|
|
313
|
+
needs to bind it: another app on the phone can bind it too and list the rooms,
|
|
314
|
+
but the provider serves only the app's own sessions, so another app can't
|
|
315
|
+
select a room. Only an app that bypasses Android's hidden-API restrictions can
|
|
316
|
+
still set the volume of a room the app plays to.
|
|
317
|
+
|
|
318
|
+
When a Sonos room that another app's provider serves is selected, the library
|
|
319
|
+
unselects it: the output stays the phone, and the switcher stops offering
|
|
320
|
+
**Stop casting** for it.
|
|
296
321
|
|
|
297
322
|
## Opening the output picker
|
|
298
323
|
|
package/website/guide/browser.md
CHANGED
|
@@ -447,14 +447,14 @@ Tapping a row that's already in the current queue from the same page skips in pl
|
|
|
447
447
|
import { configureBrowser, setQueue, play } from 'react-native-audio-browser'
|
|
448
448
|
|
|
449
449
|
configureBrowser({
|
|
450
|
-
handleTrackLoad: async ({ track, queue, startIndex }) => {
|
|
450
|
+
handleTrackLoad: async ({ track, queue, startIndex, startPosition }) => {
|
|
451
451
|
if (isVideo(track)) {
|
|
452
452
|
// your surface — return without touching the player; audio stays put
|
|
453
453
|
openVideoPlayer(track)
|
|
454
454
|
return
|
|
455
455
|
}
|
|
456
456
|
// audio: drive playback yourself — the library won't auto-play
|
|
457
|
-
setQueue(queue, startIndex)
|
|
457
|
+
setQueue(queue, startIndex, startPosition)
|
|
458
458
|
play()
|
|
459
459
|
}
|
|
460
460
|
})
|