Skip to content

Commit

Permalink
Disable WebM on Safari <15
Browse files Browse the repository at this point in the history
This is a temporary measure as Safari isn't currently decoding WebM files correctly This issue is being tracked in #1476.
  • Loading branch information
goldfire committed Jun 20, 2021
1 parent 309376b commit 09a3b28
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/howler.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -264,8 +264,11 @@
var mpegTest = audioTest.canPlayType('audio/mpeg;').replace(/^no$/, '');

// Opera version <33 has mixed MP3 support, so we need to check for and block it.
var checkOpera = self._navigator && self._navigator.userAgent.match(/OPR\/([0-6].)/g);
var ua = self._navigator ? self._navigator.userAgent : '';
var checkOpera = ua.match(/OPR\/([0-6].)/g);
var isOldOpera = (checkOpera && parseInt(checkOpera[0].split('/')[1], 10) < 33);
var checkSafari = ua.indexOf('Safari') !== -1 && ua.indexOf('Chrome') === -1;
var isOldSafari = (checkSafari && parseInt(ua.match(/Version\/(.*?) /)[1], 10) < 15);

self._codecs = {
mp3: !!(!isOldOpera && (mpegTest || audioTest.canPlayType('audio/mp3;').replace(/^no$/, ''))),
Expand All @@ -279,8 +282,8 @@
m4a: !!(audioTest.canPlayType('audio/x-m4a;') || audioTest.canPlayType('audio/m4a;') || audioTest.canPlayType('audio/aac;')).replace(/^no$/, ''),
m4b: !!(audioTest.canPlayType('audio/x-m4b;') || audioTest.canPlayType('audio/m4b;') || audioTest.canPlayType('audio/aac;')).replace(/^no$/, ''),
mp4: !!(audioTest.canPlayType('audio/x-mp4;') || audioTest.canPlayType('audio/mp4;') || audioTest.canPlayType('audio/aac;')).replace(/^no$/, ''),
weba: !!audioTest.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, ''),
webm: !!audioTest.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, ''),
weba: !!(!isOldSafari && audioTest.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')),
webm: !!(!isOldSafari && audioTest.canPlayType('audio/webm; codecs="vorbis"').replace(/^no$/, '')),
dolby: !!audioTest.canPlayType('audio/mp4; codecs="ec-3"').replace(/^no$/, ''),
flac: !!(audioTest.canPlayType('audio/x-flac;') || audioTest.canPlayType('audio/flac;')).replace(/^no$/, '')
};
Expand Down

0 comments on commit 09a3b28

Please sign in to comment.