react-native-audio-browser 0.2.0-next.42 → 0.2.0-next.44
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/AudioBrowser.kt +2 -2
- package/android/src/test/java/com/audiobrowser/player/PlayerInvalidTrackTest.kt +67 -0
- package/ios/CarPlay/MediaIntentPlayback.swift +1 -1
- package/ios/HybridAudioBrowser+Player.swift +4 -4
- package/ios/Model/TrackPlayerError.swift +4 -0
- package/ios/Player/Player.swift +31 -16
- package/ios/Tests/ArtworkFreshnessTests.swift +67 -0
- package/ios/Tests/PlayerInvalidTrackTests.swift +65 -0
- package/ios/Tests/PlayerPolicyTests.swift +78 -78
- package/ios/Tests/PlayerTests.swift +109 -109
- package/ios/Util/ArtworkFreshness.swift +42 -0
- package/ios/Util/ArtworkImageFetcher.swift +92 -11
- package/package.json +1 -1
|
@@ -25,9 +25,9 @@ private func loadTrack(
|
|
|
25
25
|
id: String = "t1",
|
|
26
26
|
src: String? = "https://example.com/audio.mp3",
|
|
27
27
|
title: String = "Test Track",
|
|
28
|
-
) {
|
|
28
|
+
) throws {
|
|
29
29
|
let track = Track(id: id, src: src, title: title)
|
|
30
|
-
player.setQueue([track])
|
|
30
|
+
try player.setQueue([track])
|
|
31
31
|
}
|
|
32
32
|
|
|
33
33
|
// MARK: - Transition + Side Effects
|
|
@@ -35,9 +35,9 @@ private func loadTrack(
|
|
|
35
35
|
@Suite("Player - transition + side effects")
|
|
36
36
|
struct TransitionTests {
|
|
37
37
|
@Test @MainActor
|
|
38
|
-
func toReady_startsPlayback_whenPlayWhenReady() {
|
|
38
|
+
func toReady_startsPlayback_whenPlayWhenReady() throws {
|
|
39
39
|
let (c, eh, _, _) = makeCoordinator()
|
|
40
|
-
loadTrack(c)
|
|
40
|
+
try loadTrack(c)
|
|
41
41
|
c.setPlayWhenReady(true)
|
|
42
42
|
eh.startPlaybackCallCount = 0 // reset from playWhenReady setter
|
|
43
43
|
|
|
@@ -48,9 +48,9 @@ struct TransitionTests {
|
|
|
48
48
|
}
|
|
49
49
|
|
|
50
50
|
@Test @MainActor
|
|
51
|
-
func toReady_doesNotStart_whenNotPlayWhenReady() {
|
|
51
|
+
func toReady_doesNotStart_whenNotPlayWhenReady() throws {
|
|
52
52
|
let (c, eh, _, _) = makeCoordinator()
|
|
53
|
-
loadTrack(c)
|
|
53
|
+
try loadTrack(c)
|
|
54
54
|
c.transition(.bufferingSufficient)
|
|
55
55
|
|
|
56
56
|
#expect(c.state == .ready)
|
|
@@ -248,9 +248,9 @@ struct EmitStateChangeTests {
|
|
|
248
248
|
}
|
|
249
249
|
|
|
250
250
|
@Test @MainActor
|
|
251
|
-
func emitsQueueEnded_onEndedAndLastTrack() {
|
|
251
|
+
func emitsQueueEnded_onEndedAndLastTrack() throws {
|
|
252
252
|
let (c, eh, cb, _) = makeCoordinator()
|
|
253
|
-
loadTrack(c)
|
|
253
|
+
try loadTrack(c)
|
|
254
254
|
eh.currentTime = 42
|
|
255
255
|
cb.queueEndedEvents.removeAll()
|
|
256
256
|
|
|
@@ -407,9 +407,9 @@ struct ObserverGuardTests {
|
|
|
407
407
|
@Suite("Player - playWhenReady")
|
|
408
408
|
struct PlayWhenReadyTests {
|
|
409
409
|
@Test @MainActor
|
|
410
|
-
func true_fromError_triggersReload() {
|
|
410
|
+
func true_fromError_triggersReload() throws {
|
|
411
411
|
let (c, eh, _, _) = makeCoordinator()
|
|
412
|
-
loadTrack(c)
|
|
412
|
+
try loadTrack(c)
|
|
413
413
|
eh.emit(.itemPrepared(likelyToKeepUp: false))
|
|
414
414
|
c.transition(.errorOccurred(.playbackFailed))
|
|
415
415
|
eh.resumePosition = 42
|
|
@@ -425,9 +425,9 @@ struct PlayWhenReadyTests {
|
|
|
425
425
|
}
|
|
426
426
|
|
|
427
427
|
@Test @MainActor
|
|
428
|
-
func true_fromStopped_triggersReload() {
|
|
428
|
+
func true_fromStopped_triggersReload() throws {
|
|
429
429
|
let (c, eh, _, _) = makeCoordinator()
|
|
430
|
-
loadTrack(c)
|
|
430
|
+
try loadTrack(c)
|
|
431
431
|
c.transition(.stopped)
|
|
432
432
|
eh.resumePosition = 42
|
|
433
433
|
let resolvesBefore = eh.resolveAndLoadCalls.count
|
|
@@ -498,27 +498,27 @@ struct SkipAvailabilityCoordinatorTests {
|
|
|
498
498
|
}
|
|
499
499
|
|
|
500
500
|
@Test @MainActor
|
|
501
|
-
func singleTrack_disablesBoth() {
|
|
501
|
+
func singleTrack_disablesBoth() throws {
|
|
502
502
|
let (c, eh, _, _) = makeCoordinator()
|
|
503
|
-
c.setQueue([Track(id: "t1", src: "https://example.com/1.mp3", title: "Track 1")])
|
|
503
|
+
try c.setQueue([Track(id: "t1", src: "https://example.com/1.mp3", title: "Track 1")])
|
|
504
504
|
|
|
505
505
|
#expect(eh.updateSkipAvailabilityCalls.last?.canNext == false)
|
|
506
506
|
#expect(eh.updateSkipAvailabilityCalls.last?.canPrevious == false)
|
|
507
507
|
}
|
|
508
508
|
|
|
509
509
|
@Test @MainActor
|
|
510
|
-
func firstOfMany_nextOnly() {
|
|
510
|
+
func firstOfMany_nextOnly() throws {
|
|
511
511
|
let (c, eh, _, _) = makeCoordinator()
|
|
512
|
-
c.setQueue(Self.multiTrack())
|
|
512
|
+
try c.setQueue(Self.multiTrack())
|
|
513
513
|
|
|
514
514
|
#expect(eh.updateSkipAvailabilityCalls.last?.canNext == true)
|
|
515
515
|
#expect(eh.updateSkipAvailabilityCalls.last?.canPrevious == false)
|
|
516
516
|
}
|
|
517
517
|
|
|
518
518
|
@Test @MainActor
|
|
519
|
-
func lastOfMany_previousOnly() {
|
|
519
|
+
func lastOfMany_previousOnly() throws {
|
|
520
520
|
let (c, eh, _, _) = makeCoordinator()
|
|
521
|
-
c.setQueue(Self.multiTrack())
|
|
521
|
+
try c.setQueue(Self.multiTrack())
|
|
522
522
|
try? c.skipTo(1)
|
|
523
523
|
|
|
524
524
|
#expect(eh.updateSkipAvailabilityCalls.last?.canNext == false)
|
|
@@ -526,9 +526,9 @@ struct SkipAvailabilityCoordinatorTests {
|
|
|
526
526
|
}
|
|
527
527
|
|
|
528
528
|
@Test @MainActor
|
|
529
|
-
func repeatAll_repushesAvailability_atEnd() {
|
|
529
|
+
func repeatAll_repushesAvailability_atEnd() throws {
|
|
530
530
|
let (c, eh, _, _) = makeCoordinator()
|
|
531
|
-
c.setQueue(Self.multiTrack())
|
|
531
|
+
try c.setQueue(Self.multiTrack())
|
|
532
532
|
try? c.skipTo(1) // last track
|
|
533
533
|
eh.updateSkipAvailabilityCalls.removeAll()
|
|
534
534
|
|
|
@@ -545,35 +545,35 @@ struct SkipAvailabilityCoordinatorTests {
|
|
|
545
545
|
@Suite("Player - handleCurrentTrackChanged")
|
|
546
546
|
struct HandleCurrentTrackChangedTests {
|
|
547
547
|
@Test @MainActor
|
|
548
|
-
func clearsError_beforeTransition() {
|
|
548
|
+
func clearsError_beforeTransition() throws {
|
|
549
549
|
let (c, eh, _, _) = makeCoordinator()
|
|
550
550
|
eh.hasLoadedAsset = true
|
|
551
551
|
c.transition(.errorOccurred(.playbackFailed))
|
|
552
552
|
#expect(c.errorStatus.error != nil)
|
|
553
553
|
|
|
554
|
-
loadTrack(c)
|
|
554
|
+
try loadTrack(c)
|
|
555
555
|
|
|
556
556
|
// After loading a track, the error should be cleared
|
|
557
557
|
#expect(c.errorStatus.error == nil)
|
|
558
558
|
}
|
|
559
559
|
|
|
560
560
|
@Test @MainActor
|
|
561
|
-
func preservesPlayWhenReady_acrossLoading() {
|
|
561
|
+
func preservesPlayWhenReady_acrossLoading() throws {
|
|
562
562
|
let (c, _, _, _) = makeCoordinator()
|
|
563
563
|
c.setPlayWhenReady(true)
|
|
564
564
|
|
|
565
|
-
loadTrack(c)
|
|
565
|
+
try loadTrack(c)
|
|
566
566
|
|
|
567
567
|
#expect(c.playWhenReady == true)
|
|
568
568
|
#expect(c.state == .loading)
|
|
569
569
|
}
|
|
570
570
|
|
|
571
571
|
@Test @MainActor
|
|
572
|
-
func nilSrc_transitionsToError() {
|
|
572
|
+
func nilSrc_transitionsToError() throws {
|
|
573
573
|
let (c, _, cb, _) = makeCoordinator()
|
|
574
574
|
|
|
575
|
-
let track = Track(id: "t1", src: nil, title: "No Source")
|
|
576
|
-
c.setQueue([track])
|
|
575
|
+
let track = Track(id: "t1", path: "/no-source", src: nil, title: "No Source")
|
|
576
|
+
try c.setQueue([track])
|
|
577
577
|
|
|
578
578
|
#expect(c.state == .error)
|
|
579
579
|
#expect(c.errorStatus.error == .invalidSourceUrl("nil"))
|
|
@@ -581,10 +581,10 @@ struct HandleCurrentTrackChangedTests {
|
|
|
581
581
|
}
|
|
582
582
|
|
|
583
583
|
@Test @MainActor
|
|
584
|
-
func emitsActiveTrackChangedEvent() {
|
|
584
|
+
func emitsActiveTrackChangedEvent() throws {
|
|
585
585
|
let (c, _, cb, _) = makeCoordinator()
|
|
586
586
|
|
|
587
|
-
loadTrack(c)
|
|
587
|
+
try loadTrack(c)
|
|
588
588
|
|
|
589
589
|
#expect(cb.activeTrackChanges.count == 1)
|
|
590
590
|
let event = cb.activeTrackChanges.first!
|
|
@@ -599,9 +599,9 @@ struct HandleCurrentTrackChangedTests {
|
|
|
599
599
|
@Suite("Player - handleTrackDidPlayToEndTime")
|
|
600
600
|
struct HandleTrackDidPlayToEndTimeTests {
|
|
601
601
|
@Test @MainActor
|
|
602
|
-
func repeatTrack_replays() {
|
|
602
|
+
func repeatTrack_replays() throws {
|
|
603
603
|
let (c, eh, _, _) = makeCoordinator()
|
|
604
|
-
startPlaying(c, eh)
|
|
604
|
+
try startPlaying(c, eh)
|
|
605
605
|
c.repeatMode = .track
|
|
606
606
|
eh.startPlaybackCallCount = 0
|
|
607
607
|
|
|
@@ -617,9 +617,9 @@ struct HandleTrackDidPlayToEndTimeTests {
|
|
|
617
617
|
/// reloads (a bare .paused would park at the end, where play() no-ops).
|
|
618
618
|
/// A repeating queue never conceptually ends, so no queue-ended reaches JS.
|
|
619
619
|
@Test @MainActor
|
|
620
|
-
func repeatTrack_withoutIntent_settlesEnded() {
|
|
620
|
+
func repeatTrack_withoutIntent_settlesEnded() throws {
|
|
621
621
|
let (c, eh, cb, _) = makeCoordinator()
|
|
622
|
-
loadTrack(c)
|
|
622
|
+
try loadTrack(c)
|
|
623
623
|
c.repeatMode = .track
|
|
624
624
|
c.setPlayWhenReady(false)
|
|
625
625
|
|
|
@@ -631,9 +631,9 @@ struct HandleTrackDidPlayToEndTimeTests {
|
|
|
631
631
|
}
|
|
632
632
|
|
|
633
633
|
@Test @MainActor
|
|
634
|
-
func lastTrack_noRepeat_transitionsToEnded() {
|
|
634
|
+
func lastTrack_noRepeat_transitionsToEnded() throws {
|
|
635
635
|
let (c, eh, cb, _) = makeCoordinator()
|
|
636
|
-
loadTrack(c)
|
|
636
|
+
try loadTrack(c)
|
|
637
637
|
c.repeatMode = .off
|
|
638
638
|
|
|
639
639
|
eh.emit(.playedToEnd)
|
|
@@ -643,13 +643,13 @@ struct HandleTrackDidPlayToEndTimeTests {
|
|
|
643
643
|
}
|
|
644
644
|
|
|
645
645
|
@Test @MainActor
|
|
646
|
-
func midQueue_advancesToNext() {
|
|
646
|
+
func midQueue_advancesToNext() throws {
|
|
647
647
|
let (c, eh, cb, _) = makeCoordinator()
|
|
648
648
|
let tracks = [
|
|
649
649
|
Track(id: "t1", src: "https://example.com/1.mp3", title: "Track 1"),
|
|
650
650
|
Track(id: "t2", src: "https://example.com/2.mp3", title: "Track 2"),
|
|
651
651
|
]
|
|
652
|
-
c.setQueue(tracks)
|
|
652
|
+
try c.setQueue(tracks)
|
|
653
653
|
cb.activeTrackChanges.removeAll()
|
|
654
654
|
|
|
655
655
|
eh.emit(.playedToEnd)
|
|
@@ -669,9 +669,9 @@ struct HandleTrackDidPlayToEndTimeTests {
|
|
|
669
669
|
@Suite("Player - natural end drops play intent")
|
|
670
670
|
struct NaturalEndPlayIntentTests {
|
|
671
671
|
@Test @MainActor
|
|
672
|
-
func naturalEnd_clearsPlayWhenReady() {
|
|
672
|
+
func naturalEnd_clearsPlayWhenReady() throws {
|
|
673
673
|
let (c, eh, _, _) = makeCoordinator()
|
|
674
|
-
startPlaying(c, eh)
|
|
674
|
+
try startPlaying(c, eh)
|
|
675
675
|
|
|
676
676
|
eh.emit(.playedToEnd)
|
|
677
677
|
|
|
@@ -680,9 +680,9 @@ struct NaturalEndPlayIntentTests {
|
|
|
680
680
|
}
|
|
681
681
|
|
|
682
682
|
@Test @MainActor
|
|
683
|
-
func naturalEnd_requestsSessionRelease() {
|
|
683
|
+
func naturalEnd_requestsSessionRelease() throws {
|
|
684
684
|
let (c, eh, _, _) = makeCoordinator()
|
|
685
|
-
startPlaying(c, eh)
|
|
685
|
+
try startPlaying(c, eh)
|
|
686
686
|
eh.scheduleAudioSessionReleaseCount = 0
|
|
687
687
|
|
|
688
688
|
eh.emit(.playedToEnd)
|
|
@@ -693,9 +693,9 @@ struct NaturalEndPlayIntentTests {
|
|
|
693
693
|
/// play() from .ended must reload from the start — startPlayback() alone is a
|
|
694
694
|
/// silent no-op on a player parked at the end of its item.
|
|
695
695
|
@Test @MainActor
|
|
696
|
-
func playAfterNaturalEnd_reloadsFromStart() {
|
|
696
|
+
func playAfterNaturalEnd_reloadsFromStart() throws {
|
|
697
697
|
let (c, eh, _, _) = makeCoordinator()
|
|
698
|
-
startPlaying(c, eh)
|
|
698
|
+
try startPlaying(c, eh)
|
|
699
699
|
eh.emit(.playedToEnd)
|
|
700
700
|
eh.resumePosition = 300
|
|
701
701
|
let resolvesBefore = eh.resolveAndLoadCalls.count
|
|
@@ -710,9 +710,9 @@ struct NaturalEndPlayIntentTests {
|
|
|
710
710
|
/// timeControlStatus pause after the end reaches the state machine — the
|
|
711
711
|
/// table's .ended guard must hold the state.
|
|
712
712
|
@Test @MainActor
|
|
713
|
-
func strayPauseAfterNaturalEnd_staysEnded() {
|
|
713
|
+
func strayPauseAfterNaturalEnd_staysEnded() throws {
|
|
714
714
|
let (c, eh, _, _) = makeCoordinator()
|
|
715
|
-
startPlaying(c, eh)
|
|
715
|
+
try startPlaying(c, eh)
|
|
716
716
|
eh.emit(.playedToEnd)
|
|
717
717
|
#expect(c.state == .ended)
|
|
718
718
|
|
|
@@ -722,9 +722,9 @@ struct NaturalEndPlayIntentTests {
|
|
|
722
722
|
}
|
|
723
723
|
|
|
724
724
|
@Test @MainActor
|
|
725
|
-
func interruptionAfterNaturalEnd_doesNotArmResume() {
|
|
725
|
+
func interruptionAfterNaturalEnd_doesNotArmResume() throws {
|
|
726
726
|
let (c, eh, _, _) = makeCoordinator()
|
|
727
|
-
startPlaying(c, eh)
|
|
727
|
+
try startPlaying(c, eh)
|
|
728
728
|
eh.emit(.playedToEnd)
|
|
729
729
|
let resolvesBefore = eh.resolveAndLoadCalls.count
|
|
730
730
|
|
|
@@ -827,9 +827,9 @@ struct SleepTimerFadeTests {
|
|
|
827
827
|
}
|
|
828
828
|
|
|
829
829
|
@Test @MainActor
|
|
830
|
-
func completion_pausesThenRestoresPreFadeVolume() {
|
|
830
|
+
func completion_pausesThenRestoresPreFadeVolume() throws {
|
|
831
831
|
let (c, eh, _, clock) = makeCoordinator()
|
|
832
|
-
loadTrack(c)
|
|
832
|
+
try loadTrack(c)
|
|
833
833
|
c.setPlayWhenReady(true)
|
|
834
834
|
c.transition(.bufferingSufficient) // leave .loading so pause reaches the player
|
|
835
835
|
eh.pausePlaybackCallCount = 0
|
|
@@ -846,9 +846,9 @@ struct SleepTimerFadeTests {
|
|
|
846
846
|
}
|
|
847
847
|
|
|
848
848
|
@Test @MainActor
|
|
849
|
-
func completion_withoutFade_justPauses() {
|
|
849
|
+
func completion_withoutFade_justPauses() throws {
|
|
850
850
|
let (c, eh, _, clock) = makeCoordinator()
|
|
851
|
-
loadTrack(c)
|
|
851
|
+
try loadTrack(c)
|
|
852
852
|
c.setPlayWhenReady(true)
|
|
853
853
|
eh.volume = 0.8
|
|
854
854
|
c.sleepTimerManager.set(seconds: 20)
|
|
@@ -874,9 +874,9 @@ struct SleepTimerFadeTests {
|
|
|
874
874
|
}
|
|
875
875
|
|
|
876
876
|
@Test @MainActor
|
|
877
|
-
func pauseDuringFade_clearsSleepTimer() {
|
|
877
|
+
func pauseDuringFade_clearsSleepTimer() throws {
|
|
878
878
|
let (c, _, _, clock) = makeCoordinator()
|
|
879
|
-
loadTrack(c)
|
|
879
|
+
try loadTrack(c)
|
|
880
880
|
c.setPlayWhenReady(true)
|
|
881
881
|
|
|
882
882
|
startFade(c, clock)
|
|
@@ -886,9 +886,9 @@ struct SleepTimerFadeTests {
|
|
|
886
886
|
}
|
|
887
887
|
|
|
888
888
|
@Test @MainActor
|
|
889
|
-
func pauseWithoutFade_leavesSleepTimerAlone() {
|
|
889
|
+
func pauseWithoutFade_leavesSleepTimerAlone() throws {
|
|
890
890
|
let (c, _, _, _) = makeCoordinator()
|
|
891
|
-
loadTrack(c)
|
|
891
|
+
try loadTrack(c)
|
|
892
892
|
c.setPlayWhenReady(true)
|
|
893
893
|
c.sleepTimerManager.set(seconds: 60, fadeDuration: 10)
|
|
894
894
|
|
|
@@ -902,8 +902,8 @@ struct SleepTimerFadeTests {
|
|
|
902
902
|
|
|
903
903
|
/// Helper to drive the player into an actively-playing state.
|
|
904
904
|
@MainActor
|
|
905
|
-
private func startPlaying(_ c: Player, _ eh: MockPlayerEngine) {
|
|
906
|
-
loadTrack(c)
|
|
905
|
+
private func startPlaying(_ c: Player, _ eh: MockPlayerEngine) throws {
|
|
906
|
+
try loadTrack(c)
|
|
907
907
|
eh.hasLoadedAsset = true
|
|
908
908
|
eh.hasItem = true
|
|
909
909
|
c.setPlayWhenReady(true)
|
|
@@ -913,9 +913,9 @@ private func startPlaying(_ c: Player, _ eh: MockPlayerEngine) {
|
|
|
913
913
|
@Suite("Player - audio session interruptions")
|
|
914
914
|
struct InterruptionTests {
|
|
915
915
|
@Test @MainActor
|
|
916
|
-
func began_whilePlaying_pauses() {
|
|
916
|
+
func began_whilePlaying_pauses() throws {
|
|
917
917
|
let (c, eh, _, _) = makeCoordinator()
|
|
918
|
-
startPlaying(c, eh)
|
|
918
|
+
try startPlaying(c, eh)
|
|
919
919
|
#expect(c.state == .playing)
|
|
920
920
|
|
|
921
921
|
c.handleInterruptionBegan()
|
|
@@ -928,9 +928,9 @@ struct InterruptionTests {
|
|
|
928
928
|
/// is swallowed because `playWhenReady` is still true, so the state stays
|
|
929
929
|
/// `.playing`. The interruption handler must force the pause regardless.
|
|
930
930
|
@Test @MainActor
|
|
931
|
-
func began_afterSwallowedTimeControlPause_stillPauses() {
|
|
931
|
+
func began_afterSwallowedTimeControlPause_stillPauses() throws {
|
|
932
932
|
let (c, eh, _, _) = makeCoordinator()
|
|
933
|
-
startPlaying(c, eh)
|
|
933
|
+
try startPlaying(c, eh)
|
|
934
934
|
|
|
935
935
|
eh.emit(.timeControlStatus(.paused, waitingForNoItem: false))
|
|
936
936
|
#expect(c.state == .playing) // swallowed — the symptom this fix targets
|
|
@@ -941,9 +941,9 @@ struct InterruptionTests {
|
|
|
941
941
|
}
|
|
942
942
|
|
|
943
943
|
@Test @MainActor
|
|
944
|
-
func ended_shouldResume_resumesWhenWasPlaying() {
|
|
944
|
+
func ended_shouldResume_resumesWhenWasPlaying() throws {
|
|
945
945
|
let (c, eh, _, _) = makeCoordinator()
|
|
946
|
-
startPlaying(c, eh)
|
|
946
|
+
try startPlaying(c, eh)
|
|
947
947
|
c.handleInterruptionBegan()
|
|
948
948
|
#expect(c.playWhenReady == false)
|
|
949
949
|
eh.startPlaybackCallCount = 0
|
|
@@ -955,9 +955,9 @@ struct InterruptionTests {
|
|
|
955
955
|
}
|
|
956
956
|
|
|
957
957
|
@Test @MainActor
|
|
958
|
-
func ended_withoutShouldResume_staysPaused() {
|
|
958
|
+
func ended_withoutShouldResume_staysPaused() throws {
|
|
959
959
|
let (c, eh, _, _) = makeCoordinator()
|
|
960
|
-
startPlaying(c, eh)
|
|
960
|
+
try startPlaying(c, eh)
|
|
961
961
|
c.handleInterruptionBegan()
|
|
962
962
|
|
|
963
963
|
c.handleInterruptionEnded(shouldResume: false)
|
|
@@ -970,9 +970,9 @@ struct InterruptionTests {
|
|
|
970
970
|
/// paused-when-interrupted must not grab a non-mixable session for a resume
|
|
971
971
|
/// that never happens.
|
|
972
972
|
@Test @MainActor
|
|
973
|
-
func willResumeAfterInterruption_reflectsCapturedIntent() {
|
|
973
|
+
func willResumeAfterInterruption_reflectsCapturedIntent() throws {
|
|
974
974
|
let (c, eh, _, _) = makeCoordinator()
|
|
975
|
-
startPlaying(c, eh)
|
|
975
|
+
try startPlaying(c, eh)
|
|
976
976
|
|
|
977
977
|
c.handleInterruptionBegan()
|
|
978
978
|
#expect(c.willResumeAfterInterruption == true)
|
|
@@ -988,9 +988,9 @@ struct InterruptionTests {
|
|
|
988
988
|
/// iOS can deliver nested interruptions (Siri, then a phone call) — a second
|
|
989
989
|
/// .began must not re-capture the now-false intent and wipe the resume flag.
|
|
990
990
|
@Test @MainActor
|
|
991
|
-
func doubleBegan_preservesResumeIntent() {
|
|
991
|
+
func doubleBegan_preservesResumeIntent() throws {
|
|
992
992
|
let (c, eh, _, _) = makeCoordinator()
|
|
993
|
-
startPlaying(c, eh)
|
|
993
|
+
try startPlaying(c, eh)
|
|
994
994
|
|
|
995
995
|
c.handleInterruptionBegan()
|
|
996
996
|
c.handleInterruptionBegan()
|
|
@@ -1002,9 +1002,9 @@ struct InterruptionTests {
|
|
|
1002
1002
|
/// Unplugging headphones during a call is a deliberate output loss — the
|
|
1003
1003
|
/// call ending must not blast playback from the built-in speaker.
|
|
1004
1004
|
@Test @MainActor
|
|
1005
|
-
func routeDisconnectDuringInterruption_cancelsResume() {
|
|
1005
|
+
func routeDisconnectDuringInterruption_cancelsResume() throws {
|
|
1006
1006
|
let (c, eh, _, _) = makeCoordinator()
|
|
1007
|
-
startPlaying(c, eh)
|
|
1007
|
+
try startPlaying(c, eh)
|
|
1008
1008
|
c.handleInterruptionBegan()
|
|
1009
1009
|
|
|
1010
1010
|
c.handleRouteDisconnected()
|
|
@@ -1016,9 +1016,9 @@ struct InterruptionTests {
|
|
|
1016
1016
|
/// An explicit stop during the interruption is a terminal command — the
|
|
1017
1017
|
/// interruption-end must not restart playback over it.
|
|
1018
1018
|
@Test @MainActor
|
|
1019
|
-
func stopDuringInterruption_isNotOverriddenByResume() {
|
|
1019
|
+
func stopDuringInterruption_isNotOverriddenByResume() throws {
|
|
1020
1020
|
let (c, eh, _, _) = makeCoordinator()
|
|
1021
|
-
startPlaying(c, eh)
|
|
1021
|
+
try startPlaying(c, eh)
|
|
1022
1022
|
c.handleInterruptionBegan()
|
|
1023
1023
|
let resolvesBefore = eh.resolveAndLoadCalls.count
|
|
1024
1024
|
|
|
@@ -1033,9 +1033,9 @@ struct InterruptionTests {
|
|
|
1033
1033
|
/// A user who plays then pauses during the interruption has taken ownership
|
|
1034
1034
|
/// of the intent — interruption-end must not override their pause.
|
|
1035
1035
|
@Test @MainActor
|
|
1036
|
-
func userPauseDuringInterruption_overridesResume() {
|
|
1036
|
+
func userPauseDuringInterruption_overridesResume() throws {
|
|
1037
1037
|
let (c, eh, _, _) = makeCoordinator()
|
|
1038
|
-
startPlaying(c, eh)
|
|
1038
|
+
try startPlaying(c, eh)
|
|
1039
1039
|
c.handleInterruptionBegan()
|
|
1040
1040
|
|
|
1041
1041
|
c.play()
|
|
@@ -1046,9 +1046,9 @@ struct InterruptionTests {
|
|
|
1046
1046
|
}
|
|
1047
1047
|
|
|
1048
1048
|
@Test @MainActor
|
|
1049
|
-
func ended_doesNotResume_whenNotPlayingBeforeInterruption() {
|
|
1049
|
+
func ended_doesNotResume_whenNotPlayingBeforeInterruption() throws {
|
|
1050
1050
|
let (c, eh, _, _) = makeCoordinator()
|
|
1051
|
-
startPlaying(c, eh)
|
|
1051
|
+
try startPlaying(c, eh)
|
|
1052
1052
|
// Pause before the interruption (e.g. user already paused).
|
|
1053
1053
|
c.setPlayWhenReady(false)
|
|
1054
1054
|
eh.emit(.timeControlStatus(.paused, waitingForNoItem: false))
|
|
@@ -1070,7 +1070,7 @@ struct MutationSkipAvailabilityTests {
|
|
|
1070
1070
|
@Test @MainActor
|
|
1071
1071
|
func move_pushesPostMutationAvailability() throws {
|
|
1072
1072
|
let (c, eh, _, _) = makeCoordinator()
|
|
1073
|
-
c.setQueue([
|
|
1073
|
+
try c.setQueue([
|
|
1074
1074
|
Track(id: "a", src: "https://example.com/a.mp3", title: "A"),
|
|
1075
1075
|
Track(id: "b", src: "https://example.com/b.mp3", title: "B"),
|
|
1076
1076
|
])
|
|
@@ -1086,7 +1086,7 @@ struct MutationSkipAvailabilityTests {
|
|
|
1086
1086
|
@Test @MainActor
|
|
1087
1087
|
func removeBeforeCurrent_pushesPostMutationAvailability() throws {
|
|
1088
1088
|
let (c, eh, _, _) = makeCoordinator()
|
|
1089
|
-
c.setQueue(
|
|
1089
|
+
try c.setQueue(
|
|
1090
1090
|
[
|
|
1091
1091
|
Track(id: "a", src: "https://example.com/a.mp3", title: "A"),
|
|
1092
1092
|
Track(id: "b", src: "https://example.com/b.mp3", title: "B"),
|
|
@@ -1153,9 +1153,9 @@ struct LoadTests {
|
|
|
1153
1153
|
}
|
|
1154
1154
|
|
|
1155
1155
|
@Test @MainActor
|
|
1156
|
-
func aNewTrackStartsAnUnprovenLoad() {
|
|
1156
|
+
func aNewTrackStartsAnUnprovenLoad() throws {
|
|
1157
1157
|
let (c, eh, _, _) = makeCoordinator()
|
|
1158
|
-
c.setQueue([track("a"), track("b")])
|
|
1158
|
+
try c.setQueue([track("a"), track("b")])
|
|
1159
1159
|
let first = c.load
|
|
1160
1160
|
eh.emit(.audioDidStart)
|
|
1161
1161
|
#expect(c.load?.hasPlayed == true)
|
|
@@ -1169,9 +1169,9 @@ struct LoadTests {
|
|
|
1169
1169
|
/// The healthy-playback refill resets the retry budgets mid-play; the load, and with it the
|
|
1170
1170
|
/// recovery budget, must survive it.
|
|
1171
1171
|
@Test @MainActor
|
|
1172
|
-
func aRetryResetKeepsTheLoad() {
|
|
1172
|
+
func aRetryResetKeepsTheLoad() throws {
|
|
1173
1173
|
let (c, eh, _, _) = makeCoordinator()
|
|
1174
|
-
c.setQueue([track("a")])
|
|
1174
|
+
try c.setQueue([track("a")])
|
|
1175
1175
|
eh.emit(.audioDidStart)
|
|
1176
1176
|
let load = c.load
|
|
1177
1177
|
|
|
@@ -1201,9 +1201,9 @@ struct QueuePublicationTests {
|
|
|
1201
1201
|
}
|
|
1202
1202
|
|
|
1203
1203
|
@Test @MainActor
|
|
1204
|
-
func setQueue_publishesTheQueueBeforeTheActiveTrack() {
|
|
1204
|
+
func setQueue_publishesTheQueueBeforeTheActiveTrack() throws {
|
|
1205
1205
|
let (c, _, cb, _) = makeCoordinator()
|
|
1206
|
-
c.setQueue(threeTracks())
|
|
1206
|
+
try c.setQueue(threeTracks())
|
|
1207
1207
|
#expect(cb.queueChanges.map { $0.map(\.id) } == [["a", "b", "c"]])
|
|
1208
1208
|
#expect(cb.queueAndTrackOrder == ["queue", "activeTrack"])
|
|
1209
1209
|
}
|
|
@@ -1211,16 +1211,16 @@ struct QueuePublicationTests {
|
|
|
1211
1211
|
@Test @MainActor
|
|
1212
1212
|
func move_publishesTheSettledQueueOnce() throws {
|
|
1213
1213
|
let (c, _, cb, _) = makeCoordinator()
|
|
1214
|
-
c.setQueue(threeTracks())
|
|
1214
|
+
try c.setQueue(threeTracks())
|
|
1215
1215
|
cb.queueChanges.removeAll()
|
|
1216
1216
|
try c.move(fromIndex: 0, toIndex: 2)
|
|
1217
1217
|
#expect(cb.queueChanges.map { $0.map(\.id) } == [["b", "c", "a"]])
|
|
1218
1218
|
}
|
|
1219
1219
|
|
|
1220
1220
|
@Test @MainActor
|
|
1221
|
-
func clear_publishesAnEmptyQueue() {
|
|
1221
|
+
func clear_publishesAnEmptyQueue() throws {
|
|
1222
1222
|
let (c, _, cb, _) = makeCoordinator()
|
|
1223
|
-
c.setQueue(threeTracks())
|
|
1223
|
+
try c.setQueue(threeTracks())
|
|
1224
1224
|
cb.queueChanges.removeAll()
|
|
1225
1225
|
c.clear()
|
|
1226
1226
|
#expect(cb.queueChanges.map(\.count) == [0])
|
|
@@ -1229,7 +1229,7 @@ struct QueuePublicationTests {
|
|
|
1229
1229
|
@Test @MainActor
|
|
1230
1230
|
func navigation_publishesNoQueue() throws {
|
|
1231
1231
|
let (c, _, cb, _) = makeCoordinator()
|
|
1232
|
-
c.setQueue(threeTracks())
|
|
1232
|
+
try c.setQueue(threeTracks())
|
|
1233
1233
|
cb.queueChanges.removeAll()
|
|
1234
1234
|
c.next()
|
|
1235
1235
|
c.previous()
|
|
@@ -1271,36 +1271,36 @@ struct StopCancelsRetryTests {
|
|
|
1271
1271
|
@Suite("Player - audio session release")
|
|
1272
1272
|
struct SessionReleaseTests {
|
|
1273
1273
|
@Test @MainActor
|
|
1274
|
-
func deliberatePause_requestsRelease() {
|
|
1274
|
+
func deliberatePause_requestsRelease() throws {
|
|
1275
1275
|
let (c, eh, _, _) = makeCoordinator()
|
|
1276
|
-
startPlaying(c, eh)
|
|
1276
|
+
try startPlaying(c, eh)
|
|
1277
1277
|
eh.scheduleAudioSessionReleaseCount = 0
|
|
1278
1278
|
c.pause()
|
|
1279
1279
|
#expect(eh.scheduleAudioSessionReleaseCount == 1)
|
|
1280
1280
|
}
|
|
1281
1281
|
|
|
1282
1282
|
@Test @MainActor
|
|
1283
|
-
func play_doesNotRequestRelease() {
|
|
1283
|
+
func play_doesNotRequestRelease() throws {
|
|
1284
1284
|
let (c, eh, _, _) = makeCoordinator()
|
|
1285
|
-
startPlaying(c, eh)
|
|
1285
|
+
try startPlaying(c, eh)
|
|
1286
1286
|
#expect(eh.scheduleAudioSessionReleaseCount == 0)
|
|
1287
1287
|
}
|
|
1288
1288
|
|
|
1289
1289
|
@Test @MainActor
|
|
1290
|
-
func interruptionBegan_doesNotRequestRelease() {
|
|
1290
|
+
func interruptionBegan_doesNotRequestRelease() throws {
|
|
1291
1291
|
// A phone call pauses (playWhenReady → false) but is meant to resume, so the session must be
|
|
1292
1292
|
// held — the exact race the intent-gating design exists to avoid.
|
|
1293
1293
|
let (c, eh, _, _) = makeCoordinator()
|
|
1294
|
-
startPlaying(c, eh)
|
|
1294
|
+
try startPlaying(c, eh)
|
|
1295
1295
|
eh.scheduleAudioSessionReleaseCount = 0
|
|
1296
1296
|
c.handleInterruptionBegan()
|
|
1297
1297
|
#expect(eh.scheduleAudioSessionReleaseCount == 0)
|
|
1298
1298
|
}
|
|
1299
1299
|
|
|
1300
1300
|
@Test @MainActor
|
|
1301
|
-
func interruptionEnded_withResume_doesNotRequestRelease() {
|
|
1301
|
+
func interruptionEnded_withResume_doesNotRequestRelease() throws {
|
|
1302
1302
|
let (c, eh, _, _) = makeCoordinator()
|
|
1303
|
-
startPlaying(c, eh)
|
|
1303
|
+
try startPlaying(c, eh)
|
|
1304
1304
|
c.handleInterruptionBegan()
|
|
1305
1305
|
eh.scheduleAudioSessionReleaseCount = 0
|
|
1306
1306
|
c.handleInterruptionEnded(shouldResume: true)
|
|
@@ -1308,9 +1308,9 @@ struct SessionReleaseTests {
|
|
|
1308
1308
|
}
|
|
1309
1309
|
|
|
1310
1310
|
@Test @MainActor
|
|
1311
|
-
func interruptionEnded_withoutResume_requestsRelease() {
|
|
1311
|
+
func interruptionEnded_withoutResume_requestsRelease() throws {
|
|
1312
1312
|
let (c, eh, _, _) = makeCoordinator()
|
|
1313
|
-
startPlaying(c, eh)
|
|
1313
|
+
try startPlaying(c, eh)
|
|
1314
1314
|
c.handleInterruptionBegan()
|
|
1315
1315
|
eh.scheduleAudioSessionReleaseCount = 0
|
|
1316
1316
|
c.handleInterruptionEnded(shouldResume: false)
|
|
@@ -1332,9 +1332,9 @@ struct MediaStackEffectTests {
|
|
|
1332
1332
|
}
|
|
1333
1333
|
|
|
1334
1334
|
@Test @MainActor
|
|
1335
|
-
func playIntent_cancelsTheReleaseBeforeJSHearsIt_thenActivatesOnOutput() {
|
|
1335
|
+
func playIntent_cancelsTheReleaseBeforeJSHearsIt_thenActivatesOnOutput() throws {
|
|
1336
1336
|
let (c, _, cb) = makeTraced()
|
|
1337
|
-
loadTrack(c)
|
|
1337
|
+
try loadTrack(c)
|
|
1338
1338
|
cb.publishOrder.removeAll()
|
|
1339
1339
|
|
|
1340
1340
|
c.setPlayWhenReady(true)
|
|
@@ -1346,9 +1346,9 @@ struct MediaStackEffectTests {
|
|
|
1346
1346
|
}
|
|
1347
1347
|
|
|
1348
1348
|
@Test @MainActor
|
|
1349
|
-
func pause_rendersWithoutActivating_thenSchedulesTheRelease() {
|
|
1349
|
+
func pause_rendersWithoutActivating_thenSchedulesTheRelease() throws {
|
|
1350
1350
|
let (c, eh, cb) = makeTraced()
|
|
1351
|
-
startPlaying(c, eh)
|
|
1351
|
+
try startPlaying(c, eh)
|
|
1352
1352
|
cb.publishOrder.removeAll()
|
|
1353
1353
|
|
|
1354
1354
|
c.pause()
|
|
@@ -1359,9 +1359,9 @@ struct MediaStackEffectTests {
|
|
|
1359
1359
|
}
|
|
1360
1360
|
|
|
1361
1361
|
@Test @MainActor
|
|
1362
|
-
func playbackChange_rendersAfterJSHearsIt() {
|
|
1362
|
+
func playbackChange_rendersAfterJSHearsIt() throws {
|
|
1363
1363
|
let (c, _, cb) = makeTraced()
|
|
1364
|
-
loadTrack(c)
|
|
1364
|
+
try loadTrack(c)
|
|
1365
1365
|
cb.publishOrder.removeAll()
|
|
1366
1366
|
|
|
1367
1367
|
c.transition(.errorOccurred(.playbackFailed))
|
|
@@ -1370,13 +1370,13 @@ struct MediaStackEffectTests {
|
|
|
1370
1370
|
}
|
|
1371
1371
|
|
|
1372
1372
|
@Test @MainActor
|
|
1373
|
-
func activeTrackChange_resetsTheNowPlayingLinesAfterJSHearsIt() {
|
|
1373
|
+
func activeTrackChange_resetsTheNowPlayingLinesAfterJSHearsIt() throws {
|
|
1374
1374
|
let (c, eh, cb, _) = makeCoordinator()
|
|
1375
1375
|
eh.onSeamCall = { [weak cb] call in
|
|
1376
1376
|
if call == "nowPlayingTrackChanged" { cb?.queueAndTrackOrder.append(call) }
|
|
1377
1377
|
}
|
|
1378
1378
|
|
|
1379
|
-
c.setQueue([Track(id: "t1", src: "https://example.com/a.mp3", title: "A")])
|
|
1379
|
+
try c.setQueue([Track(id: "t1", src: "https://example.com/a.mp3", title: "A")])
|
|
1380
1380
|
|
|
1381
1381
|
#expect(cb.queueAndTrackOrder == ["queue", "activeTrack", "nowPlayingTrackChanged"])
|
|
1382
1382
|
#expect(eh.nowPlayingTrackChangedCount == 1)
|
|
@@ -1411,9 +1411,9 @@ struct NowPlayingPreviewTests {
|
|
|
1411
1411
|
}
|
|
1412
1412
|
|
|
1413
1413
|
@Test @MainActor
|
|
1414
|
-
func endingPreview_restoresTheCurrentTrackAndRendersItsLines() {
|
|
1414
|
+
func endingPreview_restoresTheCurrentTrackAndRendersItsLines() throws {
|
|
1415
1415
|
let (c, eh, _, _) = makeCoordinator()
|
|
1416
|
-
loadTrack(c, id: "current")
|
|
1416
|
+
try loadTrack(c, id: "current")
|
|
1417
1417
|
c.previewNowPlaying(Track(id: "tapped", src: "https://example.com/tapped.mp3", title: "Tapped"))
|
|
1418
1418
|
let rendersBefore = eh.nowPlayingRenderCount
|
|
1419
1419
|
|