react-native-audio-browser 0.2.0-next.86 → 0.2.0-next.88
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/player/MediaSessionCallback.kt +6 -2
- package/android/src/main/java/com/audiobrowser/player/PlaybackStateStore.kt +1 -3
- package/android/src/main/java/com/audiobrowser/player/Player.kt +11 -0
- package/android/src/main/java/com/audiobrowser/player/SessionViewListener.kt +25 -5
- package/android/src/test/java/com/audiobrowser/AudioFixtures.kt +32 -0
- package/android/src/test/java/com/audiobrowser/LegacyRatingTest.kt +6 -19
- package/android/src/test/java/com/audiobrowser/ServiceFixtures.kt +48 -0
- package/android/src/test/java/com/audiobrowser/ServiceTaskRemovedTest.kt +2 -34
- package/android/src/test/java/com/audiobrowser/SessionPositionUpdatesTest.kt +4 -63
- package/android/src/test/java/com/audiobrowser/player/HandleTrackLoadSeekTest.kt +182 -0
- package/android/src/test/java/com/audiobrowser/player/LiveStreamEndTest.kt +6 -24
- package/android/src/test/java/com/audiobrowser/player/PlayerRetryTest.kt +15 -40
- package/android/src/test/java/com/audiobrowser/player/PlayerSetupEndedTest.kt +2 -28
- package/android/src/test/java/com/audiobrowser/player/PlayerSuppressionTest.kt +3 -28
- package/android/src/test/java/com/audiobrowser/player/SessionPlayTest.kt +6 -32
- package/android/src/test/java/com/audiobrowser/player/SessionViewListenerTest.kt +204 -0
- package/android/src/test/java/com/audiobrowser/player/SessionViewTest.kt +75 -31
- package/package.json +1 -1
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
package com.audiobrowser.player
|
|
2
2
|
|
|
3
|
-
import android.net.Uri
|
|
4
3
|
import android.os.Looper
|
|
5
4
|
import androidx.media3.common.C
|
|
6
5
|
import androidx.media3.common.Player as MediaPlayer
|
|
6
|
+
import androidx.media3.common.Timeline
|
|
7
7
|
import androidx.media3.session.MediaSession
|
|
8
8
|
import androidx.media3.session.controllerTitle
|
|
9
|
+
import androidx.media3.session.countLegacyStateUpdates
|
|
9
10
|
import androidx.media3.session.legacy.PlaybackStateCompat
|
|
10
11
|
import androidx.media3.session.legacyState
|
|
11
12
|
import com.audiobrowser.Callbacks
|
|
@@ -13,12 +14,17 @@ import com.audiobrowser.TestFixtures
|
|
|
13
14
|
import com.audiobrowser.goOnline
|
|
14
15
|
import com.audiobrowser.model.PlayerSetupOptions
|
|
15
16
|
import com.audiobrowser.model.RetryPolicy
|
|
17
|
+
import com.audiobrowser.silentWavBytes
|
|
18
|
+
import com.audiobrowser.silentWavUri
|
|
16
19
|
import com.audiobrowser.util.TrackFactory
|
|
17
20
|
import com.margelo.nitro.audiobrowser.PlaybackState
|
|
18
|
-
import java.io.
|
|
19
|
-
import java.
|
|
20
|
-
import java.nio.ByteOrder
|
|
21
|
+
import java.io.IOException
|
|
22
|
+
import java.net.ServerSocket
|
|
21
23
|
import java.time.Duration
|
|
24
|
+
import java.util.concurrent.CountDownLatch
|
|
25
|
+
import java.util.concurrent.TimeUnit
|
|
26
|
+
import java.util.concurrent.atomic.AtomicInteger
|
|
27
|
+
import kotlin.concurrent.thread
|
|
22
28
|
import org.junit.After
|
|
23
29
|
import org.junit.Assert.assertEquals
|
|
24
30
|
import org.junit.Assert.fail
|
|
@@ -113,7 +119,7 @@ class SessionViewTest {
|
|
|
113
119
|
|
|
114
120
|
@Test
|
|
115
121
|
fun `an ended queue a rebuild carried idle reads ended`() {
|
|
116
|
-
play(RetryPolicy.Default,
|
|
122
|
+
play(RetryPolicy.Default, folder.silentWavUri(Duration.ofMillis(500)))
|
|
117
123
|
idleUntil("ENDED") { player.playbackState == PlaybackState.ENDED }
|
|
118
124
|
|
|
119
125
|
player.setup(PlayerSetupOptions(maxBuffer = 120_000.0))
|
|
@@ -125,18 +131,77 @@ class SessionViewTest {
|
|
|
125
131
|
|
|
126
132
|
@Test
|
|
127
133
|
fun `the session hears the current track's title`() {
|
|
128
|
-
play(RetryPolicy.Default,
|
|
134
|
+
play(RetryPolicy.Default, folder.silentWavUri(Duration.ofMillis(500)))
|
|
129
135
|
idleUntil("ENDED") { player.playbackState == PlaybackState.ENDED }
|
|
130
136
|
|
|
131
137
|
assertEquals("T", session.controllerTitle())
|
|
132
138
|
}
|
|
133
139
|
|
|
140
|
+
@Test
|
|
141
|
+
fun `a reconnect attempt tells the session nothing it was already told`() {
|
|
142
|
+
val server = ServerSocket(0)
|
|
143
|
+
val connections = AtomicInteger()
|
|
144
|
+
val drop = CountDownLatch(1)
|
|
145
|
+
// Serves five seconds of a stream until the drop, then ends each connection unanswered.
|
|
146
|
+
thread(isDaemon = true) {
|
|
147
|
+
server.accept().use { socket ->
|
|
148
|
+
val request = socket.getInputStream().bufferedReader()
|
|
149
|
+
while (!request.readLine().isNullOrEmpty()) Unit
|
|
150
|
+
socket.getOutputStream().run {
|
|
151
|
+
write("HTTP/1.1 200 OK\r\nContent-Type: audio/wav\r\n\r\n".toByteArray())
|
|
152
|
+
write(silentWavBytes(Duration.ofMinutes(1)), 0, 40_000)
|
|
153
|
+
flush()
|
|
154
|
+
}
|
|
155
|
+
drop.await(30, TimeUnit.SECONDS)
|
|
156
|
+
}
|
|
157
|
+
while (!server.isClosed) {
|
|
158
|
+
try {
|
|
159
|
+
server.accept().close()
|
|
160
|
+
connections.incrementAndGet()
|
|
161
|
+
} catch (_: IOException) {
|
|
162
|
+
return@thread
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
try {
|
|
167
|
+
play(RetryPolicy.Infinite(), "http://127.0.0.1:${server.localPort}/live", live = true)
|
|
168
|
+
idleUntil("PLAYING") { player.playbackState == PlaybackState.PLAYING }
|
|
169
|
+
drop.countDown()
|
|
170
|
+
// Stands in for the drop, which the engine never reads: its disabled audio track stops it
|
|
171
|
+
// reading the stream.
|
|
172
|
+
player.exoPlayer.stop()
|
|
173
|
+
player.exoPlayer.prepare()
|
|
174
|
+
idleUntil("the first reconnect") { connections.get() >= 1 }
|
|
175
|
+
val states = session.countLegacyStateUpdates()
|
|
176
|
+
val timelines = AtomicInteger()
|
|
177
|
+
player.forwardingPlayer.addListener(
|
|
178
|
+
object : MediaPlayer.Listener {
|
|
179
|
+
override fun onTimelineChanged(timeline: Timeline, reason: Int) {
|
|
180
|
+
timelines.incrementAndGet()
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
)
|
|
184
|
+
|
|
185
|
+
idleUntil("three more reconnects") { connections.get() >= 4 }
|
|
186
|
+
|
|
187
|
+
assertEquals(PlaybackState.BUFFERING, player.playbackState)
|
|
188
|
+
assertEquals(0, states())
|
|
189
|
+
assertEquals(0, timelines.get())
|
|
190
|
+
} finally {
|
|
191
|
+
server.close()
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
134
195
|
private fun failTerminally() {
|
|
135
196
|
play(RetryPolicy.Limited(maxRetries = 0))
|
|
136
197
|
idleUntil("a terminal error") { player.playbackState == PlaybackState.ERROR }
|
|
137
198
|
}
|
|
138
199
|
|
|
139
|
-
private fun play(
|
|
200
|
+
private fun play(
|
|
201
|
+
retryPolicy: RetryPolicy,
|
|
202
|
+
src: String = "https://127.0.0.1:9/stream",
|
|
203
|
+
live: Boolean? = null,
|
|
204
|
+
) {
|
|
140
205
|
goOnline(context)
|
|
141
206
|
player.setup(PlayerSetupOptions(retryPolicy = retryPolicy))
|
|
142
207
|
player.setCallbacks(callbacks)
|
|
@@ -147,7 +212,9 @@ class SessionViewTest {
|
|
|
147
212
|
.buildUpon()
|
|
148
213
|
.setTrackTypeDisabled(C.TRACK_TYPE_AUDIO, true)
|
|
149
214
|
.build()
|
|
150
|
-
player.exoPlayer.setMediaItems(
|
|
215
|
+
player.exoPlayer.setMediaItems(
|
|
216
|
+
listOf(TrackFactory.toMedia3(TestFixtures.track(src = src).copy(live = live)))
|
|
217
|
+
)
|
|
151
218
|
player.exoPlayer.prepare()
|
|
152
219
|
player.play()
|
|
153
220
|
}
|
|
@@ -164,27 +231,4 @@ class SessionViewTest {
|
|
|
164
231
|
shadowOf(Looper.getMainLooper()).idle()
|
|
165
232
|
}
|
|
166
233
|
}
|
|
167
|
-
|
|
168
|
-
/** Half a second of 8 kHz mono 8-bit silence. */
|
|
169
|
-
private fun silentWav(): File {
|
|
170
|
-
val samples = 4_000
|
|
171
|
-
val header =
|
|
172
|
-
ByteBuffer.allocate(44).order(ByteOrder.LITTLE_ENDIAN).apply {
|
|
173
|
-
put("RIFF".toByteArray())
|
|
174
|
-
putInt(36 + samples)
|
|
175
|
-
put("WAVEfmt ".toByteArray())
|
|
176
|
-
putInt(16)
|
|
177
|
-
putShort(1)
|
|
178
|
-
putShort(1)
|
|
179
|
-
putInt(8_000)
|
|
180
|
-
putInt(8_000)
|
|
181
|
-
putShort(1)
|
|
182
|
-
putShort(8)
|
|
183
|
-
put("data".toByteArray())
|
|
184
|
-
putInt(samples)
|
|
185
|
-
}
|
|
186
|
-
return folder.newFile("silence.wav").apply {
|
|
187
|
-
writeBytes(header.array() + ByteArray(samples) { 0x80.toByte() })
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
234
|
}
|