Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a util for handling media readyState related logic.
Fixes #2555. Change-Id: I735064952bc425bfb18d6c5681921ae1691eb348
- Loading branch information
Showing
7 changed files
with
83 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
/** @license | ||
* Copyright 2016 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
goog.provide('shaka.util.MediaReadyState'); | ||
|
||
|
||
shaka.util.MediaReadyState = class { | ||
/* | ||
* @param {!HTMLMediaElement} mediaElement | ||
* @param {HTMLMediaElement.ReadyState} readyState | ||
* @param {!function()} callback | ||
*/ | ||
static waitForReadyState(mediaElement, readyState, eventManager, callback) { | ||
if (readyState == HTMLMediaElement.HAVE_NOTHING || | ||
mediaElement.readyState >= readyState) { | ||
callback(); | ||
} else { | ||
const MediaReadyState = shaka.util.MediaReadyState; | ||
const eventName = | ||
MediaReadyState.READY_STATES_TO_EVENT_NAMES_.get(readyState); | ||
eventManager.listenOnce(mediaElement, eventName, callback); | ||
} | ||
} | ||
}; | ||
|
||
/** | ||
* @const {!Map.<number, string>} | ||
* @private | ||
*/ | ||
shaka.util.MediaReadyState.READY_STATES_TO_EVENT_NAMES_ = new Map([ | ||
[HTMLMediaElement.HAVE_METADATA, 'loadedmetadata'], | ||
[HTMLMediaElement.HAVE_CURRENT_DATA, 'loadeddata'], | ||
[HTMLMediaElement.HAVE_FUTURE_DATA, 'canplay'], | ||
[HTMLMediaElement.HAVE_ENOUGH_DATA, 'canplaythrough'], | ||
]); |