Skip to content

Commit

Permalink
add SourceBuffer API checks
Browse files Browse the repository at this point in the history
  • Loading branch information
mad-gooze committed May 16, 2017
1 parent a32eabc commit 6019ef6
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/hls.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,18 @@ class Hls {

static isSupported() {
window.MediaSource = window.MediaSource || window.WebKitMediaSource;
return (window.MediaSource &&
typeof window.MediaSource.isTypeSupported === 'function' &&
window.MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"'));
window.SourceBuffer = window.SourceBuffer || window.WebKitSourceBuffer;

const isTypeSupported = window.MediaSource &&
typeof window.MediaSource.isTypeSupported === 'function' &&
window.MediaSource.isTypeSupported('video/mp4; codecs="avc1.42E01E,mp4a.40.2"');
const hasSupportedSourceBuffer = window.SourceBuffer && window.SourceBuffer.prototype &&
typeof window.SourceBuffer.prototype.appendBuffer === 'function' &&
typeof window.SourceBuffer.prototype.remove === 'function';
const isSafari = navigator.vendor && navigator.vendor.indexOf('Apple') > -1;

// safari does not expose SourceBuffer globally so checking SourceBuffer.prototype is impossible
return isTypeSupported && (hasSupportedSourceBuffer || isSafari);
}

static get Events() {
Expand Down

0 comments on commit 6019ef6

Please sign in to comment.