forked from shaka-project/shaka-player
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(MediaCap): Add polyfill for MediaCapabilities
If navigator.mediaCapabilties is not supported by the browser, use MediaSource.isTypeSupported to check if the stream is supported. Issue shaka-project#1391 Change-Id: Iee0c7e339add2a07028ed14a03df14e4d36a203e
- Loading branch information
1 parent
57ee238
commit f4c6063
Showing
3 changed files
with
105 additions
and
48 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/*! @license | ||
* Shaka Player | ||
* Copyright 2016 Google LLC | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
goog.provide('shaka.polyfill.MediaCapabilities'); | ||
|
||
goog.require('shaka.log'); | ||
goog.require('shaka.polyfill'); | ||
|
||
|
||
/** | ||
* @summary A polyfill to provide navigator.mediaCapabilities on all browsers. | ||
* This is necessary for Tizen 3, Xbox One and possibly others we have yet to | ||
* discover. | ||
*/ | ||
shaka.polyfill.MediaCapabilities = class { | ||
/** | ||
* Install the polyfill if needed. | ||
*/ | ||
static install() { | ||
shaka.log.debug('MediaCapabilities: install'); | ||
|
||
if (navigator.mediaCapabilities) { | ||
shaka.log.debug( | ||
'MediaCapabilities: Native mediaCapabilities support found.'); | ||
return; | ||
} | ||
|
||
navigator.mediaCapabilities = /** @type {!MediaCapabilities} */ ({}); | ||
navigator.mediaCapabilities.decodingInfo = | ||
shaka.polyfill.MediaCapabilities.decodingInfo_; | ||
} | ||
|
||
/** | ||
* @param {!MediaDecodingConfiguration} mediaDecodingConfig | ||
* @return {!Promise.<!MediaCapabilitiesDecodingInfo>} | ||
* @private | ||
*/ | ||
static decodingInfo_(mediaDecodingConfig) { | ||
const res = { | ||
supported: false, | ||
powerEfficient: true, | ||
smooth: true, | ||
keySystemAccess: null, | ||
configuration: mediaDecodingConfig, | ||
}; | ||
|
||
if (!mediaDecodingConfig) { | ||
return Promise.resolve(res); | ||
} | ||
|
||
// Use 'MediaSource.isTypeSupported' to check if the stream is supported. | ||
if (mediaDecodingConfig['video']) { | ||
const contentType = mediaDecodingConfig['video'].contentType; | ||
const isSupported = MediaSource.isTypeSupported(contentType); | ||
if (!isSupported) { | ||
return Promise.resolve(res); | ||
} | ||
} | ||
|
||
if (mediaDecodingConfig['audio']) { | ||
const contentType = mediaDecodingConfig['audio'].contentType; | ||
const isSupported = MediaSource.isTypeSupported(contentType); | ||
if (!isSupported) { | ||
return Promise.resolve(res); | ||
} | ||
} | ||
|
||
res.supported = true; | ||
return Promise.resolve(res); | ||
} | ||
}; | ||
|
||
|
||
shaka.polyfill.register(shaka.polyfill.MediaCapabilities.install); |
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