Skip to content

Commit

Permalink
Add support for HEAD request mime type getting.
Browse files Browse the repository at this point in the history
  • Loading branch information
theodab committed Oct 10, 2023
1 parent 9120559 commit edb3d72
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions lib/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -1209,7 +1209,9 @@ shaka.Player = class extends shaka.util.FakeEventTarget {

this.assetUri_ = assetUri;

if (this.shouldUseSrcEquals_(assetUri, mimeType)) {
const shouldUseSrcEquals =
await this.shouldUseSrcEquals_(assetUri, mimeType);
if (shouldUseSrcEquals) {
await this.initializeSrcEqualsDrmInner_(mimeType);
await this.srcEqualsInner_(startTime, startTimeOfLoad);
} else {
Expand All @@ -1232,12 +1234,12 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
*
* @param {string} assetUri
* @param {string=} mimeType
* @return {boolean}
* @return {!Promise.<boolean>}
* |true| if the content should be loaded with src=, |false| if the content
* should be loaded with MediaSource.
* @private
*/
shouldUseSrcEquals_(assetUri, mimeType) {
async shouldUseSrcEquals_(assetUri, mimeType) {
const Platform = shaka.util.Platform;
const MimeUtils = shaka.util.MimeUtils;

Expand All @@ -1255,11 +1257,15 @@ shaka.Player = class extends shaka.util.FakeEventTarget {
mimeType = shaka.Player.SRC_EQUAL_EXTENSIONS_TO_MIME_TYPES_[extension];
}

// TODO: The load graph system has a design limitation that requires routing
// destination to be chosen synchronously. This means we can only make the
// right choice about src= consistently if we have a well-known file
// extension or API-provided MIME type. Detection of MIME type from a HEAD
// request (as is done for manifest types) can't be done yet.
// If no MIME type is provided, and we can't base it on extension, make a
// HEAD request to determine it.
if (!mimeType) {
// TODO: Modify |HlsParser.guessMimeType_| to also use
// |shaka.media.ManifestParser.getMimeType|, for standardization?
const retryParams = this.config_.manifest.retryParameters;
mimeType = await shaka.media.ManifestParser.getMimeType(
assetUri, this.networkingEngine_, retryParams);
}

if (mimeType) {
// If we have a MIME type, check if the browser can play it natively.
Expand Down

0 comments on commit edb3d72

Please sign in to comment.