mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-13 15:46:46 +03:00
feat: Add throwOnPreloadNotSupported flag to preload() (#10163)
This commit is contained in:
committed by
GitHub
parent
6e0599ab3e
commit
8daa8803f7
+10
-3
@@ -2220,10 +2220,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
||||
* for VOD and liveEdge for LIVE).
|
||||
* @param {?string=} mimeType
|
||||
* @param {?shaka.extern.PlayerConfiguration=} config
|
||||
* @param {boolean=} throwOnPreloadNotSupported
|
||||
* @return {!Promise<?shaka.media.PreloadManager>}
|
||||
* @export
|
||||
*/
|
||||
async preload(assetUri, startTime = null, mimeType, config) {
|
||||
async preload(assetUri, startTime = null, mimeType, config,
|
||||
throwOnPreloadNotSupported = false) {
|
||||
goog.asserts.assert(this.config_, 'Config must not be null!');
|
||||
mimeType = mimeType?.toLowerCase();
|
||||
const preloadConfig = this.defaultConfig_();
|
||||
@@ -2233,10 +2235,15 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
|
||||
assetUri, startTime, mimeType, /* standardLoad= */ false,
|
||||
preloadConfig);
|
||||
if (!preloadManager) {
|
||||
this.onError_(new shaka.util.Error(
|
||||
const error = new shaka.util.Error(
|
||||
shaka.util.Error.Severity.CRITICAL,
|
||||
shaka.util.Error.Category.PLAYER,
|
||||
shaka.util.Error.Code.SRC_EQUALS_PRELOAD_NOT_SUPPORTED));
|
||||
shaka.util.Error.Code.SRC_EQUALS_PRELOAD_NOT_SUPPORTED);
|
||||
if (throwOnPreloadNotSupported) {
|
||||
throw error;
|
||||
} else {
|
||||
this.onError_(error);
|
||||
}
|
||||
} else {
|
||||
preloadManager.start();
|
||||
}
|
||||
|
||||
@@ -282,7 +282,8 @@ shaka.queue.QueueManager = class extends shaka.util.FakeEventTarget {
|
||||
try {
|
||||
const preloadManager = await this.player_.preload(
|
||||
nextItem.manifestUri, nextItem.startTime,
|
||||
nextItem.mimeType, nextItem.config);
|
||||
nextItem.mimeType, nextItem.config,
|
||||
/* throwOnPreloadNotSupported= */ true);
|
||||
this.preloadNext_ = {item: nextItem, preloadManager};
|
||||
} catch (e) {
|
||||
// Ignore errors during preload
|
||||
|
||||
@@ -162,7 +162,7 @@ describe('QueueManager', () => {
|
||||
await shaka.test.Util.shortDelay();
|
||||
|
||||
expect(preloadSpy).toHaveBeenCalledWith(
|
||||
queueItem2.manifestUri, null, null, null);
|
||||
queueItem2.manifestUri, null, null, null, true);
|
||||
});
|
||||
|
||||
it('cleans up previous preload when playing next item', async () => {
|
||||
|
||||
Reference in New Issue
Block a user