react-native-audio-browser 1.0.0-next.2 → 1.0.0-next.4
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/cast/java/com/audiobrowser/cast/CastSupport.kt +37 -14
- package/android/src/main/java/com/audiobrowser/AudioBrowser.kt +38 -10
- package/android/src/main/java/com/audiobrowser/Service.kt +6 -41
- package/android/src/main/java/com/audiobrowser/browser/BrowserManager.kt +40 -34
- package/android/src/main/java/com/audiobrowser/browser/BrowserUrlResolution.kt +6 -5
- package/android/src/main/java/com/audiobrowser/browser/JsonModels.kt +12 -7
- package/android/src/main/java/com/audiobrowser/extension/QueueIndex.kt +19 -0
- package/android/src/main/java/com/audiobrowser/http/HttpClient.kt +2 -1
- package/android/src/main/java/com/audiobrowser/http/RequestConfigBuilder.kt +32 -18
- package/android/src/main/java/com/audiobrowser/model/PlayerSetupOptions.kt +2 -2
- package/android/src/main/java/com/audiobrowser/player/AutomaticBufferManager.kt +17 -16
- package/android/src/main/java/com/audiobrowser/player/InterceptingPlayer.kt +11 -0
- package/android/src/main/java/com/audiobrowser/player/MediaFactory.kt +5 -1
- package/android/src/main/java/com/audiobrowser/player/MediaSessionCallback.kt +28 -21
- package/android/src/main/java/com/audiobrowser/player/Player.kt +41 -31
- package/android/src/main/java/com/audiobrowser/player/PlayerListener.kt +4 -0
- package/android/src/main/java/com/audiobrowser/player/ResolvingOnReloadSource.kt +38 -0
- package/android/src/main/java/com/audiobrowser/player/TransformingDataSource.kt +34 -19
- package/android/src/main/java/com/audiobrowser/remote/RemotePlayback.kt +10 -1
- package/android/src/main/java/com/audiobrowser/remote/RemoteSwitchingPlayer.kt +48 -4
- package/android/src/main/java/com/audiobrowser/util/BrowserPathHelper.kt +32 -34
- package/android/src/main/java/com/audiobrowser/util/SearchParamsFactory.kt +64 -0
- package/android/src/test/java/com/audiobrowser/ContentRefreshNavigationErrorTest.kt +236 -0
- package/android/src/test/java/com/audiobrowser/NavigateTrackTest.kt +116 -0
- package/android/src/test/java/com/audiobrowser/TestFixtures.kt +41 -0
- package/android/src/test/java/com/audiobrowser/browser/BrowserManagerBuildApiRequestTest.kt +21 -4
- package/android/src/test/java/com/audiobrowser/browser/BrowserManagerFavoritesTest.kt +49 -0
- package/android/src/test/java/com/audiobrowser/browser/BrowserManagerPageShapeTest.kt +93 -0
- package/android/src/test/java/com/audiobrowser/browser/BrowserManagerUnparsableResponseTest.kt +82 -0
- package/android/src/test/java/com/audiobrowser/browser/BrowserUrlResolutionTest.kt +27 -0
- package/android/src/test/java/com/audiobrowser/browser/JsonArtworkTest.kt +7 -1
- package/android/src/test/java/com/audiobrowser/browser/JsonFavoritedTest.kt +34 -0
- package/android/src/test/java/com/audiobrowser/browser/JsonStyleTest.kt +6 -6
- package/android/src/test/java/com/audiobrowser/extension/QueueIndexTest.kt +44 -0
- package/android/src/test/java/com/audiobrowser/http/HttpClientTest.kt +34 -0
- package/android/src/test/java/com/audiobrowser/http/RequestConfigBuilderTest.kt +90 -7
- package/android/src/test/java/com/audiobrowser/model/PlayerSetupOptionsTest.kt +19 -2
- package/android/src/test/java/com/audiobrowser/player/AutomaticBufferManagerTest.kt +17 -0
- package/android/src/test/java/com/audiobrowser/player/FavoriteCapabilityTest.kt +41 -0
- package/android/src/test/java/com/audiobrowser/player/MediaFactoryTest.kt +39 -0
- package/android/src/test/java/com/audiobrowser/player/MediaUrlReloadTest.kt +212 -0
- package/android/src/test/java/com/audiobrowser/player/PlayerSeekSnapshotTest.kt +45 -0
- package/android/src/test/java/com/audiobrowser/player/SessionQueueShuffleOrderTest.kt +38 -0
- package/android/src/test/java/com/audiobrowser/player/SessionVoiceSearchTest.kt +173 -0
- package/android/src/test/java/com/audiobrowser/player/TransformingDataSourceTest.kt +127 -1
- package/android/src/test/java/com/audiobrowser/remote/FakeRemote.kt +28 -0
- package/android/src/test/java/com/audiobrowser/remote/RemoteSwitchingPlayerTest.kt +116 -0
- package/android/src/test/java/com/audiobrowser/util/BrowserPathHelperTest.kt +44 -0
- package/android/src/testCast/java/com/audiobrowser/cast/SdkCastRemoteTest.kt +188 -0
- package/ios/Browser/BrowserError.swift +8 -0
- package/ios/Browser/BrowserManager.swift +29 -28
- package/ios/Browser/BrowserPathHelper.swift +26 -24
- package/ios/Browser/FavoriteSet.swift +16 -8
- package/ios/Browser/Favorites.swift +66 -0
- package/ios/Browser/JsonModels.swift +27 -7
- package/ios/Browser/NavigationErrorState.swift +18 -1
- package/ios/Browser/PageResolver.swift +2 -2
- package/ios/Browser/RequestLayer.swift +11 -4
- package/ios/Browser/RequestPipeline.swift +8 -4
- package/ios/Browser/TabBarEntries.swift +7 -0
- package/ios/CarPlay/CarPlayImageLoader.swift +3 -7
- package/ios/CarPlay/CarPlaySession+Navigator.swift +3 -1
- package/ios/CarPlay/IntentHandlers.swift +1 -7
- package/ios/CarPlay/MediaIntentCriteria.swift +4 -4
- package/ios/Extension/CGSize+AspectFit.swift +11 -0
- package/ios/Extension/Dictionary+Headers.swift +8 -0
- package/ios/Extension/NavigationError+Conversion.swift +4 -3
- package/ios/Extension/ResolvedTrack+Copying.swift +15 -0
- package/ios/Http/HttpClient.swift +37 -11
- package/ios/HybridAudioBrowser+Browser.swift +9 -16
- package/ios/HybridAudioBrowser+Options.swift +1 -0
- package/ios/HybridAudioBrowser+Player.swift +24 -23
- package/ios/HybridAudioBrowser+PlayerCallbacks.swift +1 -2
- package/ios/Model/NitroTypeStubs.swift +39 -0
- package/ios/Model/TrackPlayerError.swift +21 -2
- package/ios/Player/AudioSessionController.swift +2 -2
- package/ios/Player/MediaLoader.swift +1 -1
- package/ios/Player/PlaybackStateMachine.swift +1 -2
- package/ios/Player/Player.swift +59 -20
- package/ios/Player/PlayerEngine.swift +5 -0
- package/ios/Player/QueueManager.swift +21 -4
- package/ios/Tests/BrowserErrorTests.swift +21 -0
- package/ios/Tests/BrowserPathHelperTests.swift +18 -0
- package/ios/Tests/CGSizeAspectFitTests.swift +36 -0
- package/ios/Tests/ClampedVolumeTests.swift +26 -0
- package/ios/Tests/FavoriteSetTests.swift +68 -3
- package/ios/Tests/FavoritesTests.swift +102 -0
- package/ios/Tests/HttpClientUserAgentTests.swift +45 -0
- package/ios/Tests/JsonModelsTests.swift +74 -6
- package/ios/Tests/MediaIntentCriteriaTests.swift +11 -1
- package/ios/Tests/MediaLoaderAssetOptionsTests.swift +7 -0
- package/ios/Tests/NavigationErrorStateTests.swift +73 -0
- package/ios/Tests/PlaybackStateMachineTests.swift +6 -4
- package/ios/Tests/PlayerPolicyTests.swift +38 -0
- package/ios/Tests/PlayerProgressTests.swift +109 -0
- package/ios/Tests/PlayerTests.swift +106 -0
- package/ios/Tests/QueueIndexTests.swift +43 -0
- package/ios/Tests/QueueManagerTests.swift +79 -15
- package/ios/Tests/RequestLayerTests.swift +22 -3
- package/ios/Tests/TabBarEntriesTests.swift +19 -0
- package/ios/Tests/TrackSelectorTests.swift +154 -0
- package/ios/Tests/UnparsableResponseTests.swift +91 -0
- package/ios/TrackSelector.swift +28 -8
- package/ios/Util/ArtworkImageFetcher.swift +9 -8
- package/ios/Util/SVGProcessor.swift +6 -17
- package/lib/commonjs/features/browser-config.js +6 -3
- package/lib/commonjs/features/browser-config.js.map +1 -1
- package/lib/commonjs/features/errors.js +12 -7
- package/lib/commonjs/features/errors.js.map +1 -1
- package/lib/commonjs/features/nowPlaying.js +9 -3
- package/lib/commonjs/features/nowPlaying.js.map +1 -1
- package/lib/commonjs/features/playback/controls.js +1 -2
- package/lib/commonjs/features/playback/controls.js.map +1 -1
- package/lib/commonjs/features/playback/trackPlaybackTime.js +2 -1
- package/lib/commonjs/features/playback/trackPlaybackTime.js.map +1 -1
- package/lib/commonjs/features/player/setup.js +2 -2
- package/lib/commonjs/features/queue/activeTrack.js +4 -2
- package/lib/commonjs/features/queue/activeTrack.js.map +1 -1
- package/lib/commonjs/features/sleepTimer.js +6 -5
- package/lib/commonjs/features/sleepTimer.js.map +1 -1
- package/lib/commonjs/utils/LazyNativeEmitter.js +2 -1
- package/lib/commonjs/utils/LazyNativeEmitter.js.map +1 -1
- package/lib/commonjs/utils/NativeUpdatedValue.js +2 -1
- package/lib/commonjs/utils/NativeUpdatedValue.js.map +1 -1
- package/lib/commonjs/utils/callListener.js +23 -0
- package/lib/commonjs/utils/callListener.js.map +1 -0
- package/lib/module/features/browser-config.js +6 -3
- package/lib/module/features/browser-config.js.map +1 -1
- package/lib/module/features/errors.js +12 -7
- package/lib/module/features/errors.js.map +1 -1
- package/lib/module/features/nowPlaying.js +9 -3
- package/lib/module/features/nowPlaying.js.map +1 -1
- package/lib/module/features/playback/controls.js +1 -2
- package/lib/module/features/playback/controls.js.map +1 -1
- package/lib/module/features/playback/trackPlaybackTime.js +2 -1
- package/lib/module/features/playback/trackPlaybackTime.js.map +1 -1
- package/lib/module/features/player/setup.js +2 -2
- package/lib/module/features/queue/activeTrack.js +4 -2
- package/lib/module/features/queue/activeTrack.js.map +1 -1
- package/lib/module/features/sleepTimer.js +6 -5
- package/lib/module/features/sleepTimer.js.map +1 -1
- package/lib/module/utils/LazyNativeEmitter.js +2 -1
- package/lib/module/utils/LazyNativeEmitter.js.map +1 -1
- package/lib/module/utils/NativeUpdatedValue.js +2 -1
- package/lib/module/utils/NativeUpdatedValue.js.map +1 -1
- package/lib/module/utils/callListener.js +19 -0
- package/lib/module/utils/callListener.js.map +1 -0
- package/lib/typescript/src/features/browser-config.d.ts.map +1 -1
- package/lib/typescript/src/features/errors.d.ts +8 -6
- package/lib/typescript/src/features/errors.d.ts.map +1 -1
- package/lib/typescript/src/features/nowPlaying.d.ts +2 -1
- package/lib/typescript/src/features/nowPlaying.d.ts.map +1 -1
- package/lib/typescript/src/features/playback/controls.d.ts +1 -2
- package/lib/typescript/src/features/playback/controls.d.ts.map +1 -1
- package/lib/typescript/src/features/playback/trackPlaybackTime.d.ts.map +1 -1
- package/lib/typescript/src/features/player/setup.d.ts +2 -2
- package/lib/typescript/src/features/queue/activeTrack.d.ts +2 -1
- package/lib/typescript/src/features/queue/activeTrack.d.ts.map +1 -1
- package/lib/typescript/src/features/sleepTimer.d.ts +2 -1
- package/lib/typescript/src/features/sleepTimer.d.ts.map +1 -1
- package/lib/typescript/src/types/browser.d.ts +3 -2
- package/lib/typescript/src/types/browser.d.ts.map +1 -1
- package/lib/typescript/src/utils/LazyNativeEmitter.d.ts.map +1 -1
- package/lib/typescript/src/utils/NativeUpdatedValue.d.ts.map +1 -1
- package/lib/typescript/src/utils/callListener.d.ts +7 -0
- package/lib/typescript/src/utils/callListener.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/features/browser-config.test.ts +15 -0
- package/src/features/browser-config.ts +6 -3
- package/src/features/errors.test.ts +83 -0
- package/src/features/errors.ts +12 -7
- package/src/features/hook-wiring.test.ts +11 -10
- package/src/features/nowPlaying.ts +9 -3
- package/src/features/playback/controls.ts +1 -2
- package/src/features/playback/trackPlaybackTime.test.ts +24 -1
- package/src/features/playback/trackPlaybackTime.ts +2 -1
- package/src/features/player/setup.ts +2 -2
- package/src/features/queue/activeTrack.test.ts +32 -0
- package/src/features/queue/activeTrack.ts +8 -2
- package/src/features/sleepTimer.test.ts +24 -0
- package/src/features/sleepTimer.ts +6 -5
- package/src/types/browser.ts +3 -2
- package/src/utils/LazyNativeEmitter.test.ts +32 -0
- package/src/utils/LazyNativeEmitter.ts +3 -1
- package/src/utils/NativeUpdatedValue.test.ts +32 -0
- package/src/utils/NativeUpdatedValue.ts +3 -1
- package/src/utils/callListener.ts +17 -0
- package/website/guide/configuration.md +3 -3
- package/website/guide/errors.md +3 -1
- package/website/guide/live-streams.md +22 -20
|
@@ -12,8 +12,8 @@ import timber.log.Timber
|
|
|
12
12
|
/**
|
|
13
13
|
* Raises [DynamicLoadControl]'s `bufferForPlaybackAfterRebufferMs` after each underrun, to what the
|
|
14
14
|
* measured drain rate says would last [targetPlaybackDurationMs]. The threshold only rises, up to
|
|
15
|
-
* [maxRebufferBufferMs],
|
|
16
|
-
* [defaultConfig].
|
|
15
|
+
* [maxRebufferBufferMs], or stays where the setup put it if that is higher, until a playlist change
|
|
16
|
+
* or a seek to another item resets it to [defaultConfig].
|
|
17
17
|
*
|
|
18
18
|
* An underrun is a rebuffer while every load delivers, however slowly: a connection that stays open
|
|
19
19
|
* and stalls counts. A rebuffer while media3 retries a failed load in place does not, nor does a
|
|
@@ -241,9 +241,13 @@ class AutomaticBufferManager(
|
|
|
241
241
|
)
|
|
242
242
|
|
|
243
243
|
if (playbackDurationMs > 0 && bufferAtPlaybackStartMs > 0) {
|
|
244
|
-
val newRebufferBuffer =
|
|
245
|
-
calculateOptimalRebufferBuffer(playbackDurationMs, bufferAtPlaybackStartMs)
|
|
246
244
|
val currentConfig = loadControl.getBufferConfig()
|
|
245
|
+
val newRebufferBuffer =
|
|
246
|
+
calculateOptimalRebufferBuffer(
|
|
247
|
+
playbackDurationMs,
|
|
248
|
+
bufferAtPlaybackStartMs,
|
|
249
|
+
currentConfig.bufferForPlaybackAfterRebufferMs,
|
|
250
|
+
)
|
|
247
251
|
if (newRebufferBuffer != currentConfig.bufferForPlaybackAfterRebufferMs) {
|
|
248
252
|
Timber.d(
|
|
249
253
|
"Adjusting rebuffer threshold: %dms -> %dms",
|
|
@@ -270,18 +274,14 @@ class AutomaticBufferManager(
|
|
|
270
274
|
|
|
271
275
|
/**
|
|
272
276
|
* Assumes the buffer held at ready drained to empty over [playbackDurationMs], and returns the
|
|
273
|
-
* threshold that would last [targetPlaybackDurationMs]: 1000ms lasting 30s needs 2000ms.
|
|
277
|
+
* threshold that would last [targetPlaybackDurationMs]: 1000ms lasting 30s needs 2000ms. Both
|
|
278
|
+
* durations must be positive.
|
|
274
279
|
*/
|
|
275
|
-
private fun calculateOptimalRebufferBuffer(
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
return (currentConfig.bufferForPlaybackAfterRebufferMs * 1.5)
|
|
281
|
-
.toInt()
|
|
282
|
-
.coerceIn(defaultConfig.bufferForPlaybackAfterRebufferMs, maxRebufferBufferMs)
|
|
283
|
-
}
|
|
284
|
-
|
|
280
|
+
private fun calculateOptimalRebufferBuffer(
|
|
281
|
+
playbackDurationMs: Long,
|
|
282
|
+
initialBufferMs: Long,
|
|
283
|
+
currentThresholdMs: Int,
|
|
284
|
+
): Int {
|
|
285
285
|
val drainRateMsPerSec = (initialBufferMs.toFloat() / (playbackDurationMs / 1000f))
|
|
286
286
|
|
|
287
287
|
val neededBufferMs = (drainRateMsPerSec * (targetPlaybackDurationMs / 1000)).toLong()
|
|
@@ -295,7 +295,8 @@ class AutomaticBufferManager(
|
|
|
295
295
|
// The current threshold as the floor: it never drops within an item.
|
|
296
296
|
return neededBufferMs
|
|
297
297
|
.toInt()
|
|
298
|
-
.
|
|
298
|
+
.coerceAtMost(maxRebufferBufferMs)
|
|
299
|
+
.coerceAtLeast(currentThresholdMs)
|
|
299
300
|
}
|
|
300
301
|
|
|
301
302
|
// endregion
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
package com.audiobrowser.player
|
|
2
2
|
|
|
3
|
+
import androidx.media3.common.C
|
|
3
4
|
import androidx.media3.common.ForwardingPlayer
|
|
5
|
+
import androidx.media3.common.MediaItem
|
|
4
6
|
import androidx.media3.common.PlaybackException
|
|
5
7
|
import androidx.media3.common.Player as MediaPlayer
|
|
6
8
|
import com.audiobrowser.Callbacks
|
|
@@ -59,6 +61,8 @@ internal class InterceptingPlayer(
|
|
|
59
61
|
private val engineView: (Int) -> Int,
|
|
60
62
|
/** Whether the engine's playing is a blip the retry loop hides. */
|
|
61
63
|
private val masksPlaying: () -> Boolean,
|
|
64
|
+
/** Leads the engine's shuffle order with a start index, given the queue's size. */
|
|
65
|
+
private val leadShuffleOrder: (startIndex: Int, count: Int) -> Unit,
|
|
62
66
|
private val playPlayer: () -> Unit,
|
|
63
67
|
private val stopPlayer: () -> Unit,
|
|
64
68
|
) : ForwardingPlayer(player) {
|
|
@@ -201,4 +205,11 @@ internal class InterceptingPlayer(
|
|
|
201
205
|
intercept({ it.handleRemoteSeek(RemoteSeekEvent(position = positionMs.toDouble() / 1000.0)) }) {
|
|
202
206
|
super.seekTo(positionMs)
|
|
203
207
|
}
|
|
208
|
+
|
|
209
|
+
// Media3 sets here the queue of a track picked on an external surface and of playback
|
|
210
|
+
// resumption. An unset start index is skipped: shuffleOrderLedBy would clamp it to 0.
|
|
211
|
+
override fun setMediaItems(mediaItems: List<MediaItem>, startIndex: Int, startPositionMs: Long) {
|
|
212
|
+
super.setMediaItems(mediaItems, startIndex, startPositionMs)
|
|
213
|
+
if (startIndex != C.INDEX_UNSET) leadShuffleOrder(startIndex, mediaItems.size)
|
|
214
|
+
}
|
|
204
215
|
}
|
|
@@ -135,7 +135,11 @@ class MediaFactory(
|
|
|
135
135
|
factory.setLoadErrorHandlingPolicy(
|
|
136
136
|
RetryLoadErrorHandlingPolicy(sources, { isCurrent(mediaItem) }, cache, onLoadFailure)
|
|
137
137
|
)
|
|
138
|
-
val source =
|
|
138
|
+
val source =
|
|
139
|
+
ResolvingOnReloadSource(
|
|
140
|
+
factory.setDataSourceFactory(dataSourceFactory).createMediaSource(mediaItem),
|
|
141
|
+
transformingFactory,
|
|
142
|
+
)
|
|
139
143
|
// Adaptive sources retry in place: the policy never ends their connection.
|
|
140
144
|
return if (retrying && sources != RetryLoadErrorHandlingPolicy.Sources.ADAPTIVE)
|
|
141
145
|
ConnectionEndSource(source)
|
|
@@ -24,6 +24,7 @@ import com.audiobrowser.navigationErrorFor
|
|
|
24
24
|
import com.audiobrowser.util.Automotive
|
|
25
25
|
import com.audiobrowser.util.BrowserPathHelper
|
|
26
26
|
import com.audiobrowser.util.RatingFavorites
|
|
27
|
+
import com.audiobrowser.util.SearchParamsFactory
|
|
27
28
|
import com.audiobrowser.util.TrackFactory
|
|
28
29
|
import com.audiobrowser.util.isAutomotive
|
|
29
30
|
import com.google.common.collect.ImmutableList
|
|
@@ -34,13 +35,11 @@ import com.margelo.nitro.audiobrowser.FormattedNavigationError
|
|
|
34
35
|
import com.margelo.nitro.audiobrowser.Gate
|
|
35
36
|
import com.margelo.nitro.audiobrowser.GateEvent
|
|
36
37
|
import com.margelo.nitro.audiobrowser.GateReason
|
|
37
|
-
import com.margelo.nitro.audiobrowser.MediaReference
|
|
38
38
|
import com.margelo.nitro.audiobrowser.NativeGateRequest
|
|
39
39
|
import com.margelo.nitro.audiobrowser.NavigationError
|
|
40
40
|
import com.margelo.nitro.audiobrowser.NavigationErrorType
|
|
41
41
|
import com.margelo.nitro.audiobrowser.PlayerCapabilities
|
|
42
42
|
import com.margelo.nitro.audiobrowser.RemoteButtonLayout
|
|
43
|
-
import com.margelo.nitro.audiobrowser.SearchParams
|
|
44
43
|
import com.margelo.nitro.audiobrowser.Section
|
|
45
44
|
import com.margelo.nitro.audiobrowser.Track
|
|
46
45
|
import kotlinx.coroutines.CancellationException
|
|
@@ -56,9 +55,9 @@ import timber.log.Timber
|
|
|
56
55
|
|
|
57
56
|
/**
|
|
58
57
|
* Everything the MediaLibrarySession serves except transport, which reaches the player through
|
|
59
|
-
* [InterceptingPlayer]
|
|
60
|
-
* answering through [scope] run on IO, so anything
|
|
61
|
-
* the rest answer on the Media3 application thread.
|
|
58
|
+
* [InterceptingPlayer]. Play-from-search arrives here as a set of one item that has only a query,
|
|
59
|
+
* and as an intent in the service. Callbacks answering through [scope] run on IO, so anything
|
|
60
|
+
* touching ExoPlayer hops to [Dispatchers.Main]; the rest answer on the Media3 application thread.
|
|
62
61
|
*/
|
|
63
62
|
class MediaSessionCallback(private val player: Player) :
|
|
64
63
|
MediaLibraryService.MediaLibrarySession.Callback {
|
|
@@ -96,19 +95,6 @@ class MediaSessionCallback(private val player: Player) :
|
|
|
96
95
|
}
|
|
97
96
|
}
|
|
98
97
|
|
|
99
|
-
// Car search surfaces give free text only. Mirrors BrowserManager's query→SearchParams.
|
|
100
|
-
private fun searchParams(query: String): SearchParams =
|
|
101
|
-
SearchParams(
|
|
102
|
-
mode = null,
|
|
103
|
-
query = query,
|
|
104
|
-
genre = null,
|
|
105
|
-
artist = null,
|
|
106
|
-
album = null,
|
|
107
|
-
title = null,
|
|
108
|
-
playlist = null,
|
|
109
|
-
reference = MediaReference.UNKNOWN,
|
|
110
|
-
)
|
|
111
|
-
|
|
112
98
|
private fun createGateMediaItem(gate: Gate): MediaItem =
|
|
113
99
|
createErrorMediaItem(
|
|
114
100
|
BrowserPathHelper.GATE_PATH,
|
|
@@ -614,7 +600,11 @@ class MediaSessionCallback(private val player: Player) :
|
|
|
614
600
|
|
|
615
601
|
val searchOutcome =
|
|
616
602
|
audioBrowser.gateDecision(
|
|
617
|
-
NativeGateRequest(
|
|
603
|
+
NativeGateRequest(
|
|
604
|
+
reason = GateReason.SEARCH,
|
|
605
|
+
path = null,
|
|
606
|
+
search = SearchParamsFactory.fromQuery(query),
|
|
607
|
+
)
|
|
618
608
|
)
|
|
619
609
|
// Search is gated with the browse tree, or it would route around the gate. One result: the
|
|
620
610
|
// gate tile (see onGetSearchResult).
|
|
@@ -721,7 +711,11 @@ class MediaSessionCallback(private val player: Player) :
|
|
|
721
711
|
|
|
722
712
|
val searchOutcome =
|
|
723
713
|
audioBrowser.gateDecision(
|
|
724
|
-
NativeGateRequest(
|
|
714
|
+
NativeGateRequest(
|
|
715
|
+
reason = GateReason.SEARCH,
|
|
716
|
+
path = null,
|
|
717
|
+
search = SearchParamsFactory.fromQuery(query),
|
|
718
|
+
)
|
|
725
719
|
)
|
|
726
720
|
// The one result onSearch announced for a gated search.
|
|
727
721
|
if (searchOutcome.gated) {
|
|
@@ -860,8 +854,21 @@ class MediaSessionCallback(private val player: Player) :
|
|
|
860
854
|
}
|
|
861
855
|
}
|
|
862
856
|
|
|
857
|
+
val voiceSearch = mediaItems.singleOrNull()?.let { SearchParamsFactory.voiceSearchOf(it) }
|
|
863
858
|
val result =
|
|
864
|
-
|
|
859
|
+
if (voiceSearch != null) {
|
|
860
|
+
// A failed future leaves current playback untouched.
|
|
861
|
+
val found =
|
|
862
|
+
player.voiceSearch(voiceSearch)
|
|
863
|
+
?: throw IllegalStateException("Voice search gated or without a playable result")
|
|
864
|
+
MediaSession.MediaItemsWithStartPosition(
|
|
865
|
+
found.map { TrackFactory.toMedia3(it) },
|
|
866
|
+
0,
|
|
867
|
+
startPositionMs,
|
|
868
|
+
)
|
|
869
|
+
} else {
|
|
870
|
+
browserManager.resolveMediaItemsForPlayback(mediaItems, startIndex, startPositionMs)
|
|
871
|
+
}
|
|
865
872
|
|
|
866
873
|
val tracks = result.mediaItems.map { TrackFactory.fromMedia3(it) }.toTypedArray()
|
|
867
874
|
// setQueue reads an unset index as "keep the current one". Media3 still gets it unset on the
|
|
@@ -278,6 +278,8 @@ internal constructor(
|
|
|
278
278
|
browserRegistered = CompletableDeferred()
|
|
279
279
|
}
|
|
280
280
|
field = value
|
|
281
|
+
// Covers a browser assigned after its options were applied.
|
|
282
|
+
value?.browserManager?.setFavoriteEnabled(options.capabilities.favoriteEnabled)
|
|
281
283
|
}
|
|
282
284
|
|
|
283
285
|
/**
|
|
@@ -674,6 +676,7 @@ internal constructor(
|
|
|
674
676
|
playerState = { playbackState },
|
|
675
677
|
engineView = ::retryView,
|
|
676
678
|
masksPlaying = { retryMasksPlaying },
|
|
679
|
+
leadShuffleOrder = ::leadShuffleOrder,
|
|
677
680
|
playPlayer = ::play,
|
|
678
681
|
stopPlayer = ::stop,
|
|
679
682
|
)
|
|
@@ -796,14 +799,17 @@ internal constructor(
|
|
|
796
799
|
) {
|
|
797
800
|
val mediaItems = TrackFactory.toMedia3(tracks).toMutableList()
|
|
798
801
|
sessionPlayer.setMediaItems(mediaItems, startIndex, startPositionMs)
|
|
799
|
-
|
|
800
|
-
if (mediaItems.isNotEmpty()) {
|
|
801
|
-
localEngine.setShuffleOrder(shuffleOrderLedBy(startIndex, mediaItems.size))
|
|
802
|
-
}
|
|
802
|
+
leadShuffleOrder(startIndex, mediaItems.size)
|
|
803
803
|
queueSourcePath = sourcePath
|
|
804
804
|
sessionPlayer.prepare()
|
|
805
805
|
}
|
|
806
806
|
|
|
807
|
+
/** Call after setting a queue of [count] tracks that starts on [startIndex]. */
|
|
808
|
+
private fun leadShuffleOrder(startIndex: Int, count: Int) {
|
|
809
|
+
// While remote, the queue plays in list order.
|
|
810
|
+
if (count > 0) localEngine.setShuffleOrder(shuffleOrderLedBy(startIndex, count))
|
|
811
|
+
}
|
|
812
|
+
|
|
807
813
|
/** @throws IllegalArgumentException if [index] is out of bounds. */
|
|
808
814
|
fun replaceTrack(index: Int, track: Track) {
|
|
809
815
|
validateIndex(index)
|
|
@@ -1116,33 +1122,11 @@ internal constructor(
|
|
|
1116
1122
|
*/
|
|
1117
1123
|
suspend fun playFromSearch(params: SearchParams): Boolean {
|
|
1118
1124
|
return try {
|
|
1119
|
-
val
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
)
|
|
1125
|
-
if (gateOutcome.gated) {
|
|
1126
|
-
Timber.i("playFromSearch refused — request is gated")
|
|
1127
|
-
audioBrowser.onGate(GateEvent(GateReason.SEARCH))
|
|
1128
|
-
return false
|
|
1129
|
-
}
|
|
1130
|
-
val browserManager = audioBrowser.browserManager
|
|
1131
|
-
|
|
1132
|
-
Timber.d(
|
|
1133
|
-
"Executing voice search: mode=${params.mode}, query='${params.query}', artist='${params.artist}', album='${params.album}'"
|
|
1134
|
-
)
|
|
1135
|
-
val tracks = browserManager.searchPlayable(params)
|
|
1136
|
-
|
|
1137
|
-
if (tracks != null && tracks.isNotEmpty()) {
|
|
1138
|
-
Timber.d("Found ${tracks.size} track(s), playing first: ${tracks[0].title}")
|
|
1139
|
-
setQueue(tracks)
|
|
1140
|
-
play()
|
|
1141
|
-
true
|
|
1142
|
-
} else {
|
|
1143
|
-
Timber.w("No tracks found for search: ${params}")
|
|
1144
|
-
false
|
|
1145
|
-
}
|
|
1125
|
+
val tracks = voiceSearch(params) ?: return false
|
|
1126
|
+
Timber.d("Found ${tracks.size} track(s), playing first: ${tracks[0].title}")
|
|
1127
|
+
setQueue(tracks)
|
|
1128
|
+
play()
|
|
1129
|
+
true
|
|
1146
1130
|
} catch (e: Exception) {
|
|
1147
1131
|
currentCoroutineContext().ensureActive()
|
|
1148
1132
|
Timber.e(e, "Error handling voice search: ${params}")
|
|
@@ -1150,6 +1134,32 @@ internal constructor(
|
|
|
1150
1134
|
}
|
|
1151
1135
|
}
|
|
1152
1136
|
|
|
1137
|
+
/**
|
|
1138
|
+
* The playable results of a voice search, from the first. Gated like browsing, or voice search
|
|
1139
|
+
* would be a way around the gate.
|
|
1140
|
+
*
|
|
1141
|
+
* @return null when gated (after onGate) or when nothing playable is found
|
|
1142
|
+
* @throws Exception when the browser is not registered in time or the search callback fails
|
|
1143
|
+
*/
|
|
1144
|
+
suspend fun voiceSearch(params: SearchParams): Array<Track>? {
|
|
1145
|
+
val audioBrowser = awaitBrowser()
|
|
1146
|
+
val gateOutcome =
|
|
1147
|
+
audioBrowser.gateDecision(
|
|
1148
|
+
NativeGateRequest(reason = GateReason.SEARCH, path = null, search = params)
|
|
1149
|
+
)
|
|
1150
|
+
if (gateOutcome.gated) {
|
|
1151
|
+
Timber.i("Voice search refused: request is gated")
|
|
1152
|
+
audioBrowser.onGate(GateEvent(GateReason.SEARCH))
|
|
1153
|
+
return null
|
|
1154
|
+
}
|
|
1155
|
+
Timber.d(
|
|
1156
|
+
"Executing voice search: mode=${params.mode}, query='${params.query}', artist='${params.artist}', album='${params.album}'"
|
|
1157
|
+
)
|
|
1158
|
+
return audioBrowser.browserManager.searchPlayable(params).also {
|
|
1159
|
+
if (it == null) Timber.w("No tracks found for search: ${params}")
|
|
1160
|
+
}
|
|
1161
|
+
}
|
|
1162
|
+
|
|
1153
1163
|
/** An ended queue stays ended, as on an ended engine. */
|
|
1154
1164
|
fun prepare() {
|
|
1155
1165
|
if (liveStreamParked) return
|
|
@@ -87,6 +87,10 @@ class PlayerListener(private val player: Player) : MediaPlayer.Listener {
|
|
|
87
87
|
player.dropFailureReports()
|
|
88
88
|
}
|
|
89
89
|
}
|
|
90
|
+
// The periodic save runs only while set to play.
|
|
91
|
+
if (reason == MediaPlayer.DISCONTINUITY_REASON_SEEK && !player.playWhenReady) {
|
|
92
|
+
player.playbackStateStore.save()
|
|
93
|
+
}
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
override fun onMediaItemTransition(mediaItem: MediaItem?, reason: Int) {
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
package com.audiobrowser.player
|
|
2
|
+
|
|
3
|
+
import androidx.media3.exoplayer.source.MediaPeriod
|
|
4
|
+
import androidx.media3.exoplayer.source.MediaSource
|
|
5
|
+
import androidx.media3.exoplayer.source.WrappingMediaSource
|
|
6
|
+
import androidx.media3.exoplayer.upstream.Allocator
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Has the track's media URL resolved afresh on each reload of [source]: each time the engine
|
|
10
|
+
* prepares it (a stop or an error releases it), and each period after the first, since the engine
|
|
11
|
+
* keeps a queue item's source prepared while others play (a skip back to it, a repeat).
|
|
12
|
+
*/
|
|
13
|
+
class ResolvingOnReloadSource(
|
|
14
|
+
source: MediaSource,
|
|
15
|
+
private val urls: TransformingDataSource.Factory,
|
|
16
|
+
) : WrappingMediaSource(source) {
|
|
17
|
+
|
|
18
|
+
/** Whether a period was created since the last preparation; read on the playback thread only. */
|
|
19
|
+
private var periodCreated = false
|
|
20
|
+
|
|
21
|
+
override fun prepareSourceInternal() {
|
|
22
|
+
periodCreated = false
|
|
23
|
+
urls.resolveOnNextMediaOpen = true
|
|
24
|
+
super.prepareSourceInternal()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
override fun createPeriod(
|
|
28
|
+
id: MediaSource.MediaPeriodId,
|
|
29
|
+
allocator: Allocator,
|
|
30
|
+
startPositionUs: Long,
|
|
31
|
+
): MediaPeriod {
|
|
32
|
+
// Not on the first: an HLS source has opened its playlist before it, which marking again would
|
|
33
|
+
// resolve twice.
|
|
34
|
+
if (periodCreated) urls.resolveOnNextMediaOpen = true
|
|
35
|
+
periodCreated = true
|
|
36
|
+
return super.createPeriod(id, allocator, startPositionUs)
|
|
37
|
+
}
|
|
38
|
+
}
|
|
@@ -17,8 +17,10 @@ import timber.log.Timber
|
|
|
17
17
|
* `createMediaSource`, deadlocks while a synchronous Nitro call such as `seekTo` holds the JS
|
|
18
18
|
* thread.
|
|
19
19
|
*
|
|
20
|
-
* The first open resolves the media URL and caches the result on the [Factory]
|
|
21
|
-
*
|
|
20
|
+
* The first open resolves the media URL and caches the result on the [Factory]. A later open of the
|
|
21
|
+
* media URL (a seek, a playlist refresh) reuses it, unless the track reloaded or the last open or
|
|
22
|
+
* read of it failed: the URL or its token may have expired. Opens of other URLs (HLS segments,
|
|
23
|
+
* keys) keep their own URL and reuse the cached headers and user agent.
|
|
22
24
|
*/
|
|
23
25
|
class TransformingDataSource(private val upstream: DataSource, private val factory: Factory) :
|
|
24
26
|
DataSource {
|
|
@@ -44,6 +46,8 @@ class TransformingDataSource(private val upstream: DataSource, private val facto
|
|
|
44
46
|
|
|
45
47
|
private var resolvedUri: Uri? = null
|
|
46
48
|
|
|
49
|
+
private var openedMediaUrl = false
|
|
50
|
+
|
|
47
51
|
override fun open(dataSpec: DataSpec): Long {
|
|
48
52
|
val originalUrl = dataSpec.uri.toString()
|
|
49
53
|
|
|
@@ -51,16 +55,10 @@ class TransformingDataSource(private val upstream: DataSource, private val facto
|
|
|
51
55
|
val (finalUrl, headers, userAgent) =
|
|
52
56
|
when {
|
|
53
57
|
cached == null -> resolveAndCache(originalUrl)
|
|
54
|
-
//
|
|
55
|
-
//
|
|
56
|
-
// After a failed load it re-resolves once instead, since the URL or token may have expired.
|
|
58
|
+
// The resolved URL, never the original: that may be schemeless ("/listen/<id>/x.mp3"),
|
|
59
|
+
// which DefaultDataSource routes to a file and fails.
|
|
57
60
|
originalUrl == factory.cachedOriginalUrl ->
|
|
58
|
-
if (factory.
|
|
59
|
-
factory.reresolveOnNextMediaOpen = false
|
|
60
|
-
resolveAndCache(originalUrl)
|
|
61
|
-
} else {
|
|
62
|
-
cached
|
|
63
|
-
}
|
|
61
|
+
if (factory.resolveOnNextMediaOpen) resolveAndCache(originalUrl) else cached
|
|
64
62
|
// An already-absolute segment or key URL: keep it, reuse the headers.
|
|
65
63
|
else -> Triple(originalUrl, cached.second, cached.third)
|
|
66
64
|
}
|
|
@@ -68,9 +66,11 @@ class TransformingDataSource(private val upstream: DataSource, private val facto
|
|
|
68
66
|
val requestHeaders = buildMap {
|
|
69
67
|
putAll(dataSpec.httpRequestHeaders)
|
|
70
68
|
putAll(headers)
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
69
|
+
val headerAgent =
|
|
70
|
+
keys.filter { it.equals("User-Agent", ignoreCase = true) }.map { remove(it) }.lastOrNull()
|
|
71
|
+
// Under this exact name, so it replaces MediaFactory's default rather than sitting beside it.
|
|
72
|
+
val agent = if (userAgent != DEFAULT_USER_AGENT) userAgent else headerAgent
|
|
73
|
+
agent?.let { put("User-Agent", it) }
|
|
74
74
|
}
|
|
75
75
|
val mergedHeaders =
|
|
76
76
|
if (wantsOpenEndedRange(dataSpec, requestHeaders)) {
|
|
@@ -83,18 +83,20 @@ class TransformingDataSource(private val upstream: DataSource, private val facto
|
|
|
83
83
|
dataSpec.buildUpon().setUri(finalUrl.toUri()).setHttpRequestHeaders(mergedHeaders).build()
|
|
84
84
|
|
|
85
85
|
resolvedUri = transformedSpec.uri
|
|
86
|
+
openedMediaUrl = originalUrl == factory.cachedOriginalUrl
|
|
86
87
|
return try {
|
|
87
88
|
upstream.open(transformedSpec)
|
|
88
89
|
} catch (e: IOException) {
|
|
89
90
|
// Only a media-URL failure refreshes the URL; a failed segment or key leaves it alone.
|
|
90
|
-
if (
|
|
91
|
-
factory.
|
|
91
|
+
if (openedMediaUrl) {
|
|
92
|
+
factory.resolveOnNextMediaOpen = true
|
|
92
93
|
}
|
|
93
94
|
throw e
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
|
|
97
98
|
private fun resolveAndCache(originalUrl: String): Triple<String, Map<String, String>, String> {
|
|
99
|
+
factory.resolveOnNextMediaOpen = false
|
|
98
100
|
val resolved = resolveRequestConfig(originalUrl)
|
|
99
101
|
factory.cachedTransform = resolved
|
|
100
102
|
factory.cachedOriginalUrl = originalUrl
|
|
@@ -103,7 +105,16 @@ class TransformingDataSource(private val upstream: DataSource, private val facto
|
|
|
103
105
|
}
|
|
104
106
|
|
|
105
107
|
override fun read(buffer: ByteArray, offset: Int, length: Int): Int {
|
|
106
|
-
return
|
|
108
|
+
return try {
|
|
109
|
+
upstream.read(buffer, offset, length)
|
|
110
|
+
} catch (e: IOException) {
|
|
111
|
+
// An in-place retry reopens the media URL after a dropped read. A load cancelled for a seek,
|
|
112
|
+
// whose thread the loader interrupts, keeps it.
|
|
113
|
+
if (openedMediaUrl && !Thread.currentThread().isInterrupted) {
|
|
114
|
+
factory.resolveOnNextMediaOpen = true
|
|
115
|
+
}
|
|
116
|
+
throw e
|
|
117
|
+
}
|
|
107
118
|
}
|
|
108
119
|
|
|
109
120
|
override fun addTransferListener(transferListener: TransferListener) {
|
|
@@ -127,6 +138,7 @@ class TransformingDataSource(private val upstream: DataSource, private val facto
|
|
|
127
138
|
override fun close() {
|
|
128
139
|
upstream.close()
|
|
129
140
|
resolvedUri = null
|
|
141
|
+
openedMediaUrl = false
|
|
130
142
|
}
|
|
131
143
|
|
|
132
144
|
/**
|
|
@@ -164,8 +176,11 @@ class TransformingDataSource(private val upstream: DataSource, private val facto
|
|
|
164
176
|
|
|
165
177
|
@Volatile internal var cachedOriginalUrl: String? = null
|
|
166
178
|
|
|
167
|
-
|
|
168
|
-
|
|
179
|
+
/**
|
|
180
|
+
* Set by a failed open or read of the media URL and by [ResolvingOnReloadSource] on a reload;
|
|
181
|
+
* the next open of the media URL resolves it again and clears it.
|
|
182
|
+
*/
|
|
183
|
+
@Volatile internal var resolveOnNextMediaOpen: Boolean = false
|
|
169
184
|
|
|
170
185
|
override fun createDataSource(): DataSource {
|
|
171
186
|
return TransformingDataSource(upstream = upstreamFactory.createDataSource(), factory = this)
|
|
@@ -12,11 +12,20 @@ internal interface RemotePlayback {
|
|
|
12
12
|
* The receiver of the current session; read it only while [isSessionAvailable]. It plays one item
|
|
13
13
|
* at a time: setting an item loads it there from the given position, and plays it if
|
|
14
14
|
* `playWhenReady` is set, without [MediaPlayer.prepare]. A new session can bring a new player.
|
|
15
|
+
* While [isSuspended], it drops every command.
|
|
15
16
|
*/
|
|
16
17
|
val player: MediaPlayer
|
|
17
18
|
|
|
19
|
+
/** True while [isSuspended] too: the session is kept, and the receiver plays on. */
|
|
18
20
|
val isSessionAvailable: Boolean
|
|
19
21
|
|
|
22
|
+
/**
|
|
23
|
+
* The session is kept but out of reach: nothing sent to [player] arrives, and its state stands
|
|
24
|
+
* still until the session resumes.
|
|
25
|
+
*/
|
|
26
|
+
val isSuspended: Boolean
|
|
27
|
+
get() = false
|
|
28
|
+
|
|
20
29
|
/** Calls [listener] on the main thread; null stops the calls. */
|
|
21
30
|
fun setListener(listener: Listener?)
|
|
22
31
|
|
|
@@ -24,7 +33,7 @@ internal interface RemotePlayback {
|
|
|
24
33
|
fun release()
|
|
25
34
|
|
|
26
35
|
interface Listener {
|
|
27
|
-
/** [isSessionAvailable] or [player] changed. */
|
|
36
|
+
/** [isSessionAvailable], [isSuspended] or [player] changed. */
|
|
28
37
|
fun onSessionChanged()
|
|
29
38
|
|
|
30
39
|
/**
|
|
@@ -31,6 +31,8 @@ import timber.log.Timber
|
|
|
31
31
|
* - Moving between remotes, or to a remote's new session, goes from receiver to receiver.
|
|
32
32
|
* - A receiver's failure, or an item it hasn't started within [startTimeoutMs] of being sent or
|
|
33
33
|
* played, is the player error until [prepare] loads the item again. [stop] stops the receiver.
|
|
34
|
+
* - While the remote's session is suspended, playback stays there, and the item loaded or the stop
|
|
35
|
+
* made meanwhile goes to the receiver at the resume. Other commands made then are lost.
|
|
34
36
|
* - [setVolume] sets the receiver's device volume while remote.
|
|
35
37
|
*/
|
|
36
38
|
internal class RemoteSwitchingPlayer(
|
|
@@ -76,6 +78,12 @@ internal class RemoteSwitchingPlayer(
|
|
|
76
78
|
|
|
77
79
|
/** The receiver's last timed metadata for the current item; none until it holds that item. */
|
|
78
80
|
var timedMetadata = NO_TIMED_METADATA
|
|
81
|
+
|
|
82
|
+
/** [RemotePlayback.isSuspended] as last followed: a send or a stop waits for the resume. */
|
|
83
|
+
var suspended = output.isSuspended
|
|
84
|
+
|
|
85
|
+
/** A stop made while [suspended], for the resume; a later send replaces it. */
|
|
86
|
+
var stopHeld = false
|
|
79
87
|
}
|
|
80
88
|
}
|
|
81
89
|
|
|
@@ -194,6 +202,7 @@ internal class RemoteSwitchingPlayer(
|
|
|
194
202
|
current.output.isSessionAvailable &&
|
|
195
203
|
current.output.player === current.receiver
|
|
196
204
|
) {
|
|
205
|
+
followSuspension(current)
|
|
197
206
|
return
|
|
198
207
|
}
|
|
199
208
|
val next = remotes.firstOrNull { it.isSessionAvailable }
|
|
@@ -209,6 +218,32 @@ internal class RemoteSwitchingPlayer(
|
|
|
209
218
|
}
|
|
210
219
|
}
|
|
211
220
|
|
|
221
|
+
/**
|
|
222
|
+
* No start times out while the receiver is out of reach. At the resume, the item sent meanwhile,
|
|
223
|
+
* or sent just before and never seen there, goes to the receiver, and a stop made meanwhile stops
|
|
224
|
+
* it.
|
|
225
|
+
*/
|
|
226
|
+
private fun followSuspension(remote: Route.Remote) {
|
|
227
|
+
val suspended = remote.output.isSuspended
|
|
228
|
+
if (suspended == remote.suspended) return
|
|
229
|
+
remote.suspended = suspended
|
|
230
|
+
if (suspended) {
|
|
231
|
+
disarmStart(remote)
|
|
232
|
+
return
|
|
233
|
+
}
|
|
234
|
+
if (remote.stopHeld) {
|
|
235
|
+
remote.stopHeld = false
|
|
236
|
+
stopReceiver(remote)
|
|
237
|
+
}
|
|
238
|
+
when (val load = remote.load) {
|
|
239
|
+
is Load.Sent ->
|
|
240
|
+
if (receiverHolds(remote, load.item)) armStart(remote)
|
|
241
|
+
else send(remote, load.item, load.positionMs)
|
|
242
|
+
is Load.Playing -> if (playIntent && !started(remote)) armStart(remote)
|
|
243
|
+
else -> Unit
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
|
|
212
247
|
private fun handOverToRemote(target: RemotePlayback) {
|
|
213
248
|
route =
|
|
214
249
|
Route.HandingOver(
|
|
@@ -317,6 +352,11 @@ internal class RemoteSwitchingPlayer(
|
|
|
317
352
|
remote.startTimeout = null
|
|
318
353
|
}
|
|
319
354
|
|
|
355
|
+
/** Holds the stop back for the resume while [remote] is suspended. */
|
|
356
|
+
private fun stopReceiver(remote: Route.Remote) {
|
|
357
|
+
if (remote.suspended) remote.stopHeld = true else stopReceiver(remote.receiver)
|
|
358
|
+
}
|
|
359
|
+
|
|
320
360
|
/** A receiver whose session already ended refuses commands; it has stopped by itself. */
|
|
321
361
|
private fun stopReceiver(receiver: MediaPlayer) {
|
|
322
362
|
try {
|
|
@@ -332,7 +372,7 @@ internal class RemoteSwitchingPlayer(
|
|
|
332
372
|
val item = queue.current
|
|
333
373
|
if (item == null) {
|
|
334
374
|
remote.load = Load.Idle(C.TIME_UNSET)
|
|
335
|
-
stopReceiver(remote
|
|
375
|
+
stopReceiver(remote)
|
|
336
376
|
return
|
|
337
377
|
}
|
|
338
378
|
remote.load =
|
|
@@ -351,6 +391,10 @@ internal class RemoteSwitchingPlayer(
|
|
|
351
391
|
|
|
352
392
|
private fun send(remote: Route.Remote, item: MediaItem, positionMs: Long) {
|
|
353
393
|
remote.load = Load.Sent(item, positionMs)
|
|
394
|
+
if (remote.suspended) {
|
|
395
|
+
remote.stopHeld = false
|
|
396
|
+
return
|
|
397
|
+
}
|
|
354
398
|
armStart(remote)
|
|
355
399
|
try {
|
|
356
400
|
// Before the load, which autoplays as this says. Told again, a receiver plays what it holds.
|
|
@@ -553,7 +597,7 @@ internal class RemoteSwitchingPlayer(
|
|
|
553
597
|
// item while the next resolves is not told to play it.
|
|
554
598
|
if (!playWhenReady || remote.load !is Load.Resolving)
|
|
555
599
|
remote.receiver.playWhenReady = playWhenReady
|
|
556
|
-
if (remote.load is Load.Playing) {
|
|
600
|
+
if (remote.load is Load.Playing && !remote.suspended) {
|
|
557
601
|
if (resumes) armStart(remote) else if (!playWhenReady) disarmStart(remote)
|
|
558
602
|
}
|
|
559
603
|
return done()
|
|
@@ -575,7 +619,7 @@ internal class RemoteSwitchingPlayer(
|
|
|
575
619
|
if (remote == null) return super.handleStop()
|
|
576
620
|
val positionMs = positionOn(remote)
|
|
577
621
|
cancelLoad(remote)
|
|
578
|
-
stopReceiver(remote
|
|
622
|
+
stopReceiver(remote)
|
|
579
623
|
remote.load = Load.Idle(positionMs)
|
|
580
624
|
return done()
|
|
581
625
|
}
|
|
@@ -640,7 +684,7 @@ internal class RemoteSwitchingPlayer(
|
|
|
640
684
|
nothingAfter && repeat == REPEAT_MODE_ALL -> queue.moveTo(0)
|
|
641
685
|
nothingAfter && playing -> {
|
|
642
686
|
cancelLoad(remote)
|
|
643
|
-
stopReceiver(remote
|
|
687
|
+
stopReceiver(remote)
|
|
644
688
|
remote.load = Load.Ended(0)
|
|
645
689
|
return done()
|
|
646
690
|
}
|