Skip to content

Commit

Permalink
Merge pull request #143 from aasenov/feature/add_managed_media_source…
Browse files Browse the repository at this point in the history
…_support

Add Managed Media Source support (for IPhone running IOS 17+)
  • Loading branch information
samirkumardas authored Jul 28, 2024
2 parents 6233431 + 6ccfd37 commit f6a91bc
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/jmuxer.js
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,29 @@ export default class JMuxer extends Event {
}

setupMSE() {
window.MediaSource = window.MediaSource || window.WebKitMediaSource;
window.MediaSource = window.MediaSource || window.WebKitMediaSource || window.ManagedMediaSource;
if (!window.MediaSource) {
throw 'Oops! Browser does not support media source extension.';
throw 'Oops! Browser does not support Media Source Extension or Managed Media Source (IOS 17+).';
}
this.isMSESupported = !!window.MediaSource;
this.mediaSource = new MediaSource();
this.mediaSource = new window.MediaSource();
this.url = URL.createObjectURL(this.mediaSource);
this.node.src = this.url;
if(window.MediaSource === window.ManagedMediaSource) {
try {
this.node.removeAttribute('src');
// ManagedMediaSource will not open without disableRemotePlayback set to false or source alternatives
this.node.disableRemotePlayback = true;
const source = document.createElement('source');
source.type = 'video/mp4';
source.src = this.url;
this.node.appendChild(source);
this.node.load();
} catch (error) {
this.node.src = this.url;
}
} else {
this.node.src = this.url;
}
this.mseEnded = false;
this.mediaSource.addEventListener('sourceopen', this.onMSEOpen.bind(this));
this.mediaSource.addEventListener('sourceclose', this.onMSEClose.bind(this));
Expand Down

0 comments on commit f6a91bc

Please sign in to comment.