react-native-audio-browser 0.2.0-next.84 → 0.2.0-next.86
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/Service.kt +17 -0
- package/android/src/main/java/com/audiobrowser/player/Player.kt +1 -0
- package/android/src/main/java/com/audiobrowser/player/PlayerListener.kt +6 -6
- package/android/src/main/java/com/audiobrowser/remote/RemoteSwitchingPlayer.kt +12 -21
- package/android/src/test/java/androidx/media3/session/SessionViews.kt +19 -0
- package/android/src/test/java/com/audiobrowser/SessionPositionUpdatesTest.kt +173 -0
- package/android/src/test/java/com/audiobrowser/player/PlayerRetryTest.kt +17 -0
- package/android/src/test/java/com/audiobrowser/player/PlayerTrackChangeTest.kt +23 -0
- package/android/src/test/java/com/audiobrowser/remote/FakeRemote.kt +2 -1
- package/android/src/test/java/com/audiobrowser/remote/RemoteSwitchingPlayerTest.kt +37 -0
- package/package.json +1 -1
- package/website/guide/live-streams.md +42 -9
|
@@ -5,6 +5,7 @@ import android.app.SearchManager
|
|
|
5
5
|
import android.content.ComponentName
|
|
6
6
|
import android.content.Intent
|
|
7
7
|
import android.content.ServiceConnection
|
|
8
|
+
import android.content.pm.PackageManager
|
|
8
9
|
import android.os.Binder
|
|
9
10
|
import android.os.IBinder
|
|
10
11
|
import android.provider.MediaStore
|
|
@@ -152,6 +153,7 @@ class Service : MediaLibraryService(), MediaSessionService.Listener {
|
|
|
152
153
|
mediaSession =
|
|
153
154
|
MediaLibrarySession.Builder(this, player.forwardingPlayer, player.getMediaSessionCallback())
|
|
154
155
|
.setBitmapLoader(CacheBitmapLoader(coilBitmapLoader))
|
|
156
|
+
.setPeriodicPositionUpdateEnabled(periodicPositionUpdatesEnabled())
|
|
155
157
|
// https://github.com/androidx/media/issues/1218
|
|
156
158
|
.setSessionActivity(
|
|
157
159
|
PendingIntent.getActivity(
|
|
@@ -173,6 +175,13 @@ class Service : MediaLibraryService(), MediaSessionService.Listener {
|
|
|
173
175
|
}
|
|
174
176
|
}
|
|
175
177
|
|
|
178
|
+
/** The app's [PERIODIC_POSITION_UPDATES] manifest meta-data; true when it declares none. */
|
|
179
|
+
private fun periodicPositionUpdatesEnabled(): Boolean =
|
|
180
|
+
packageManager
|
|
181
|
+
.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
|
|
182
|
+
.metaData
|
|
183
|
+
?.getBoolean(PERIODIC_POSITION_UPDATES, true) ?: true
|
|
184
|
+
|
|
176
185
|
override fun onStartCommand(intent: Intent?, flags: Int, startId: Int): Int {
|
|
177
186
|
Timber.d("onStartCommand: action=${intent?.action}")
|
|
178
187
|
|
|
@@ -360,4 +369,12 @@ class Service : MediaLibraryService(), MediaSessionService.Listener {
|
|
|
360
369
|
inner class LocalBinder : Binder() {
|
|
361
370
|
val service = this@Service
|
|
362
371
|
}
|
|
372
|
+
|
|
373
|
+
companion object {
|
|
374
|
+
/**
|
|
375
|
+
* Application meta-data that, set to false, stops media3's periodic position update: the
|
|
376
|
+
* session re-sending External Surfaces the playback state every 3 s while playing or loading.
|
|
377
|
+
*/
|
|
378
|
+
const val PERIODIC_POSITION_UPDATES = "com.audiobrowser.PERIODIC_POSITION_UPDATES"
|
|
379
|
+
}
|
|
363
380
|
}
|
|
@@ -1135,6 +1135,7 @@ internal constructor(
|
|
|
1135
1135
|
// The next play is a new Load.
|
|
1136
1136
|
retryLoop?.suspend()
|
|
1137
1137
|
sessionPlayer.stop()
|
|
1138
|
+
playerListener.fenceOutgoingMetadata()
|
|
1138
1139
|
// Idle at its end, the next prepare would end it again at once.
|
|
1139
1140
|
if (ended) sessionPlayer.seekToDefaultPosition()
|
|
1140
1141
|
}
|
|
@@ -31,17 +31,17 @@ class PlayerListener(private val player: Player) : MediaPlayer.Listener {
|
|
|
31
31
|
@MediaPlayer.State private var lastEngineState = MediaPlayer.STATE_IDLE
|
|
32
32
|
|
|
33
33
|
/**
|
|
34
|
-
* Set from an app-started
|
|
35
|
-
* metadata delivery is the outgoing
|
|
36
|
-
* the
|
|
34
|
+
* Set from an app-started command that ends the stream until the playback thread has handled it.
|
|
35
|
+
* Until then every metadata delivery is the outgoing stream's: its renderer posted them to the
|
|
36
|
+
* main looper before the command, and nothing removes them.
|
|
37
37
|
*/
|
|
38
38
|
private var metadataFence: Any? = null
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* Its target runs on the playback thread right after
|
|
42
|
-
* main-looper target goes to the back of that thread's queue, where a release would drop it.
|
|
41
|
+
* Call right after the command. Its target runs on the playback thread right after that command.
|
|
42
|
+
* A main-looper target goes to the back of that thread's queue, where a release would drop it.
|
|
43
43
|
*/
|
|
44
|
-
|
|
44
|
+
internal fun fenceOutgoingMetadata() {
|
|
45
45
|
val fence = Any()
|
|
46
46
|
metadataFence = fence
|
|
47
47
|
player.exoPlayer
|
|
@@ -98,6 +98,13 @@ internal class RemoteSwitchingPlayer(
|
|
|
98
98
|
class Ended(val positionMs: Long) : Load
|
|
99
99
|
}
|
|
100
100
|
|
|
101
|
+
/**
|
|
102
|
+
* The phone's metadata last reported. A block is reported once, and as none from the next state
|
|
103
|
+
* on, so that an equal block after it goes out as ExoPlayer sends it: the state emits only a
|
|
104
|
+
* change, and a stream's first title after a reconnect often equals its last.
|
|
105
|
+
*/
|
|
106
|
+
private var reportedMetadata: Metadata? = null
|
|
107
|
+
|
|
101
108
|
init {
|
|
102
109
|
setRemotes(remotes)
|
|
103
110
|
}
|
|
@@ -137,22 +144,9 @@ internal class RemoteSwitchingPlayer(
|
|
|
137
144
|
private val remoteRoute: Route.Remote?
|
|
138
145
|
get() = route as? Route.Remote
|
|
139
146
|
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
/**
|
|
144
|
-
* The phone's metadata as it stopped, reported as none until the phone sends more. The state
|
|
145
|
-
* emits only a change, and a stream's first title after a reconnect often equals its last.
|
|
146
|
-
*/
|
|
147
|
-
private var titleAtStop: Metadata? = null
|
|
148
|
-
|
|
149
|
-
private fun withoutStoppedTitle(state: State): State {
|
|
150
|
-
if (localStopPending) {
|
|
151
|
-
localStopPending = false
|
|
152
|
-
titleAtStop = state.timedMetadata
|
|
153
|
-
}
|
|
154
|
-
if (state.timedMetadata !== titleAtStop) {
|
|
155
|
-
titleAtStop = null
|
|
147
|
+
private fun withEachBlockOnce(state: State): State {
|
|
148
|
+
if (state.timedMetadata !== reportedMetadata) {
|
|
149
|
+
reportedMetadata = state.timedMetadata
|
|
156
150
|
return state
|
|
157
151
|
}
|
|
158
152
|
return state.buildUpon().setTimedMetadata(NO_TIMED_METADATA).build()
|
|
@@ -464,7 +458,7 @@ internal class RemoteSwitchingPlayer(
|
|
|
464
458
|
|
|
465
459
|
override fun getState(): State {
|
|
466
460
|
val state = super.getState()
|
|
467
|
-
val remote = remoteRoute ?: return
|
|
461
|
+
val remote = remoteRoute ?: return withEachBlockOnce(state)
|
|
468
462
|
val load = remote.load
|
|
469
463
|
val holds = load is Load.Playing && receiverHolds(remote, load.item)
|
|
470
464
|
// Duration, seekability and liveness come from the receiver's data for the item it plays.
|
|
@@ -565,10 +559,7 @@ internal class RemoteSwitchingPlayer(
|
|
|
565
559
|
|
|
566
560
|
override fun handleStop(): ListenableFuture<*> {
|
|
567
561
|
val remote = remoteRoute
|
|
568
|
-
if (remote == null)
|
|
569
|
-
localStopPending = true
|
|
570
|
-
return super.handleStop()
|
|
571
|
-
}
|
|
562
|
+
if (remote == null) return super.handleStop()
|
|
572
563
|
val positionMs = positionOn(remote)
|
|
573
564
|
cancelLoad(remote)
|
|
574
565
|
stopReceiver(remote.receiver)
|
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
package androidx.media3.session
|
|
2
2
|
|
|
3
|
+
import android.os.Handler
|
|
4
|
+
import android.os.Looper
|
|
5
|
+
import androidx.media3.session.legacy.MediaControllerCompat
|
|
6
|
+
import androidx.media3.session.legacy.PlaybackStateCompat
|
|
7
|
+
|
|
3
8
|
// Read in place: Robolectric can't connect a controller to the session.
|
|
4
9
|
|
|
5
10
|
/** The state legacy controllers (Android Auto, Bluetooth, the system UI) were last told. */
|
|
@@ -17,3 +22,17 @@ internal fun MediaSession.controllerError() = impl.playerInfo.playerError
|
|
|
17
22
|
|
|
18
23
|
/** Whether media3 controllers were last told it plays. */
|
|
19
24
|
internal fun MediaSession.controllerPlaying() = impl.playerInfo.isPlaying
|
|
25
|
+
|
|
26
|
+
/** Counts the playback states legacy controllers are told from now on. */
|
|
27
|
+
internal fun MediaSession.countLegacyStateUpdates(): () -> Int {
|
|
28
|
+
var count = 0
|
|
29
|
+
impl.mediaSessionLegacyStub.sessionCompat.controller.registerCallback(
|
|
30
|
+
object : MediaControllerCompat.Callback() {
|
|
31
|
+
override fun onPlaybackStateChanged(state: PlaybackStateCompat?) {
|
|
32
|
+
count += 1
|
|
33
|
+
}
|
|
34
|
+
},
|
|
35
|
+
Handler(Looper.getMainLooper()),
|
|
36
|
+
)
|
|
37
|
+
return { count }
|
|
38
|
+
}
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
package com.audiobrowser
|
|
2
|
+
|
|
3
|
+
import android.content.ComponentName
|
|
4
|
+
import android.net.Uri
|
|
5
|
+
import android.os.Binder
|
|
6
|
+
import android.os.Bundle
|
|
7
|
+
import android.os.Looper
|
|
8
|
+
import android.os.Process
|
|
9
|
+
import androidx.annotation.OptIn
|
|
10
|
+
import androidx.media3.common.C
|
|
11
|
+
import androidx.media3.common.util.UnstableApi
|
|
12
|
+
import androidx.media3.session.MediaSession
|
|
13
|
+
import androidx.media3.session.countLegacyStateUpdates
|
|
14
|
+
import com.audiobrowser.util.TrackFactory
|
|
15
|
+
import java.io.File
|
|
16
|
+
import java.nio.ByteBuffer
|
|
17
|
+
import java.nio.ByteOrder
|
|
18
|
+
import java.time.Duration
|
|
19
|
+
import org.junit.After
|
|
20
|
+
import org.junit.Assert.assertEquals
|
|
21
|
+
import org.junit.Assert.assertTrue
|
|
22
|
+
import org.junit.Assert.fail
|
|
23
|
+
import org.junit.Rule
|
|
24
|
+
import org.junit.Test
|
|
25
|
+
import org.junit.rules.TemporaryFolder
|
|
26
|
+
import org.junit.runner.RunWith
|
|
27
|
+
import org.robolectric.Robolectric
|
|
28
|
+
import org.robolectric.RobolectricTestRunner
|
|
29
|
+
import org.robolectric.RuntimeEnvironment
|
|
30
|
+
import org.robolectric.Shadows.shadowOf
|
|
31
|
+
import org.robolectric.android.controller.ServiceController
|
|
32
|
+
import org.robolectric.annotation.Config
|
|
33
|
+
import org.robolectric.shadows.ShadowSystemClock
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* What the service's session tells External Surfaces while playback runs with nothing changing,
|
|
37
|
+
* with and without the app's [Service.PERIODIC_POSITION_UPDATES] meta-data.
|
|
38
|
+
*/
|
|
39
|
+
@RunWith(RobolectricTestRunner::class)
|
|
40
|
+
@Config(sdk = [28])
|
|
41
|
+
class SessionPositionUpdatesTest {
|
|
42
|
+
|
|
43
|
+
@get:Rule val folder = TemporaryFolder()
|
|
44
|
+
|
|
45
|
+
private val application = RuntimeEnvironment.getApplication()
|
|
46
|
+
private lateinit var controller: ServiceController<Service>
|
|
47
|
+
private val service
|
|
48
|
+
get() = controller.get()
|
|
49
|
+
|
|
50
|
+
private val player
|
|
51
|
+
get() = service.player
|
|
52
|
+
|
|
53
|
+
@After
|
|
54
|
+
fun destroy() {
|
|
55
|
+
controller.destroy()
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
@Test
|
|
59
|
+
fun `by default the session re-sends the playback state every 3 s`() {
|
|
60
|
+
startService(metaData = null)
|
|
61
|
+
|
|
62
|
+
assertEquals(10, legacyStateUpdatesOverSteadyPlayback(Duration.ofSeconds(30)))
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
@Test
|
|
66
|
+
fun `the app's meta-data stops the periodic playback state updates`() {
|
|
67
|
+
startService(metaData = Bundle().apply { putBoolean(Service.PERIODIC_POSITION_UPDATES, false) })
|
|
68
|
+
|
|
69
|
+
assertEquals(0, legacyStateUpdatesOverSteadyPlayback(Duration.ofSeconds(30)))
|
|
70
|
+
|
|
71
|
+
// The counter hears a real change.
|
|
72
|
+
val updates = session().countLegacyStateUpdates()
|
|
73
|
+
player.pause()
|
|
74
|
+
advance(Duration.ofMillis(500))
|
|
75
|
+
assertTrue(updates() > 0)
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
private fun startService(metaData: Bundle?) {
|
|
79
|
+
shadowOf(application.packageManager)
|
|
80
|
+
.getInternalMutablePackageInfo(application.packageName)
|
|
81
|
+
.applicationInfo!!
|
|
82
|
+
.metaData = metaData
|
|
83
|
+
// Robolectric connects an unregistered binding with a null ComponentName, which the
|
|
84
|
+
// HeadlessTaskService connection's non-null parameter rejects.
|
|
85
|
+
shadowOf(application)
|
|
86
|
+
.setComponentNameAndServiceForBindService(
|
|
87
|
+
ComponentName(application, HeadlessTaskService::class.java),
|
|
88
|
+
Binder(),
|
|
89
|
+
)
|
|
90
|
+
controller = Robolectric.buildService(Service::class.java).create()
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/** Plays a silent WAV, then counts the legacy playback states sent over [duration]. */
|
|
94
|
+
private fun legacyStateUpdatesOverSteadyPlayback(duration: Duration): Int {
|
|
95
|
+
val session = session()
|
|
96
|
+
player.exoPlayer.trackSelectionParameters =
|
|
97
|
+
player.exoPlayer.trackSelectionParameters
|
|
98
|
+
.buildUpon()
|
|
99
|
+
.setTrackTypeDisabled(C.TRACK_TYPE_AUDIO, true)
|
|
100
|
+
.build()
|
|
101
|
+
goOnline(application)
|
|
102
|
+
val src = Uri.fromFile(silentWav(seconds = 45)).toString()
|
|
103
|
+
player.exoPlayer.setMediaItems(listOf(TrackFactory.toMedia3(TestFixtures.track(src = src))))
|
|
104
|
+
player.exoPlayer.prepare()
|
|
105
|
+
player.play()
|
|
106
|
+
advanceUntil("playing") { player.exoPlayer.isPlaying }
|
|
107
|
+
// Lets the updates that starting playback sends settle.
|
|
108
|
+
advance(Duration.ofSeconds(1))
|
|
109
|
+
|
|
110
|
+
val updates = session.countLegacyStateUpdates()
|
|
111
|
+
repeat((duration.toMillis() / 500).toInt()) { advance(Duration.ofMillis(500)) }
|
|
112
|
+
|
|
113
|
+
assertTrue(player.exoPlayer.isPlaying)
|
|
114
|
+
return updates()
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
@OptIn(UnstableApi::class)
|
|
118
|
+
private fun session(): MediaSession {
|
|
119
|
+
// onGetSession ignores its argument.
|
|
120
|
+
return service.onGetSession(
|
|
121
|
+
MediaSession.ControllerInfo.createTestOnlyControllerInfo(
|
|
122
|
+
application.packageName,
|
|
123
|
+
0,
|
|
124
|
+
Process.myUid(),
|
|
125
|
+
0,
|
|
126
|
+
0,
|
|
127
|
+
false,
|
|
128
|
+
Bundle.EMPTY,
|
|
129
|
+
false,
|
|
130
|
+
)
|
|
131
|
+
)!!
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
private fun advance(duration: Duration) {
|
|
135
|
+
ShadowSystemClock.advanceBy(duration)
|
|
136
|
+
Thread.sleep(10)
|
|
137
|
+
shadowOf(Looper.getMainLooper()).idle()
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
private fun advanceUntil(what: String, condition: () -> Boolean) {
|
|
141
|
+
val deadline = System.currentTimeMillis() + 5_000
|
|
142
|
+
while (!condition()) {
|
|
143
|
+
if (System.currentTimeMillis() > deadline)
|
|
144
|
+
fail(
|
|
145
|
+
"timed out waiting for $what: ${player.playbackState}, exo ${player.exoPlayer.playbackState}"
|
|
146
|
+
)
|
|
147
|
+
advance(Duration.ofMillis(100))
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/** 8 kHz mono 8-bit silence. */
|
|
152
|
+
private fun silentWav(seconds: Int): File {
|
|
153
|
+
val samples = 8_000 * seconds
|
|
154
|
+
val header =
|
|
155
|
+
ByteBuffer.allocate(44).order(ByteOrder.LITTLE_ENDIAN).apply {
|
|
156
|
+
put("RIFF".toByteArray())
|
|
157
|
+
putInt(36 + samples)
|
|
158
|
+
put("WAVEfmt ".toByteArray())
|
|
159
|
+
putInt(16)
|
|
160
|
+
putShort(1)
|
|
161
|
+
putShort(1)
|
|
162
|
+
putInt(8_000)
|
|
163
|
+
putInt(8_000)
|
|
164
|
+
putShort(1)
|
|
165
|
+
putShort(8)
|
|
166
|
+
put("data".toByteArray())
|
|
167
|
+
putInt(samples)
|
|
168
|
+
}
|
|
169
|
+
return folder.newFile("silence.wav").apply {
|
|
170
|
+
writeBytes(header.array() + ByteArray(samples) { 0x80.toByte() })
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
}
|
|
@@ -7,9 +7,11 @@ import android.net.NetworkCapabilities
|
|
|
7
7
|
import android.net.Uri
|
|
8
8
|
import android.os.Looper
|
|
9
9
|
import androidx.media3.common.C
|
|
10
|
+
import androidx.media3.common.Metadata
|
|
10
11
|
import androidx.media3.common.PlaybackException
|
|
11
12
|
import androidx.media3.common.Player as MediaPlayer
|
|
12
13
|
import androidx.media3.common.util.StuckPlayerException
|
|
14
|
+
import androidx.media3.extractor.metadata.icy.IcyInfo
|
|
13
15
|
import com.audiobrowser.Callbacks
|
|
14
16
|
import com.audiobrowser.TestFixtures
|
|
15
17
|
import com.audiobrowser.goOnline
|
|
@@ -517,6 +519,21 @@ class PlayerRetryTest {
|
|
|
517
519
|
assertNotEquals(PlaybackState.ERROR, player.playbackState)
|
|
518
520
|
}
|
|
519
521
|
|
|
522
|
+
@Test
|
|
523
|
+
fun `a title after a reconnect inside the retry loop shows`() {
|
|
524
|
+
goOnline(context)
|
|
525
|
+
play(Uri.fromFile(silentWav()).toString(), retryPolicy = RetryPolicy.Infinite())
|
|
526
|
+
idleUntil("playing") { player.playbackState == PlaybackState.PLAYING }
|
|
527
|
+
player.exoPlayer.stop()
|
|
528
|
+
player.playerListener.onPlayerError(stuck())
|
|
529
|
+
advanceSeconds(2)
|
|
530
|
+
assertNotEquals("no reconnect", MediaPlayer.STATE_IDLE, player.exoPlayer.playbackState)
|
|
531
|
+
|
|
532
|
+
player.playerListener.onMetadata(Metadata(IcyInfo(ByteArray(0), "Song", null)))
|
|
533
|
+
|
|
534
|
+
assertEquals("Song", player.nowPlaying.timedMetadata?.title)
|
|
535
|
+
}
|
|
536
|
+
|
|
520
537
|
@Test
|
|
521
538
|
fun `with retry off, a stuck engine ends in the stalled error`() {
|
|
522
539
|
play(Uri.fromFile(silentWav()).toString())
|
|
@@ -182,6 +182,29 @@ class PlayerTrackChangeTest {
|
|
|
182
182
|
assertEquals(listOf("A's city", "A's city"), shownSecondLines())
|
|
183
183
|
}
|
|
184
184
|
|
|
185
|
+
@Test
|
|
186
|
+
fun `a title the stream had already posted does not survive a stop`() {
|
|
187
|
+
playStationWithTitle()
|
|
188
|
+
val heard = mutableListOf<TimedMetadata>()
|
|
189
|
+
player.callbacks =
|
|
190
|
+
mock(Callbacks::class.java) { invocation ->
|
|
191
|
+
if (invocation.method.name == "onTimedMetadata") heard.add(invocation.getArgument(0))
|
|
192
|
+
Answers.RETURNS_DEFAULTS.answer(invocation)
|
|
193
|
+
}
|
|
194
|
+
val playbackLooper = shadowOf(player.exoPlayer.playbackLooper)
|
|
195
|
+
playbackLooper.pause()
|
|
196
|
+
Handler(player.exoPlayer.playbackLooper).post {
|
|
197
|
+
Handler(Looper.getMainLooper()).post { player.playerListener.onMetadata(icy("A song 1")) }
|
|
198
|
+
}
|
|
199
|
+
player.stop()
|
|
200
|
+
playbackLooper.unPause()
|
|
201
|
+
idle()
|
|
202
|
+
|
|
203
|
+
assertEquals(emptyList<TimedMetadata>(), heard)
|
|
204
|
+
assertNull(player.nowPlaying.timedMetadata)
|
|
205
|
+
assertEquals(listOf("A's city", "A's city"), shownSecondLines())
|
|
206
|
+
}
|
|
207
|
+
|
|
185
208
|
@Test
|
|
186
209
|
fun `a play after a stop shows the track's own lines until the stream sends a title`() {
|
|
187
210
|
playStationWithTitle()
|
|
@@ -30,7 +30,7 @@ internal class FakeLocalPlayer(looper: Looper) : SimpleBasePlayer(looper) {
|
|
|
30
30
|
|
|
31
31
|
/**
|
|
32
32
|
* Sends a stream title. ExoPlayer sends each one it decodes; this state emits only a change, so a
|
|
33
|
-
* stop
|
|
33
|
+
* stop and a prepare clear it for the first title of each connection to go out.
|
|
34
34
|
*/
|
|
35
35
|
fun title(title: String) {
|
|
36
36
|
metadata = Metadata(0, IcyInfo(title.toByteArray(), title, null))
|
|
@@ -91,6 +91,7 @@ internal class FakeLocalPlayer(looper: Looper) : SimpleBasePlayer(looper) {
|
|
|
91
91
|
|
|
92
92
|
override fun handlePrepare(): ListenableFuture<*> {
|
|
93
93
|
readiness = STATE_READY
|
|
94
|
+
metadata = Metadata(C.TIME_UNSET)
|
|
94
95
|
prepares++
|
|
95
96
|
return done()
|
|
96
97
|
}
|
|
@@ -927,6 +927,43 @@ class RemoteSwitchingPlayerTest {
|
|
|
927
927
|
assertEquals(listOf("Song"), seen)
|
|
928
928
|
}
|
|
929
929
|
|
|
930
|
+
@Test
|
|
931
|
+
fun `each title the phone sends after a stop goes out, though it equals the last`() {
|
|
932
|
+
playLocally(listOf("a"))
|
|
933
|
+
local.title("Song")
|
|
934
|
+
idle()
|
|
935
|
+
val seen = transitionsAndTitles()
|
|
936
|
+
|
|
937
|
+
player.stop()
|
|
938
|
+
idle()
|
|
939
|
+
// A title that runs after the stop: passed on here, and dropped by the player's listener.
|
|
940
|
+
local.title("Song")
|
|
941
|
+
idle()
|
|
942
|
+
player.prepare()
|
|
943
|
+
idle()
|
|
944
|
+
local.title("Song")
|
|
945
|
+
idle()
|
|
946
|
+
|
|
947
|
+
assertEquals(listOf("Song", "Song"), seen)
|
|
948
|
+
}
|
|
949
|
+
|
|
950
|
+
@Test
|
|
951
|
+
fun `a title after the phone reconnects without a stop goes out, though it equals the last`() {
|
|
952
|
+
playLocally(listOf("a"))
|
|
953
|
+
local.title("Song")
|
|
954
|
+
idle()
|
|
955
|
+
val seen = transitionsAndTitles()
|
|
956
|
+
|
|
957
|
+
// As the retry loop reconnects: on the phone, not through this player.
|
|
958
|
+
local.stop()
|
|
959
|
+
local.prepare()
|
|
960
|
+
idle()
|
|
961
|
+
local.title("Song")
|
|
962
|
+
idle()
|
|
963
|
+
|
|
964
|
+
assertEquals(listOf("Song"), seen)
|
|
965
|
+
}
|
|
966
|
+
|
|
930
967
|
@Test
|
|
931
968
|
fun `release brings playback back and lets every remote go`() {
|
|
932
969
|
playLocally(listOf("a"))
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
---
|
|
2
|
-
description:
|
|
2
|
+
description: "The map for live audio: stream formats, missing durations, dropped connections, expiring URLs, song titles carried in-band, and Android's periodic position updates."
|
|
3
3
|
---
|
|
4
4
|
|
|
5
5
|
# Live Streams
|
|
@@ -144,13 +144,46 @@ resolved URL, so an expired one re-resolves only after that first attempt
|
|
|
144
144
|
fails (see [Fresh URLs on reconnect](#fresh-urls-on-reconnect)).
|
|
145
145
|
General seeking is in [Playback](/guide/playback).
|
|
146
146
|
|
|
147
|
+
## Periodic position updates (Android)
|
|
148
|
+
|
|
149
|
+
While the player plays or loads, Media3's media session sends External
|
|
150
|
+
Surfaces the playback state again every 3 seconds: the notification, the lock
|
|
151
|
+
screen, Android Auto, Bluetooth, and Media3 controllers in other apps (a
|
|
152
|
+
watch, say). The update carries the current and buffered position, so a
|
|
153
|
+
surface that extrapolates the position corrects any drift.
|
|
154
|
+
|
|
155
|
+
A live track has no progress bar, so a drifting position never shows, and the
|
|
156
|
+
update only refreshes the state's timestamp. Android 16's Bluetooth service
|
|
157
|
+
logs each one as `tried to update with no new data`.
|
|
158
|
+
|
|
159
|
+
If your app plays only live streams, turn the update off with a literal
|
|
160
|
+
`false` in your app's manifest:
|
|
161
|
+
|
|
162
|
+
```xml
|
|
163
|
+
<!-- android/app/src/main/AndroidManifest.xml, inside <application> -->
|
|
164
|
+
<meta-data
|
|
165
|
+
android:name="com.audiobrowser.PERIODIC_POSITION_UPDATES"
|
|
166
|
+
android:value="false" />
|
|
167
|
+
```
|
|
168
|
+
|
|
169
|
+
Every real change still reaches the surfaces at once: state, play and pause,
|
|
170
|
+
seeks, speed, Now Playing and the queue. Surfaces extrapolate an on-demand
|
|
171
|
+
position from the last state, so their progress bars keep moving. What stops
|
|
172
|
+
is the correction: a position that drifts with no state change (a Sonos
|
|
173
|
+
speaker that slips while it still reports playing, say) stays wrong on the
|
|
174
|
+
surfaces until the next change.
|
|
175
|
+
|
|
176
|
+
Leave it on, the default, if your app plays on-demand audio. The flag is
|
|
177
|
+
Android-only: iOS and web have no such update.
|
|
178
|
+
|
|
147
179
|
## API summary
|
|
148
180
|
|
|
149
|
-
| API
|
|
150
|
-
|
|
|
151
|
-
| [`Track.live`](/api/types/browser-nodes/#live)
|
|
152
|
-
| [`seekToLiveEdge()`](/api/features/playback/#seektoliveedge)
|
|
153
|
-
| [`setupPlayer({ retry })`](/guide/errors#automatic-retry)
|
|
154
|
-
| [`retry()`](/guide/errors#manual-retry)
|
|
155
|
-
| [`media.resolve`](/guide/browser#media-and-artwork)
|
|
156
|
-
| [`useOnline()`](/guide/network)
|
|
181
|
+
| API | Purpose |
|
|
182
|
+
| ----------------------------------------------------------------- | ----------------------------------------------------------------------- |
|
|
183
|
+
| [`Track.live`](/api/types/browser-nodes/#live) | Declare a live track: iOS live indicator, arms the live edge. |
|
|
184
|
+
| [`seekToLiveEdge()`](/api/features/playback/#seektoliveedge) | Jump to the newest audio (no-op for non-live tracks). |
|
|
185
|
+
| [`setupPlayer({ retry })`](/guide/errors#automatic-retry) | Automatic retry with first-connect and recovery budgets. |
|
|
186
|
+
| [`retry()`](/guide/errors#manual-retry) | Restart from `'error'` with fresh budgets. |
|
|
187
|
+
| [`media.resolve`](/guide/browser#media-and-artwork) | Build the stream request — signed / short-lived URLs. |
|
|
188
|
+
| [`useOnline()`](/guide/network) | Connectivity for your own UI; playback reacts on its own. |
|
|
189
|
+
| [`PERIODIC_POSITION_UPDATES`](#periodic-position-updates-android) | Android manifest flag: stop the 3 s position update for live-only apps. |
|