From e60da3fbcc0379e38ac0bed3402571bcb79ae4be Mon Sep 17 00:00:00 2001 From: Cecilia de Siqueira Saraiva Date: Tue, 30 Jul 2024 10:20:37 +0200 Subject: [PATCH 1/2] - Align skipToNext behavior with Android: don't do anything when there's no nextItem set up --- Sources/Player/PlaybackEngine/PlayerEngine.swift | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/Sources/Player/PlaybackEngine/PlayerEngine.swift b/Sources/Player/PlaybackEngine/PlayerEngine.swift index 49d8942c..59041833 100644 --- a/Sources/Player/PlaybackEngine/PlayerEngine.swift +++ b/Sources/Player/PlaybackEngine/PlayerEngine.swift @@ -181,13 +181,10 @@ final class PlayerEngine { func skipToNext(timestamp: UInt64) { queue.dispatch { - let playerItem = self.nextItem - self.currentItem?.unloadFromPlayer() - - guard let playerItem else { - self.reset(to: .IDLE) + guard let playerItem = self.nextItem else { return } + self.currentItem?.unloadFromPlayer() // The order is important due to logic for emitting events in didSet of the items. self.currentItem = playerItem From dbe342164cf8f067d5d75b5e0c951c8d1c872f9e Mon Sep 17 00:00:00 2001 From: Cecilia de Siqueira Saraiva Date: Tue, 30 Jul 2024 11:06:54 +0200 Subject: [PATCH 2/2] fix test after skipToNext behavior change --- .../Player/PlaybackEngine/PlayerEngineTests.swift | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Tests/PlayerTests/Player/PlaybackEngine/PlayerEngineTests.swift b/Tests/PlayerTests/Player/PlaybackEngine/PlayerEngineTests.swift index c23c6d17..30457b72 100644 --- a/Tests/PlayerTests/Player/PlaybackEngine/PlayerEngineTests.swift +++ b/Tests/PlayerTests/Player/PlaybackEngine/PlayerEngineTests.swift @@ -496,7 +496,7 @@ extension PlayerEngineTests { // THEN // Make sure it's idle, and items remain nil - XCTAssertEqual(playerEngine.getState(), .IDLE) + XCTAssertEqual(playerEngine.getState(), .NOT_PLAYING) XCTAssertEqual(playerEngine.currentItem, nil) XCTAssertEqual(playerEngine.nextItem, nil) @@ -618,17 +618,17 @@ extension PlayerEngineTests { assertGenericPlayer(assets: [asset], playCount: 2, pauseCount: 0) // WHEN - // skipToNext() should unload the current one, set the previously next as current, and nextItem should become nil. + // skipToNext() should not do anything when next item is not set up. + // If still playing, it will continue till it ends. playerEngine.skipToNext(timestamp: timestamp) - // Since setNext was not called, meaning there's no nextItem set up, then both currentItem and nextItem are nil, reset is - // called, and set to IDLE state. - assertItem(item: playerEngine.currentItem, expectedItem: nil, shouldBeLoaded: nil) + // Since setNext was not called and skipToNext didn't do anything, everything remains. + assertItem(item: playerEngine.currentItem, expectedItem: expectedPlayerItem1, shouldBeLoaded: true) assertItem(item: playerEngine.nextItem, expectedItem: nil, shouldBeLoaded: nil) - XCTAssertEqual(playerEngine.getState(), .IDLE) + XCTAssertEqual(playerEngine.getState(), .PLAYING) // Same as above - assertGenericPlayer(assets: [], playCount: 2, pauseCount: 0) + assertGenericPlayer(assets: [asset], playCount: 2, pauseCount: 0) assertPlayerLoader(trackPlaybackInfos: [trackPlaybackInfo1]) }