Skip to content
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

Transform audio nodes to video nodes on Safari #1659

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions app/javascript/src/controllers/media_tag_controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,31 @@ export default class extends Controller {
}

initializeVideoJSPlayer() {
this.transformAudioToVideoForSafari()
this.mediaTagTargets.forEach((mediaTag) => {
mediaTag.classList.add('video-js', 'vjs-default-skin')
videojs(mediaTag.id).removeChild('textTrackSettings')
})
}

// Safari 16.6 and below don't render vtt tracks for audio, so change those to be video elements.
transformAudioToVideoForSafari() {
if (!navigator.userAgent.match(/Safari/i))
return
if (![...this.mediaTagTargets].some((mediaTag) => mediaTag.nodeName === "AUDIO" && mediaTag.querySelector('track')))
return

this.mediaTagTargets.forEach((audioTag) => {
if (audioTag.nodeName !== "AUDIO")
return
const videoTag = document.createElement('video');
[...audioTag.attributes].forEach( attr => videoTag.setAttribute(attr.nodeName, attr.nodeValue))
audioTag.childNodes.forEach(child => videoTag.appendChild(child))
audioTag.parentNode.replaceChild(videoTag, audioTag);
})

}

setupThumbnails() {
const thumbnails = [...this.element.querySelectorAll('[data-slider-object]')].
map((mediaDiv, index) => buildThumbnail(mediaDiv.dataset, index))
Expand Down