react-native-audio-browser 0.2.0-next.77 → 0.2.0-next.78

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.
@@ -135,6 +135,27 @@ internal class RemoteSwitchingPlayer(
135
135
  private val remoteRoute: Route.Remote?
136
136
  get() = route as? Route.Remote
137
137
 
138
+ /** For the next [getState] to take [titleAtStop]: super.getState() consumes pending events. */
139
+ private var localStopPending = false
140
+
141
+ /**
142
+ * The phone's metadata as it stopped, reported as none until the phone sends more. The state
143
+ * emits only a change, and a stream's first title after a reconnect often equals its last.
144
+ */
145
+ private var titleAtStop: Metadata? = null
146
+
147
+ private fun withoutStoppedTitle(state: State): State {
148
+ if (localStopPending) {
149
+ localStopPending = false
150
+ titleAtStop = state.timedMetadata
151
+ }
152
+ if (state.timedMetadata !== titleAtStop) {
153
+ titleAtStop = null
154
+ return state
155
+ }
156
+ return state.buildUpon().setTimedMetadata(NO_TIMED_METADATA).build()
157
+ }
158
+
138
159
  private val receiverListener =
139
160
  object : MediaPlayer.Listener {
140
161
  override fun onMetadata(metadata: Metadata) {
@@ -441,7 +462,7 @@ internal class RemoteSwitchingPlayer(
441
462
 
442
463
  override fun getState(): State {
443
464
  val state = super.getState()
444
- val remote = remoteRoute ?: return state
465
+ val remote = remoteRoute ?: return withoutStoppedTitle(state)
445
466
  val load = remote.load
446
467
  val holds = load is Load.Playing && receiverHolds(remote, load.item)
447
468
  // Duration, seekability and liveness come from the receiver's data for the item it plays.
@@ -541,7 +562,11 @@ internal class RemoteSwitchingPlayer(
541
562
  }
542
563
 
543
564
  override fun handleStop(): ListenableFuture<*> {
544
- val remote = remoteRoute ?: return super.handleStop()
565
+ val remote = remoteRoute
566
+ if (remote == null) {
567
+ localStopPending = true
568
+ return super.handleStop()
569
+ }
545
570
  val positionMs = positionOn(remote)
546
571
  cancelLoad(remote)
547
572
  stopReceiver(remote.receiver)
@@ -26,6 +26,16 @@ internal class FakeLocalPlayer(looper: Looper) : SimpleBasePlayer(looper) {
26
26
  private var repeat = REPEAT_MODE_OFF
27
27
  private var shuffle = false
28
28
  private val uids = mutableListOf<Any>()
29
+ private var metadata = Metadata(C.TIME_UNSET)
30
+
31
+ /**
32
+ * Sends a stream title. ExoPlayer sends each one it decodes; this state emits only a change, so a
33
+ * stop clears it for the stream's first title after a reconnect to go out again.
34
+ */
35
+ fun title(title: String) {
36
+ metadata = Metadata(0, IcyInfo(title.toByteArray(), title, null))
37
+ invalidateState()
38
+ }
29
39
 
30
40
  override fun getState(): State =
31
41
  State.Builder()
@@ -44,6 +54,7 @@ internal class FakeLocalPlayer(looper: Looper) : SimpleBasePlayer(looper) {
44
54
  .setPlaybackState(if (items.isEmpty()) STATE_IDLE else readiness)
45
55
  .setRepeatMode(repeat)
46
56
  .setShuffleModeEnabled(shuffle)
57
+ .setTimedMetadata(metadata)
47
58
  .build()
48
59
 
49
60
  /** Moves to [index] without a seek, as the player does at an item's end. */
@@ -86,6 +97,7 @@ internal class FakeLocalPlayer(looper: Looper) : SimpleBasePlayer(looper) {
86
97
 
87
98
  override fun handleStop(): ListenableFuture<*> {
88
99
  readiness = STATE_IDLE
100
+ metadata = Metadata(C.TIME_UNSET)
89
101
  stops++
90
102
  return done()
91
103
  }
@@ -911,6 +911,22 @@ class RemoteSwitchingPlayerTest {
911
911
  assertEquals(listOf("a", "Song"), seen)
912
912
  }
913
913
 
914
+ @Test
915
+ fun `a play after a local stop shows the stream's title again`() {
916
+ playLocally(listOf("a"))
917
+ local.title("Song")
918
+ idle()
919
+ val seen = transitionsAndTitles()
920
+
921
+ player.stop()
922
+ player.prepare()
923
+ idle()
924
+ local.title("Song")
925
+ idle()
926
+
927
+ assertEquals(listOf("Song"), seen)
928
+ }
929
+
914
930
  @Test
915
931
  fun `release brings playback back and lets every remote go`() {
916
932
  playLocally(listOf("a"))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-audio-browser",
3
- "version": "0.2.0-next.77",
3
+ "version": "0.2.0-next.78",
4
4
  "description": "react-native-audio-browser is a react native package built with Nitro",
5
5
  "keywords": [
6
6
  "react-native",