react-native-audio-browser 0.2.0-next.71 → 0.2.0-next.72

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.
@@ -490,10 +490,8 @@ internal constructor(
490
490
  if (exoPlayer.playbackState == ExoPlayer.STATE_IDLE) PlaybackState.NONE
491
491
  else PlaybackState.BUFFERING
492
492
  )
493
- // The new engine can refuse the carried intent (audio focus denied) without a change event,
494
- // which would leave a stale true in the cache and in JS.
495
- playWhenReadyCache = exoPlayer.playWhenReady
496
- emitPlayWhenReadyChanged(exoPlayer.playWhenReady)
493
+ // The new engine starts unsuppressed: an unchanged state would not re-derive it.
494
+ refreshPlayingState()
497
495
  }
498
496
 
499
497
  setupAutomaticBufferManager(setupOptions.automaticBuffer)
@@ -1,13 +1,19 @@
1
1
  package com.audiobrowser.player
2
2
 
3
+ import android.content.Context
4
+ import android.media.AudioManager
5
+ import android.os.Looper
3
6
  import androidx.media3.common.Player as MediaPlayer
4
7
  import com.audiobrowser.Callbacks
5
8
  import com.audiobrowser.TestFixtures
6
9
  import com.audiobrowser.model.PlayerSetupOptions
7
10
  import com.audiobrowser.util.TrackFactory
11
+ import com.margelo.nitro.audiobrowser.PlaybackPlayWhenReadyChangedEvent
8
12
  import com.margelo.nitro.audiobrowser.PlaybackState
13
+ import com.margelo.nitro.audiobrowser.PlayingState
9
14
  import org.junit.After
10
15
  import org.junit.Assert.assertEquals
16
+ import org.junit.Assert.assertFalse
11
17
  import org.junit.Assert.assertNotSame
12
18
  import org.junit.Assert.assertSame
13
19
  import org.junit.Assert.assertTrue
@@ -15,8 +21,11 @@ import org.junit.Test
15
21
  import org.junit.runner.RunWith
16
22
  import org.mockito.Mockito.mock
17
23
  import org.mockito.Mockito.mockingDetails
24
+ import org.mockito.Mockito.verify
18
25
  import org.robolectric.RobolectricTestRunner
19
26
  import org.robolectric.RuntimeEnvironment
27
+ import org.robolectric.Shadows.shadowOf
28
+ import org.robolectric.annotation.Config
20
29
 
21
30
  @RunWith(RobolectricTestRunner::class)
22
31
  class PlayerSetupTest {
@@ -76,6 +85,42 @@ class PlayerSetupTest {
76
85
  )
77
86
  }
78
87
 
88
+ // SDK 28: from 33, media3 asks AudioManager.getAudioDevicesForAttributes, which Robolectric 4.11
89
+ // answers with null.
90
+ @Test
91
+ @Config(sdk = [28])
92
+ fun setupWithChangedOptionsReportsAnIntentTheNewEngineRefuses() {
93
+ player.setup(PlayerSetupOptions())
94
+ val engine = player.exoPlayer
95
+ engine.setMediaItems(listOf(item("a")))
96
+ engine.prepare()
97
+ engine.playWhenReady = true
98
+ player.setPlaybackState(PlaybackState.BUFFERING)
99
+ assertEquals(PlayingState(true, true), player.getPlayingState())
100
+ val callbacks = mock(Callbacks::class.java)
101
+ player.setCallbacks(callbacks)
102
+ val audioManager =
103
+ shadowOf(
104
+ RuntimeEnvironment.getApplication().getSystemService(Context.AUDIO_SERVICE) as AudioManager
105
+ )
106
+ audioManager.setNextFocusRequestResponse(AudioManager.AUDIOFOCUS_REQUEST_FAILED)
107
+
108
+ player.setup(PlayerSetupOptions(maxBuffer = 120_000.0))
109
+ // ExoPlayer requests focus on its playback thread and posts the refusal back.
110
+ assertTrue(player.exoPlayer.playWhenReady)
111
+ val deadline = System.currentTimeMillis() + 5_000
112
+ while (player.exoPlayer.playWhenReady && System.currentTimeMillis() < deadline) {
113
+ Thread.sleep(10)
114
+ shadowOf(Looper.getMainLooper()).idle()
115
+ }
116
+
117
+ assertFalse("no focus refusal within 5 s", player.exoPlayer.playWhenReady)
118
+ assertEquals(PlaybackState.PAUSED, player.playbackState)
119
+ assertEquals(PlayingState(false, false), player.getPlayingState())
120
+ verify(callbacks).onPlaybackPlayWhenReadyChanged(PlaybackPlayWhenReadyChangedEvent(false))
121
+ verify(callbacks).onPlaybackPlayingState(PlayingState(false, false))
122
+ }
123
+
79
124
  @Test
80
125
  fun setupWithChangedOptionsKeepsAnUnpreparedQueueStopped() {
81
126
  player.setup(PlayerSetupOptions())
@@ -143,6 +143,19 @@ class PlayerSuppressionTest {
143
143
  assertEquals(PlayingState(false, false), player.getPlayingState())
144
144
  }
145
145
 
146
+ @Test
147
+ fun `a rebuild during a transient focus loss reports the new engine's intent`() {
148
+ focus(AudioManager.AUDIOFOCUS_LOSS_TRANSIENT)
149
+ // As after a skip while suppressed.
150
+ player.setPlaybackState(PlaybackState.BUFFERING)
151
+ assertEquals(PlayingState(false, false), player.getPlayingState())
152
+
153
+ player.setup(PlayerSetupOptions(maxBuffer = 120_000.0))
154
+
155
+ assertEquals(PlayingState(true, true), player.getPlayingState())
156
+ verify(callbacks).onPlaybackPlayingState(PlayingState(true, true))
157
+ }
158
+
146
159
  private fun focus(change: Int) {
147
160
  audioManager.lastAudioFocusRequest.listener.onAudioFocusChange(change)
148
161
  val suppressed = change == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-audio-browser",
3
- "version": "0.2.0-next.71",
3
+ "version": "0.2.0-next.72",
4
4
  "description": "react-native-audio-browser is a react native package built with Nitro",
5
5
  "keywords": [
6
6
  "react-native",