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
|
@@ -61,11 +61,17 @@ internal fun createCastRemote(context: Context, receiverApplicationId: String?):
|
|
|
61
61
|
return SdkCastRemote(Cast.getSingletonInstance(context), player)
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
|
|
64
|
+
internal class SdkCastRemote(private val cast: Cast, override val player: RemoteCastPlayer) :
|
|
65
65
|
RemotePlayback {
|
|
66
66
|
private var listener: RemotePlayback.Listener? = null
|
|
67
67
|
private var client: RemoteMediaClient? = null
|
|
68
68
|
|
|
69
|
+
/**
|
|
70
|
+
* Kept through a suspension, while the receiver plays on out of reach: [player] lets go of its
|
|
71
|
+
* session then as it does at an end, so only the SDK's own end or failed resume clears this.
|
|
72
|
+
*/
|
|
73
|
+
private var hasSession = player.isCastSessionAvailable
|
|
74
|
+
|
|
69
75
|
private val ends = CastEnds()
|
|
70
76
|
|
|
71
77
|
private val statusCallback =
|
|
@@ -94,17 +100,20 @@ private class SdkCastRemote(private val cast: Cast, override val player: RemoteC
|
|
|
94
100
|
|
|
95
101
|
override fun onSessionResumed(session: CastSession, wasSuspended: Boolean) = watch(session)
|
|
96
102
|
|
|
97
|
-
override fun onSessionEnded(session: CastSession, error: Int)
|
|
103
|
+
override fun onSessionEnded(session: CastSession, error: Int) {
|
|
104
|
+
watch(null)
|
|
105
|
+
sessionGone()
|
|
106
|
+
}
|
|
98
107
|
|
|
99
108
|
override fun onSessionStarting(session: CastSession) = Unit
|
|
100
109
|
|
|
101
110
|
override fun onSessionStartFailed(session: CastSession, error: Int) = Unit
|
|
102
111
|
|
|
103
|
-
override fun onSessionEnding(session: CastSession) =
|
|
112
|
+
override fun onSessionEnding(session: CastSession) = sessionGone()
|
|
104
113
|
|
|
105
114
|
override fun onSessionResuming(session: CastSession, sessionId: String) = Unit
|
|
106
115
|
|
|
107
|
-
override fun onSessionResumeFailed(session: CastSession, error: Int) =
|
|
116
|
+
override fun onSessionResumeFailed(session: CastSession, error: Int) = sessionGone()
|
|
108
117
|
|
|
109
118
|
override fun onSessionSuspended(session: CastSession, reason: Int) = Unit
|
|
110
119
|
}
|
|
@@ -112,6 +121,24 @@ private class SdkCastRemote(private val cast: Cast, override val player: RemoteC
|
|
|
112
121
|
init {
|
|
113
122
|
cast.addSessionManagerListener(sessions)
|
|
114
123
|
watch(cast.currentCastSession)
|
|
124
|
+
player.setSessionAvailabilityListener(
|
|
125
|
+
object : SessionAvailabilityListener {
|
|
126
|
+
override fun onCastSessionAvailable() {
|
|
127
|
+
hasSession = true
|
|
128
|
+
listener?.onSessionChanged()
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
override fun onCastSessionUnavailable() {
|
|
132
|
+
listener?.onSessionChanged()
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
private fun sessionGone() {
|
|
139
|
+
if (!hasSession) return
|
|
140
|
+
hasSession = false
|
|
141
|
+
listener?.onSessionChanged()
|
|
115
142
|
}
|
|
116
143
|
|
|
117
144
|
private fun watch(session: CastSession?) {
|
|
@@ -120,20 +147,16 @@ private class SdkCastRemote(private val cast: Cast, override val player: RemoteC
|
|
|
120
147
|
client = session?.remoteMediaClient
|
|
121
148
|
client?.registerCallback(statusCallback)
|
|
122
149
|
}
|
|
150
|
+
|
|
123
151
|
override val isSessionAvailable: Boolean
|
|
124
|
-
get() =
|
|
152
|
+
get() = hasSession
|
|
153
|
+
|
|
154
|
+
/** [player] has no client between letting go of the session and taking it up again. */
|
|
155
|
+
override val isSuspended: Boolean
|
|
156
|
+
get() = hasSession && !player.isCastSessionAvailable
|
|
125
157
|
|
|
126
158
|
override fun setListener(listener: RemotePlayback.Listener?) {
|
|
127
159
|
this.listener = listener
|
|
128
|
-
player.setSessionAvailabilityListener(
|
|
129
|
-
listener?.let {
|
|
130
|
-
object : SessionAvailabilityListener {
|
|
131
|
-
override fun onCastSessionAvailable() = it.onSessionChanged()
|
|
132
|
-
|
|
133
|
-
override fun onCastSessionUnavailable() = it.onSessionChanged()
|
|
134
|
-
}
|
|
135
|
-
}
|
|
136
|
-
)
|
|
137
160
|
}
|
|
138
161
|
|
|
139
162
|
override fun release() {
|
|
@@ -25,6 +25,7 @@ import com.audiobrowser.browser.handleTrackLoad
|
|
|
25
25
|
import com.audiobrowser.browser.resolveMediaUrl
|
|
26
26
|
import com.audiobrowser.extension.NumberExt.Companion.toSeconds
|
|
27
27
|
import com.audiobrowser.extension.indexOfTappedTrack
|
|
28
|
+
import com.audiobrowser.extension.toQueueIndex
|
|
28
29
|
import com.audiobrowser.model.PlayerSetupOptions
|
|
29
30
|
import com.audiobrowser.model.PlayerUpdateOptions
|
|
30
31
|
import com.audiobrowser.player.Player
|
|
@@ -573,6 +574,10 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
573
574
|
navigationJob?.cancel()
|
|
574
575
|
|
|
575
576
|
val path = track.path
|
|
577
|
+
val playAlone: suspend () -> Unit = {
|
|
578
|
+
player.load(track)
|
|
579
|
+
player.play()
|
|
580
|
+
}
|
|
576
581
|
navigationJob =
|
|
577
582
|
mainScope.launch {
|
|
578
583
|
try {
|
|
@@ -633,7 +638,7 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
633
638
|
0.0,
|
|
634
639
|
startPosition = null,
|
|
635
640
|
intercepted = {},
|
|
636
|
-
defaultBehavior =
|
|
641
|
+
defaultBehavior = playAlone,
|
|
637
642
|
)
|
|
638
643
|
}
|
|
639
644
|
}
|
|
@@ -650,7 +655,7 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
650
655
|
0.0,
|
|
651
656
|
startPosition = null,
|
|
652
657
|
intercepted = {},
|
|
653
|
-
defaultBehavior =
|
|
658
|
+
defaultBehavior = playAlone,
|
|
654
659
|
)
|
|
655
660
|
}
|
|
656
661
|
else -> {
|
|
@@ -697,7 +702,7 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
697
702
|
launchInScope { connectedService?.player?.notifyContentChanged(path) }
|
|
698
703
|
|
|
699
704
|
if (browserManager.getPath() == path) {
|
|
700
|
-
|
|
705
|
+
refreshContent()
|
|
701
706
|
}
|
|
702
707
|
}
|
|
703
708
|
|
|
@@ -713,7 +718,24 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
713
718
|
runCatching { browserManager.queryTabs() }
|
|
714
719
|
.onFailure { Timber.e(it, "Re-querying tabs failed") }
|
|
715
720
|
}
|
|
716
|
-
|
|
721
|
+
refreshContent()
|
|
722
|
+
}
|
|
723
|
+
|
|
724
|
+
/**
|
|
725
|
+
* Reloads the current path. A reload that publishes clears the navigation error; one that fails
|
|
726
|
+
* reports it, unless a later navigation or reload has overtaken it.
|
|
727
|
+
*/
|
|
728
|
+
private fun refreshContent() {
|
|
729
|
+
mainScope.launch {
|
|
730
|
+
val path = browserManager.getPath()
|
|
731
|
+
try {
|
|
732
|
+
if (browserManager.refresh()) clearNavigationError()
|
|
733
|
+
} catch (e: CancellationException) {
|
|
734
|
+
throw e
|
|
735
|
+
} catch (e: Exception) {
|
|
736
|
+
handleBrowserException(e, path, "refreshing path: $path")
|
|
737
|
+
}
|
|
738
|
+
}
|
|
717
739
|
}
|
|
718
740
|
|
|
719
741
|
override fun setFavorites(favorites: Array<String>) {
|
|
@@ -918,16 +940,18 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
918
940
|
|
|
919
941
|
override fun add(tracks: Array<Track>, insertBeforeIndex: Double?) =
|
|
920
942
|
commandPlayer("add") { player ->
|
|
921
|
-
val inputIndex = insertBeforeIndex?.
|
|
943
|
+
val inputIndex = insertBeforeIndex?.toQueueIndex() ?: -1
|
|
922
944
|
player.add(tracks, inputIndex)
|
|
923
945
|
}
|
|
924
946
|
|
|
925
947
|
override fun move(fromIndex: Double, toIndex: Double) =
|
|
926
|
-
commandPlayer("move") { player ->
|
|
948
|
+
commandPlayer("move") { player ->
|
|
949
|
+
player.move(fromIndex.toQueueIndex(), toIndex.toQueueIndex())
|
|
950
|
+
}
|
|
927
951
|
|
|
928
952
|
override fun remove(indexes: DoubleArray) =
|
|
929
953
|
commandPlayer("remove") { player ->
|
|
930
|
-
val indexList = indexes.map { it.
|
|
954
|
+
val indexList = indexes.map { it.toQueueIndex() }
|
|
931
955
|
player.remove(indexList)
|
|
932
956
|
}
|
|
933
957
|
|
|
@@ -936,7 +960,7 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
936
960
|
|
|
937
961
|
override fun skip(index: Double, initialPosition: Double?) =
|
|
938
962
|
commandPlayer("skip") { player ->
|
|
939
|
-
player.skipTo(index.
|
|
963
|
+
player.skipTo(index.toQueueIndex())
|
|
940
964
|
|
|
941
965
|
if (initialPosition != null && initialPosition >= 0) {
|
|
942
966
|
player.seekTo((initialPosition * 1000).toLong(), TimeUnit.MILLISECONDS)
|
|
@@ -963,7 +987,11 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
963
987
|
|
|
964
988
|
override fun setQueue(tracks: Array<Track>, startIndex: Double?, startPosition: Double?) =
|
|
965
989
|
commandPlayer("setQueue") { player ->
|
|
966
|
-
player.setQueue(
|
|
990
|
+
player.setQueue(
|
|
991
|
+
tracks,
|
|
992
|
+
startIndex?.toQueueIndex() ?: 0,
|
|
993
|
+
((startPosition ?: 0.0) * 1000).toLong(),
|
|
994
|
+
)
|
|
967
995
|
}
|
|
968
996
|
|
|
969
997
|
override fun setActiveTrackFavorited(favorited: Boolean): Unit =
|
|
@@ -982,7 +1010,7 @@ class AudioBrowser : HybridAudioBrowserSpec(), ServiceConnection {
|
|
|
982
1010
|
override fun getTrack(index: Double): Track? =
|
|
983
1011
|
readPlayer(null) { player ->
|
|
984
1012
|
try {
|
|
985
|
-
player.getTrack(index.
|
|
1013
|
+
player.getTrack(index.toQueueIndex())
|
|
986
1014
|
} catch (e: IllegalArgumentException) {
|
|
987
1015
|
null
|
|
988
1016
|
}
|
|
@@ -8,7 +8,6 @@ import android.content.ServiceConnection
|
|
|
8
8
|
import android.content.pm.PackageManager
|
|
9
9
|
import android.os.Binder
|
|
10
10
|
import android.os.IBinder
|
|
11
|
-
import android.provider.MediaStore
|
|
12
11
|
import android.util.Log
|
|
13
12
|
import androidx.annotation.MainThread
|
|
14
13
|
import androidx.annotation.OptIn
|
|
@@ -29,10 +28,8 @@ import com.audiobrowser.util.BatteryWarningStore
|
|
|
29
28
|
import com.audiobrowser.util.CoilArtworkLoader
|
|
30
29
|
import com.audiobrowser.util.CoilArtworkLoaderHolder
|
|
31
30
|
import com.audiobrowser.util.CoilBitmapLoader
|
|
31
|
+
import com.audiobrowser.util.SearchParamsFactory
|
|
32
32
|
import com.margelo.nitro.audiobrowser.AppKilledPlaybackBehavior
|
|
33
|
-
import com.margelo.nitro.audiobrowser.MediaReference
|
|
34
|
-
import com.margelo.nitro.audiobrowser.SearchMode
|
|
35
|
-
import com.margelo.nitro.audiobrowser.SearchParams
|
|
36
33
|
import kotlinx.coroutines.CoroutineScope
|
|
37
34
|
import kotlinx.coroutines.Dispatchers
|
|
38
35
|
import kotlinx.coroutines.MainScope
|
|
@@ -188,7 +185,11 @@ class Service : MediaLibraryService(), MediaSessionService.Listener {
|
|
|
188
185
|
intent
|
|
189
186
|
?.takeIf { it.action == "android.media.action.MEDIA_PLAY_FROM_SEARCH" }
|
|
190
187
|
?.let { searchIntent ->
|
|
191
|
-
val searchParams =
|
|
188
|
+
val searchParams =
|
|
189
|
+
SearchParamsFactory.fromPlayFromSearch(
|
|
190
|
+
searchIntent.getStringExtra(SearchManager.QUERY) ?: "",
|
|
191
|
+
searchIntent.extras,
|
|
192
|
+
)
|
|
192
193
|
Timber.d("MEDIA_PLAY_FROM_SEARCH intent received: $searchParams")
|
|
193
194
|
// A search that plays has waited for AudioBrowser, whose MediaBrowser connecting hands
|
|
194
195
|
// the notification to Media3.
|
|
@@ -202,42 +203,6 @@ class Service : MediaLibraryService(), MediaSessionService.Listener {
|
|
|
202
203
|
return super.onStartCommand(intent, flags, startId)
|
|
203
204
|
}
|
|
204
205
|
|
|
205
|
-
/** See https://developer.android.com/guide/components/intents-common#PlaySearch */
|
|
206
|
-
private fun parseSearchIntent(intent: Intent): SearchParams {
|
|
207
|
-
val query = intent.getStringExtra(SearchManager.QUERY) ?: ""
|
|
208
|
-
|
|
209
|
-
val mediaFocus = intent.getStringExtra(MediaStore.EXTRA_MEDIA_FOCUS)
|
|
210
|
-
|
|
211
|
-
// The focus picks a vertical. Genre, artist and album focuses are filters, carried by the
|
|
212
|
-
// extras
|
|
213
|
-
// below, so they yield no mode. Android has no station or podcast focus: those verticals are
|
|
214
|
-
// iOS-only.
|
|
215
|
-
val mode =
|
|
216
|
-
when (mediaFocus) {
|
|
217
|
-
"vnd.android.cursor.item/*" -> if (query.isEmpty()) SearchMode.ANY else null
|
|
218
|
-
"vnd.android.cursor.item/audio" -> SearchMode.SONG
|
|
219
|
-
MediaStore.Audio.Playlists.ENTRY_CONTENT_TYPE -> SearchMode.PLAYLIST
|
|
220
|
-
else -> null
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
val genre = intent.getStringExtra("android.intent.extra.genre")
|
|
224
|
-
val artist = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ARTIST)
|
|
225
|
-
val album = intent.getStringExtra(MediaStore.EXTRA_MEDIA_ALBUM)
|
|
226
|
-
val title = intent.getStringExtra(MediaStore.EXTRA_MEDIA_TITLE)
|
|
227
|
-
val playlist = intent.getStringExtra("android.intent.extra.playlist")
|
|
228
|
-
|
|
229
|
-
return SearchParams(
|
|
230
|
-
mode = mode,
|
|
231
|
-
query = query,
|
|
232
|
-
genre = genre,
|
|
233
|
-
artist = artist,
|
|
234
|
-
album = album,
|
|
235
|
-
title = title,
|
|
236
|
-
playlist = playlist,
|
|
237
|
-
reference = MediaReference.UNKNOWN,
|
|
238
|
-
)
|
|
239
|
-
}
|
|
240
|
-
|
|
241
206
|
override fun onBind(intent: Intent?): IBinder? {
|
|
242
207
|
Timber.d("action: ${intent?.action}, package: ${intent?.`package`}")
|
|
243
208
|
return if (intent?.action != null) {
|
|
@@ -9,6 +9,7 @@ import com.audiobrowser.http.HttpClient
|
|
|
9
9
|
import com.audiobrowser.http.RequestConfigBuilder
|
|
10
10
|
import com.audiobrowser.util.BrowserPathHelper
|
|
11
11
|
import com.audiobrowser.util.FALLBACK_TIMEOUT
|
|
12
|
+
import com.audiobrowser.util.SearchParamsFactory
|
|
12
13
|
import com.audiobrowser.util.TrackFactory
|
|
13
14
|
import com.audiobrowser.util.artworkOf
|
|
14
15
|
import com.audiobrowser.util.awaitCancellable
|
|
@@ -35,6 +36,7 @@ import kotlinx.coroutines.async
|
|
|
35
36
|
import kotlinx.coroutines.awaitAll
|
|
36
37
|
import kotlinx.coroutines.coroutineScope
|
|
37
38
|
import kotlinx.coroutines.withContext
|
|
39
|
+
import kotlinx.serialization.SerializationException
|
|
38
40
|
import kotlinx.serialization.json.Json
|
|
39
41
|
import timber.log.Timber
|
|
40
42
|
|
|
@@ -709,8 +711,14 @@ class BrowserManager {
|
|
|
709
711
|
return content
|
|
710
712
|
}
|
|
711
713
|
|
|
712
|
-
/**
|
|
713
|
-
|
|
714
|
+
/**
|
|
715
|
+
* Re-resolves the current path, bypassing the cache, and returns whether it published the
|
|
716
|
+
* content. Overtaken by a later navigation or refresh, it publishes nothing and returns false,
|
|
717
|
+
* its failure only logged.
|
|
718
|
+
*
|
|
719
|
+
* @throws Exception when resolution fails and nothing has overtaken it
|
|
720
|
+
*/
|
|
721
|
+
suspend fun refresh(): Boolean {
|
|
714
722
|
val navigationId = ++currentNavigationId
|
|
715
723
|
|
|
716
724
|
val currentPath = path
|
|
@@ -720,11 +728,15 @@ class BrowserManager {
|
|
|
720
728
|
contentCache.remove(currentPath)
|
|
721
729
|
val content = resolve(currentPath, useCache = false)
|
|
722
730
|
|
|
723
|
-
if (navigationId
|
|
724
|
-
|
|
725
|
-
|
|
731
|
+
if (navigationId != currentNavigationId) return false
|
|
732
|
+
this.content = content
|
|
733
|
+
return true
|
|
734
|
+
} catch (e: CancellationException) {
|
|
735
|
+
throw e
|
|
726
736
|
} catch (e: Exception) {
|
|
727
|
-
|
|
737
|
+
if (navigationId == currentNavigationId) throw e
|
|
738
|
+
Timber.e(e, "Error in overtaken refresh for path: $currentPath")
|
|
739
|
+
return false
|
|
728
740
|
}
|
|
729
741
|
}
|
|
730
742
|
|
|
@@ -736,18 +748,7 @@ class BrowserManager {
|
|
|
736
748
|
}
|
|
737
749
|
|
|
738
750
|
suspend fun searchPlayable(query: String): Array<Track>? {
|
|
739
|
-
return searchPlayable(
|
|
740
|
-
SearchParams(
|
|
741
|
-
query = query,
|
|
742
|
-
mode = null,
|
|
743
|
-
genre = null,
|
|
744
|
-
artist = null,
|
|
745
|
-
album = null,
|
|
746
|
-
title = null,
|
|
747
|
-
playlist = null,
|
|
748
|
-
reference = MediaReference.UNKNOWN,
|
|
749
|
-
)
|
|
750
|
-
)
|
|
751
|
+
return searchPlayable(SearchParamsFactory.fromQuery(query))
|
|
751
752
|
}
|
|
752
753
|
|
|
753
754
|
/**
|
|
@@ -784,18 +785,7 @@ class BrowserManager {
|
|
|
784
785
|
}
|
|
785
786
|
|
|
786
787
|
suspend fun search(query: String): ResolvedTrack {
|
|
787
|
-
return search(
|
|
788
|
-
SearchParams(
|
|
789
|
-
query = query,
|
|
790
|
-
mode = null,
|
|
791
|
-
genre = null,
|
|
792
|
-
artist = null,
|
|
793
|
-
album = null,
|
|
794
|
-
title = null,
|
|
795
|
-
playlist = null,
|
|
796
|
-
reference = MediaReference.UNKNOWN,
|
|
797
|
-
)
|
|
798
|
-
)
|
|
788
|
+
return search(SearchParamsFactory.fromQuery(query))
|
|
799
789
|
}
|
|
800
790
|
|
|
801
791
|
/**
|
|
@@ -1145,8 +1135,22 @@ class BrowserManager {
|
|
|
1145
1135
|
response.fold(
|
|
1146
1136
|
onSuccess = { httpResponse ->
|
|
1147
1137
|
if (httpResponse.isSuccessful) {
|
|
1148
|
-
val jsonResolvedTrack =
|
|
1149
|
-
|
|
1138
|
+
val jsonResolvedTrack =
|
|
1139
|
+
try {
|
|
1140
|
+
json.decodeFromString<JsonResolvedTrack>(httpResponse.body).also {
|
|
1141
|
+
// A browse page needs its title (BrowserSource); the tabs page does not.
|
|
1142
|
+
if (it.title == null && path != TABS_ROUTE_PATH) {
|
|
1143
|
+
throw SerializationException("Field 'title' is required for a browse page")
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
} catch (e: Exception) {
|
|
1147
|
+
throw HttpStatusException(
|
|
1148
|
+
httpResponse.code,
|
|
1149
|
+
"Server returned ${httpResponse.code} with a response that is not a page: ${e.message}",
|
|
1150
|
+
e,
|
|
1151
|
+
)
|
|
1152
|
+
}
|
|
1153
|
+
jsonResolvedTrack.toNitro(requestedPath = path)
|
|
1150
1154
|
} else {
|
|
1151
1155
|
Timber.w(
|
|
1152
1156
|
"HTTP request failed with status ${httpResponse.code} for ${httpRequest.url}: ${httpResponse.body}"
|
|
@@ -1219,11 +1223,13 @@ class BrowserManager {
|
|
|
1219
1223
|
|
|
1220
1224
|
class ContentNotFoundException(val path: String) : Exception("Content not found")
|
|
1221
1225
|
|
|
1222
|
-
|
|
1226
|
+
/** A non-2xx response, or a 2xx response whose body does not parse. */
|
|
1227
|
+
class HttpStatusException(val statusCode: Int, message: String, cause: Throwable? = null) :
|
|
1228
|
+
Exception(message, cause)
|
|
1223
1229
|
|
|
1224
1230
|
class NetworkException(message: String, cause: Throwable? = null) : Exception(message, cause)
|
|
1225
1231
|
|
|
1226
|
-
class CallbackException(message: String) : Exception(message)
|
|
1232
|
+
class CallbackException(message: String, cause: Throwable? = null) : Exception(message, cause)
|
|
1227
1233
|
|
|
1228
1234
|
/** Mirrors NativeBrowserConfiguration from JS. */
|
|
1229
1235
|
data class BrowserConfig(
|
|
@@ -38,10 +38,10 @@ suspend fun BrowserManager.resolveMediaUrl(originalUrl: String, track: Track): M
|
|
|
38
38
|
contentType = null,
|
|
39
39
|
userAgent = null,
|
|
40
40
|
)
|
|
41
|
-
requestConfig?.let { base = RequestConfigBuilder.
|
|
41
|
+
requestConfig?.let { base = RequestConfigBuilder.mergeConfigOrBase(base, it) }
|
|
42
42
|
val mediaLayered =
|
|
43
43
|
if (mediaConfig != null) {
|
|
44
|
-
RequestConfigBuilder.
|
|
44
|
+
RequestConfigBuilder.mergeConfigOrBase(base, mediaConfig)
|
|
45
45
|
} else {
|
|
46
46
|
MediaRequestConfig(
|
|
47
47
|
resolve = null,
|
|
@@ -95,7 +95,7 @@ suspend fun BrowserManager.resolveArtworkUrl(
|
|
|
95
95
|
userAgent = null,
|
|
96
96
|
)
|
|
97
97
|
resolvedRequestConfig()?.let {
|
|
98
|
-
mergedConfig = RequestConfigBuilder.
|
|
98
|
+
mergedConfig = RequestConfigBuilder.mergeConfigOrBase(mergedConfig, it, emptyMap())
|
|
99
99
|
}
|
|
100
100
|
if (trackArtwork != null) {
|
|
101
101
|
mergedConfig = mergedConfig.copy(path = trackArtwork)
|
|
@@ -259,10 +259,11 @@ private fun buildHeadersMap(
|
|
|
259
259
|
): Map<String, String>? {
|
|
260
260
|
val mergedHeaders = mutableMapOf<String, String>()
|
|
261
261
|
headers?.let { mergedHeaders.putAll(it) }
|
|
262
|
-
|
|
262
|
+
fun hasHeader(name: String) = mergedHeaders.keys.any { it.equals(name, ignoreCase = true) }
|
|
263
|
+
if (userAgent != null && !hasHeader("User-Agent")) {
|
|
263
264
|
mergedHeaders["User-Agent"] = userAgent
|
|
264
265
|
}
|
|
265
|
-
if (contentType != null && !
|
|
266
|
+
if (contentType != null && !hasHeader("Content-Type")) {
|
|
266
267
|
mergedHeaders["Content-Type"] = contentType
|
|
267
268
|
}
|
|
268
269
|
return mergedHeaders.ifEmpty { null }
|
|
@@ -40,8 +40,8 @@ data class JsonSection(
|
|
|
40
40
|
@Serializable
|
|
41
41
|
data class JsonResolvedTrack(
|
|
42
42
|
val id: String? = null,
|
|
43
|
-
val path: String,
|
|
44
|
-
val title: String,
|
|
43
|
+
val path: String? = null,
|
|
44
|
+
val title: String? = null,
|
|
45
45
|
val subtitle: String? = null,
|
|
46
46
|
val icon: String? = null,
|
|
47
47
|
val artwork: JsonArtwork? = null,
|
|
@@ -56,6 +56,7 @@ data class JsonResolvedTrack(
|
|
|
56
56
|
val src: String? = null,
|
|
57
57
|
val style: JsonElement? = null,
|
|
58
58
|
val disabled: Boolean? = null,
|
|
59
|
+
val favorited: Boolean? = null,
|
|
59
60
|
val live: Boolean? = null,
|
|
60
61
|
val icyCharset: String? = null,
|
|
61
62
|
val carPlaySiriListButton: String? = null,
|
|
@@ -79,6 +80,7 @@ data class JsonTrack(
|
|
|
79
80
|
val request: JsonTrackRequest? = null,
|
|
80
81
|
val style: JsonElement? = null,
|
|
81
82
|
val disabled: Boolean? = null,
|
|
83
|
+
val favorited: Boolean? = null,
|
|
82
84
|
val live: Boolean? = null,
|
|
83
85
|
val icyCharset: String? = null,
|
|
84
86
|
)
|
|
@@ -140,14 +142,17 @@ fun JsonSection.toNitro(): Section {
|
|
|
140
142
|
)
|
|
141
143
|
}
|
|
142
144
|
|
|
143
|
-
|
|
145
|
+
/**
|
|
146
|
+
* The page, with [requestedPath] as its path when it has none and an empty title when it has none.
|
|
147
|
+
*/
|
|
148
|
+
fun JsonResolvedTrack.toNitro(requestedPath: String): ResolvedTrack {
|
|
144
149
|
return ResolvedTrack(
|
|
145
150
|
id = id,
|
|
146
|
-
path = path,
|
|
151
|
+
path = path ?: requestedPath,
|
|
147
152
|
sections = sections?.map { it.toNitro() }?.toTypedArray(),
|
|
148
153
|
children = children?.map { it.toNitro() }?.toTypedArray(),
|
|
149
154
|
carPlaySiriListButton = carPlaySiriListButton.toCarPlaySiriListButtonPosition(),
|
|
150
|
-
title = title,
|
|
155
|
+
title = title ?: "",
|
|
151
156
|
subtitle = subtitle,
|
|
152
157
|
artwork = artwork?.toNitro(),
|
|
153
158
|
artworkSource = null,
|
|
@@ -162,7 +167,7 @@ fun JsonResolvedTrack.toNitro(): ResolvedTrack {
|
|
|
162
167
|
src = src,
|
|
163
168
|
style = style.toSectionStyle(),
|
|
164
169
|
disabled = disabled,
|
|
165
|
-
favorited =
|
|
170
|
+
favorited = favorited,
|
|
166
171
|
live = live,
|
|
167
172
|
icyCharset = icyCharset,
|
|
168
173
|
)
|
|
@@ -186,7 +191,7 @@ fun JsonTrack.toNitro(): Track {
|
|
|
186
191
|
src = src,
|
|
187
192
|
style = style.toTrackStyle(),
|
|
188
193
|
disabled = disabled,
|
|
189
|
-
favorited =
|
|
194
|
+
favorited = favorited,
|
|
190
195
|
live = live,
|
|
191
196
|
icyCharset = icyCharset,
|
|
192
197
|
)
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
package com.audiobrowser.extension
|
|
2
|
+
|
|
3
|
+
import kotlin.math.truncate
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The queue index a JS number names, its fraction dropped.
|
|
7
|
+
*
|
|
8
|
+
* @throws IllegalArgumentException for a number no `Int` holds: NaN, infinite, or beyond `Int`'s
|
|
9
|
+
* range.
|
|
10
|
+
*/
|
|
11
|
+
fun Double.toQueueIndex(): Int {
|
|
12
|
+
val whole = truncate(this)
|
|
13
|
+
if (whole.isNaN() || whole < Int.MIN_VALUE || whole > Int.MAX_VALUE) {
|
|
14
|
+
throw IllegalArgumentException(
|
|
15
|
+
"Invalid track index: index must be a finite number within the range of Int, got $this"
|
|
16
|
+
)
|
|
17
|
+
}
|
|
18
|
+
return whole.toInt()
|
|
19
|
+
}
|
|
@@ -88,7 +88,8 @@ class HttpClient {
|
|
|
88
88
|
Headers.Builder()
|
|
89
89
|
.apply {
|
|
90
90
|
httpRequest.headers?.forEach { (name, value) -> add(name, value) }
|
|
91
|
-
|
|
91
|
+
// A `User-Agent` header in any case wins over `userAgent`.
|
|
92
|
+
if (get("User-Agent") == null) add("User-Agent", httpRequest.userAgent)
|
|
92
93
|
}
|
|
93
94
|
.build()
|
|
94
95
|
requestBuilder.headers(headers)
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
package com.audiobrowser.http
|
|
2
2
|
|
|
3
|
+
import com.audiobrowser.browser.CallbackException
|
|
3
4
|
import com.audiobrowser.util.BrowserPathHelper
|
|
4
5
|
import com.audiobrowser.util.awaitCancellable
|
|
5
6
|
import com.audiobrowser.util.awaitNested
|
|
@@ -92,8 +93,9 @@ object RequestConfigBuilder {
|
|
|
92
93
|
/**
|
|
93
94
|
* Applies [override] as a Request-Config Layer (GLOSSARY.md): its transforms, async then sync,
|
|
94
95
|
* replace the config and its static fields are then ignored; without one, its static fields merge
|
|
95
|
-
* over [base] except `path`, which stays the base's. Mirrors iOS `applyLayer`.
|
|
96
|
-
*
|
|
96
|
+
* over [base] except `path`, which stays the base's. Mirrors iOS `applyLayer`.
|
|
97
|
+
*
|
|
98
|
+
* @throws CallbackException when a transform throws
|
|
97
99
|
*/
|
|
98
100
|
suspend fun mergeConfig(
|
|
99
101
|
base: RequestConfig,
|
|
@@ -111,21 +113,35 @@ object RequestConfigBuilder {
|
|
|
111
113
|
} catch (e: CancellationException) {
|
|
112
114
|
throw e
|
|
113
115
|
} catch (e: Exception) {
|
|
114
|
-
|
|
115
|
-
|
|
116
|
+
// A JS call that throws reaches here as JSError's `what()`, `message\n\nstack`.
|
|
117
|
+
throw CallbackException(e.message?.substringBefore("\n\n") ?: e.toString(), e)
|
|
116
118
|
}
|
|
117
119
|
}
|
|
118
120
|
|
|
119
121
|
/**
|
|
120
|
-
*
|
|
121
|
-
*
|
|
122
|
+
* [mergeConfig] for media and artwork, where a throwing transform costs its own layer and not the
|
|
123
|
+
* stack: the layers under it stand, so a relative path still gets the shared `baseUrl` and a
|
|
124
|
+
* media request keeps the shared credential.
|
|
122
125
|
*/
|
|
123
|
-
suspend fun
|
|
126
|
+
suspend fun mergeConfigOrBase(
|
|
127
|
+
base: RequestConfig,
|
|
128
|
+
override: TransformableRequestConfig,
|
|
129
|
+
routeParams: Map<String, String>? = null,
|
|
130
|
+
): RequestConfig =
|
|
131
|
+
try {
|
|
132
|
+
mergeConfig(base, override, routeParams)
|
|
133
|
+
} catch (e: CallbackException) {
|
|
134
|
+
Timber.e(e.cause, "Failed to apply transform function, using base config")
|
|
135
|
+
base
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** The layer rule of [mergeConfigOrBase], keeping [override]'s resolve callbacks. */
|
|
139
|
+
suspend fun mergeConfigOrBase(
|
|
124
140
|
base: RequestConfig,
|
|
125
141
|
override: MediaRequestConfig,
|
|
126
142
|
routeParams: Map<String, String>? = null,
|
|
127
143
|
): MediaRequestConfig =
|
|
128
|
-
override.withRequestFields(
|
|
144
|
+
override.withRequestFields(mergeConfigOrBase(base, override.asTransformable(), routeParams))
|
|
129
145
|
|
|
130
146
|
private fun MediaRequestConfig.asTransformable() =
|
|
131
147
|
TransformableRequestConfig(
|
|
@@ -230,17 +246,15 @@ object RequestConfigBuilder {
|
|
|
230
246
|
|
|
231
247
|
val url = BrowserPathHelper.buildUrl(baseUrl, path)
|
|
232
248
|
|
|
249
|
+
val query = config.query
|
|
250
|
+
if (query.isNullOrEmpty()) return url
|
|
251
|
+
|
|
233
252
|
val queryString =
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
}
|
|
240
|
-
} else ""
|
|
241
|
-
} ?: ""
|
|
242
|
-
|
|
243
|
-
return "$url$queryString"
|
|
253
|
+
query.entries.joinToString("&") { (key, value) ->
|
|
254
|
+
"${encodeUrlParam(key)}=${encodeUrlParam(value)}"
|
|
255
|
+
}
|
|
256
|
+
val separator = if (url.contains('?')) "&" else "?"
|
|
257
|
+
return "$url$separator$queryString"
|
|
244
258
|
}
|
|
245
259
|
|
|
246
260
|
private fun encodeUrlParam(param: String): String {
|
|
@@ -131,8 +131,8 @@ data class PlayerSetupOptions(
|
|
|
131
131
|
|
|
132
132
|
options.keepSessionAliveOnError?.let { keepSessionAliveOnError = it }
|
|
133
133
|
options.autoUpdateNowPlayingMetadata?.let { autoUpdateNowPlayingMetadata = it }
|
|
134
|
-
|
|
135
|
-
|
|
134
|
+
// Unlike the fields above, an absent value removes the formatter and turns remote outputs off.
|
|
135
|
+
nowPlayingMetadataFormatter = options.nowPlayingMetadataFormatter
|
|
136
136
|
remoteOutputs = options.remoteOutputs
|
|
137
137
|
}
|
|
138
138
|
}
|