Skip to content

Commit

Permalink
Reimplement "Avoid Platform.supportsMediaType when loading."
Browse files Browse the repository at this point in the history
This reverts commit 6667ea5 and
reimplements it using a fallback to an arbitrary media element when
there isn't one yet.

This also adds a regression test that would have caught the issue
sooner.

Closes shaka-project#2326

Change-Id: I44573ae551db51f788d7c97b9680dfd45adee0a0
  • Loading branch information
joeyparrish committed Jan 7, 2020
1 parent 6da39f5 commit 4883691
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
3 changes: 2 additions & 1 deletion lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,8 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
if (mimeType) {
// If we have a MIME type, check if the browser can play it natively.
// This will cover both single files and native HLS.
const canPlayNatively = this.video_.canPlayType(mimeType) != '';
const mediaElement = payload.mediaElement || Platform.anyMediaElement();
const canPlayNatively = mediaElement.canPlayType(mimeType) != '';

// If we can't play natively, then src= isn't an option.
if (!canPlayNatively) {
Expand Down
5 changes: 2 additions & 3 deletions lib/util/platform.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ shaka.util.Platform = class {
* @return {boolean}
*/
static supportsMediaType(mimeType) {
const video = shaka.util.Platform.anyMediaElement_();
const video = shaka.util.Platform.anyMediaElement();
return video.canPlayType(mimeType) != '';
}

Expand Down Expand Up @@ -157,9 +157,8 @@ shaka.util.Platform = class {
* Cached elements expire in one second so that they can be GC'd or removed.
*
* @return {!HTMLMediaElement}
* @private
*/
static anyMediaElement_() {
static anyMediaElement() {
const Platform = shaka.util.Platform;
if (Platform.cachedMediaElement_) {
return Platform.cachedMediaElement_;
Expand Down
17 changes: 17 additions & 0 deletions test/player_integration.js
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,23 @@ describe('Player', () => {
expect(video.playbackRate).toBe(1);
});

// Regression test for #2326.
//
// 1. Construct an instance with a video element.
// 2. Don't call or await attach().
// 3. Call load() with a MIME type, which triggers a check for native
// playback support.
//
// Note that a real playback may use a HEAD request to fetch a MIME type,
// even if one is not specified in load().
it('immediately after construction with MIME type', async () => {
const testSchemeMimeType = 'application/x-test-manifest';
player = new compiledShaka.Player(video);
await player.load('test:sintel_compiled', 0, testSchemeMimeType);
video.play();
await waitUntilPlayheadReaches(eventManager, video, 1, 10);
});

/**
* Gets the language of the active Variant.
* @return {string}
Expand Down

0 comments on commit 4883691

Please sign in to comment.