react-native-audio-browser 0.2.0-next.44 → 0.2.0-next.46
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/browser/BrowseArtworkRegistry.kt +23 -10
- package/android/src/main/java/com/audiobrowser/player/MediaSessionCallback.kt +148 -99
- package/android/src/main/java/com/audiobrowser/player/MediaSessionCommandManager.kt +16 -4
- package/android/src/main/java/com/audiobrowser/player/NowPlayingUpdater.kt +68 -21
- package/android/src/main/java/com/audiobrowser/player/Player.kt +28 -5
- package/android/src/main/java/com/audiobrowser/util/ArtworkRoutes.kt +39 -0
- package/android/src/main/java/com/audiobrowser/util/Automotive.kt +15 -0
- package/android/src/main/java/com/audiobrowser/util/BrowserPathHelper.kt +1 -2
- package/android/src/main/java/com/audiobrowser/util/MetadataAdapter.kt +5 -1
- package/android/src/main/java/com/audiobrowser/util/TrackFactory.kt +38 -18
- package/android/src/test/java/com/audiobrowser/player/AutomotiveSkipTest.kt +93 -0
- package/android/src/test/java/com/audiobrowser/player/BrowseTilesTest.kt +92 -0
- package/android/src/test/java/com/audiobrowser/player/LiveSeekCommandTest.kt +1 -1
- package/android/src/test/java/com/audiobrowser/player/NowPlayingUpdaterTest.kt +170 -0
- package/android/src/test/java/com/audiobrowser/util/TrackFactoryRatingTest.kt +75 -0
- package/ios/Player/NowPlayingLines.swift +16 -0
- package/ios/Player/NowPlayingUpdater.swift +11 -9
- package/ios/Tests/NowPlayingLinesTests.swift +23 -0
- package/package.json +1 -1
|
@@ -1,7 +1,10 @@
|
|
|
1
1
|
package com.audiobrowser.util
|
|
2
2
|
|
|
3
|
+
import androidx.core.net.toUri
|
|
3
4
|
import androidx.media3.common.HeartRating
|
|
4
5
|
import com.audiobrowser.TestFixtures
|
|
6
|
+
import com.audiobrowser.browser.BrowseArtworkRegistry
|
|
7
|
+
import org.junit.After
|
|
5
8
|
import org.junit.Assert.assertEquals
|
|
6
9
|
import org.junit.Assert.assertNull
|
|
7
10
|
import org.junit.Assert.assertTrue
|
|
@@ -32,4 +35,76 @@ class TrackFactoryRatingTest {
|
|
|
32
35
|
val item = TrackFactory.toMedia3(TestFixtures.track(favorited = null))
|
|
33
36
|
assertNull(item.mediaMetadata.userRating)
|
|
34
37
|
}
|
|
38
|
+
|
|
39
|
+
@After
|
|
40
|
+
fun resetDevice() {
|
|
41
|
+
Automotive.device = false
|
|
42
|
+
TrackFactory.artworkRoutes = null
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
private fun automotive(): BrowseArtworkRegistry =
|
|
46
|
+
BrowseArtworkRegistry().also {
|
|
47
|
+
Automotive.device = true
|
|
48
|
+
TrackFactory.artworkRoutes = ArtworkRoutes(it, "app.artwork")
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@Test
|
|
52
|
+
fun `Android Automotive OS advertises no userRating`() {
|
|
53
|
+
automotive()
|
|
54
|
+
val item = TrackFactory.toMedia3(TestFixtures.track(favorited = true))
|
|
55
|
+
assertNull(item.mediaMetadata.userRating)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Test
|
|
59
|
+
fun `Android Automotive OS serves http artwork through the provider`() {
|
|
60
|
+
val registry = automotive()
|
|
61
|
+
val item = TrackFactory.toMedia3(TestFixtures.track(artwork = "https://a/1.png"))
|
|
62
|
+
val uri = item.mediaMetadata.artworkUri!!
|
|
63
|
+
assertEquals("content", uri.scheme)
|
|
64
|
+
assertEquals("app.artwork", uri.authority)
|
|
65
|
+
assertEquals("https://a/1.png", registry.lookup(ArtworkUris.parseToken(uri)!!)!!.finalUrl)
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
@Test
|
|
69
|
+
fun `a phone keeps the http artwork`() {
|
|
70
|
+
TrackFactory.artworkRoutes = ArtworkRoutes(BrowseArtworkRegistry(), "app.artwork")
|
|
71
|
+
val item = TrackFactory.toMedia3(TestFixtures.track(artwork = "https://a/1.png"))
|
|
72
|
+
assertEquals("https://a/1.png", item.mediaMetadata.artworkUri.toString())
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@Test
|
|
76
|
+
fun `Android Automotive OS keeps non-http artwork as it is`() {
|
|
77
|
+
automotive()
|
|
78
|
+
assertEquals(
|
|
79
|
+
"android.resource://app/1",
|
|
80
|
+
TrackFactory.sessionArtworkUri("android.resource://app/1", null, isSvg = false),
|
|
81
|
+
)
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
@Test
|
|
85
|
+
fun `the session's artwork outlives a clear of the registry, and maps back to its URL`() {
|
|
86
|
+
val registry = automotive()
|
|
87
|
+
val uri = TrackFactory.sessionArtworkUri("https://a/1.png", null, isSvg = false).toUri()
|
|
88
|
+
registry.clear()
|
|
89
|
+
assertEquals("https://a/1.png", TrackFactory.artworkRoutes!!.publicUrl(uri))
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
@Test
|
|
93
|
+
fun `JS gets another URI as it is, and none for artwork the provider forgot`() {
|
|
94
|
+
automotive()
|
|
95
|
+
val routes = TrackFactory.artworkRoutes!!
|
|
96
|
+
assertEquals("https://a/1.png", routes.publicUrl("https://a/1.png".toUri()))
|
|
97
|
+
assertEquals("content://other/art/x", routes.publicUrl("content://other/art/x".toUri()))
|
|
98
|
+
assertNull(routes.publicUrl("content://app.artwork/art/forgotten".toUri()))
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
@Test
|
|
102
|
+
fun `the session pins a browse item's provider URI it is handed back`() {
|
|
103
|
+
val registry = automotive()
|
|
104
|
+
val browseUri =
|
|
105
|
+
ArtworkRoutes(registry, "app.artwork").route("https://a/1.png", null, false, pinned = false)
|
|
106
|
+
assertEquals(browseUri, TrackFactory.sessionArtworkUri(browseUri, null, isSvg = false))
|
|
107
|
+
registry.clear()
|
|
108
|
+
assertEquals("https://a/1.png", TrackFactory.artworkRoutes!!.publicUrl(browseUri.toUri()))
|
|
109
|
+
}
|
|
35
110
|
}
|
|
@@ -25,6 +25,22 @@ struct NowPlayingLines: Equatable {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
+
/// The lines last stamped on the now-playing surface, and the track they were stamped for.
|
|
29
|
+
struct PublishedNowPlayingLines {
|
|
30
|
+
let trackId: String?
|
|
31
|
+
let lines: NowPlayingLines
|
|
32
|
+
|
|
33
|
+
init(_ lines: NowPlayingLines, for track: Track) {
|
|
34
|
+
trackId = track.identity ?? track.path
|
|
35
|
+
self.lines = lines
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/// `lines` when they were stamped for `track`, else nil.
|
|
39
|
+
func lines(for track: Track) -> NowPlayingLines? {
|
|
40
|
+
trackId == (track.identity ?? track.path) ? lines : nil
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
28
44
|
/// What the now-playing surface renders from: the player's track and state.
|
|
29
45
|
@MainActor
|
|
30
46
|
protocol NowPlayingSource: AnyObject {
|
|
@@ -33,8 +33,9 @@ final class NowPlayingUpdater {
|
|
|
33
33
|
|
|
34
34
|
private var artworkLoadTask: Task<Void, Never>?
|
|
35
35
|
|
|
36
|
-
/// The
|
|
37
|
-
|
|
36
|
+
/// The lines `onChanged` last reported, and their track, so a new track with the same text
|
|
37
|
+
/// still reports.
|
|
38
|
+
private var published: PublishedNowPlayingLines?
|
|
38
39
|
|
|
39
40
|
func setOverride(_ update: NowPlayingUpdate?) {
|
|
40
41
|
override = update
|
|
@@ -73,11 +74,13 @@ final class NowPlayingUpdater {
|
|
|
73
74
|
render()
|
|
74
75
|
}
|
|
75
76
|
|
|
76
|
-
/// The
|
|
77
|
-
///
|
|
77
|
+
/// The lines the surface shows for the current track, formatter result included; until the
|
|
78
|
+
/// track's first render, and while `enabled` is false, the flash, override or track fields.
|
|
78
79
|
var nowPlaying: NowPlayingMetadata? {
|
|
79
80
|
guard let track = source?.currentTrack else { return nil }
|
|
80
|
-
|
|
81
|
+
let rendered = enabled ? published?.lines(for: track) : nil
|
|
82
|
+
let lines = rendered ?? .resolve(track: track, flash: flash, override: override)
|
|
83
|
+
return metadata(track: track, lines: lines)
|
|
81
84
|
}
|
|
82
85
|
|
|
83
86
|
/// Empties the now-playing surface and drops any artwork fetch or formatter result in flight.
|
|
@@ -86,7 +89,7 @@ final class NowPlayingUpdater {
|
|
|
86
89
|
artworkLoadTask?.cancel()
|
|
87
90
|
artworkLoadTask = nil
|
|
88
91
|
nowPlayingInfoController.clear()
|
|
89
|
-
|
|
92
|
+
published = nil
|
|
90
93
|
formattedTrackId = nil
|
|
91
94
|
}
|
|
92
95
|
|
|
@@ -212,9 +215,8 @@ final class NowPlayingUpdater {
|
|
|
212
215
|
MPMediaItemPropertyArtist: lines.artist,
|
|
213
216
|
MPMediaItemPropertyAlbumTitle: lines.album,
|
|
214
217
|
])
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
publishedTrackId = trackId
|
|
218
|
+
guard textChanged || published?.lines(for: track) == nil else { return }
|
|
219
|
+
published = PublishedNowPlayingLines(lines, for: track)
|
|
218
220
|
onChanged?(metadata(track: track, lines: lines))
|
|
219
221
|
}
|
|
220
222
|
|
|
@@ -41,3 +41,26 @@ struct NowPlayingLinesTests {
|
|
|
41
41
|
#expect(lines == NowPlayingLines(title: "Station", artist: nil, album: nil))
|
|
42
42
|
}
|
|
43
43
|
}
|
|
44
|
+
|
|
45
|
+
@Suite("PublishedNowPlayingLines")
|
|
46
|
+
struct PublishedNowPlayingLinesTests {
|
|
47
|
+
private let station = Track(src: "https://s/a.mp3", title: "Station", artist: "City")
|
|
48
|
+
private let liveSong = NowPlayingLines(title: "Station", artist: "Song - Artist", album: nil)
|
|
49
|
+
|
|
50
|
+
@Test func theStampedTrackGetsItsLines() {
|
|
51
|
+
let published = PublishedNowPlayingLines(liveSong, for: station)
|
|
52
|
+
#expect(published.lines(for: station) == liveSong)
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
@Test func anotherTrackGetsNone() {
|
|
56
|
+
let published = PublishedNowPlayingLines(liveSong, for: station)
|
|
57
|
+
#expect(published.lines(for: Track(src: "https://s/b.mp3", title: "Station", artist: "City")) == nil)
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
@Test func aTrackWithoutIdentityMatchesOnItsPath() {
|
|
61
|
+
let folder = Track(path: "/a", title: "Folder")
|
|
62
|
+
let published = PublishedNowPlayingLines(liveSong, for: folder)
|
|
63
|
+
#expect(published.lines(for: folder) == liveSong)
|
|
64
|
+
#expect(published.lines(for: Track(path: "/b", title: "Folder")) == nil)
|
|
65
|
+
}
|
|
66
|
+
}
|