From fd57e7f48a01ffbdf296d48b80089078b410eac7 Mon Sep 17 00:00:00 2001 From: theodab Date: Mon, 12 Feb 2024 11:56:09 -0800 Subject: [PATCH] fix(preload): Fix timing of call to stopQueuingLatePhaseQueuedOperations (#6238) This method should be called after the load is successful, not if the load fails. This also adds a new test that ensures that onKeyStatus_ messages work correctly, as a regression test. This was exposed by the test failures, but was not the cause of them. Issue #6225 --- lib/player.js | 2 +- test/player_unit.js | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/lib/player.js b/lib/player.js index 5ee0e44a8b..4899b81175 100644 --- a/lib/player.js +++ b/lib/player.js @@ -1557,13 +1557,13 @@ shaka.Player = class extends shaka.util.FakeEventTarget { await this.loadInner_( startTimeOfLoad, prefetchedVariant, segmentPrefetchById); }, 'loadInner_'); + preloadManager.stopQueuingLatePhaseQueuedOperations(); } this.dispatchEvent(shaka.Player.makeEvent_( shaka.util.FakeEvent.EventName.Loaded)); } catch (error) { if (error.code != shaka.util.Error.Code.LOAD_INTERRUPTED) { await this.unload(/* initializeMediaSource= */ false); - preloadManager.stopQueuingLatePhaseQueuedOperations(); } throw error; } finally { diff --git a/test/player_unit.js b/test/player_unit.js index d1ee7b1f89..ea4e837762 100644 --- a/test/player_unit.js +++ b/test/player_unit.js @@ -715,6 +715,22 @@ describe('Player', () => { expect(player.getLoadMode()).toBe(shaka.Player.LoadMode.MEDIA_SOURCE); }); }); + + it('fires keystatuschanged events', async () => { + const keyStatusChanged = jasmine.createSpy('keyStatusChanged'); + player.addEventListener( + 'keystatuschanged', Util.spyFunc(keyStatusChanged)); + player.createDrmEngine = (playerInterface) => { + // Call the onKeyStatus on the playerInterface, before load is finished. + playerInterface.onKeyStatus({ + 'aaa': 'usable', + 'bbb': 'output-restricted', + }); + return drmEngine; + }; + await player.load(fakeManifestUri, 0, fakeMimeType); + expect(keyStatusChanged).toHaveBeenCalled(); + }); }); // describe('load/unload') describe('getConfiguration', () => {