-
Notifications
You must be signed in to change notification settings - Fork 10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: workaround to make Airplay work on Safari #74
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ var ERROR = require('../error'); | |
var getContentType = require('./getContentType'); | ||
var HLS_CONFIG = require('./hlsConfig'); | ||
|
||
var isSafari = navigator.userAgent.includes("Safari") && !(/(chrome|firefox)/i.test(window.navigator.userAgent)) && (navigator.vendor || "").startsWith("Apple"); | ||
|
||
function HTMLVideo(options) { | ||
options = options || {}; | ||
|
||
|
@@ -535,6 +537,22 @@ function HTMLVideo(options) { | |
onPropChanged('audioTracks'); | ||
onPropChanged('selectedAudioTrackId'); | ||
}); | ||
|
||
// adds the original stream source, so Safari can use it for AirPlay when it needs to | ||
// see more details here: https://github.com/video-dev/hls.js/issues/5989#issuecomment-1825916766 | ||
function attachOriginalSource() { | ||
var source = document.createElement('source'); | ||
source.src = stream.url; | ||
source.dataset.id = 'original-stream'; | ||
videoElement.appendChild(source); | ||
videoElement.disableRemotePlayback = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. could this be moved on line 28? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, this has to be done after calling |
||
|
||
hls.off(Hls.Events.MEDIA_ATTACHING, attachOriginalSource); | ||
} | ||
|
||
if (isSafari) | ||
hls.on(Hls.Events.MEDIA_ATTACHING, attachOriginalSource); | ||
|
||
hls.loadSource(stream.url); | ||
hls.attachMedia(videoElement); | ||
} else { | ||
|
@@ -570,6 +588,11 @@ function HTMLVideo(options) { | |
videoElement.removeAttribute('src'); | ||
videoElement.load(); | ||
videoElement.currentTime = 0; | ||
Array.from(videoElement.children || []).forEach(function(child) { | ||
if (child && child.dataset && child.dataset.id === 'original-stream') { | ||
videoElement.removeChild(child); | ||
} | ||
}); | ||
onPropChanged('stream'); | ||
onPropChanged('loaded'); | ||
onPropChanged('paused'); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we need to add the corresponding action in the
unload
command handler after thevideoElement.removeAttribute('src');
callsomething like:
while (videoElement.child) videoElement.removeChild(videoElement.child)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done