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

Feature: add codec support for HLS (m3u8 and m3u formats) #1592

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ Stop all sounds and reset their seek position to the beginning.

#### codecs(ext)
Check supported audio codecs. Returns `true` if the codec is supported in the current browser.
* **ext**: `String` File extension. One of: "mp3", "mpeg", "opus", "ogg", "oga", "wav", "aac", "caf", "m4a", "m4b", "mp4", "weba", "webm", "dolby", "flac".
* **ext**: `String` File extension. One of: "m3u", "m3u8", "mp3", "mpeg", "opus", "ogg", "oga", "wav", "aac", "caf", "m4a", "m4b", "mp4", "weba", "webm", "dolby", "flac".

#### unload()
Unload and destroy all currently loaded Howl objects. This will immediately stop all sounds and remove them from cache.
Expand Down
21 changes: 14 additions & 7 deletions src/howler.core.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
self.html5PoolSize = 10;

// Internal properties.
self._codecs = {};
self._codecs = null;
self._howls = [];
self._muted = false;
self._volume = 1;
Expand Down Expand Up @@ -187,11 +187,15 @@

/**
* Check for codec support of specific extension.
* @param {String} ext Audio file extention.
* @return {Boolean}
* @param {String} ext Audio file extension.
* @return {Boolean|undefined}
*/
codecs: function(ext) {
return (this || Howler)._codecs[ext.replace(/^x-/, '')];
var self = this || Howler;

if (self._codecs) {
return self._codecs[ext.replace(/^x-/, '')];
}
},

/**
Expand Down Expand Up @@ -234,8 +238,8 @@
}
} catch (e) {}

// Check for supported codecs.
if (!self.noAudio) {
// Cache list of supported codecs once.
if (!self.noAudio && !self._codecs) {
self._setupCodecs();
}

Expand All @@ -262,6 +266,7 @@
}

var mpegTest = audioTest.canPlayType('audio/mpeg;').replace(/^no$/, '');
var hlsTest = audioTest.canPlayType('application/vnd.apple.mpegurl').replace(/^no$/, '');

// Opera version <33 has mixed MP3 support, so we need to check for and block it.
var ua = self._navigator ? self._navigator.userAgent : '';
Expand All @@ -272,6 +277,8 @@
var isOldSafari = (checkSafari && safariVersion && parseInt(safariVersion[1], 10) < 15);

self._codecs = {
m3u: !!hlsTest,
m3u8: !!hlsTest,
mp3: !!(!isOldOpera && (mpegTest || audioTest.canPlayType('audio/mp3;').replace(/^no$/, ''))),
mpeg: !!mpegTest,
opus: !!audioTest.canPlayType('audio/ogg; codecs="opus"').replace(/^no$/, ''),
Expand Down Expand Up @@ -984,7 +991,7 @@

var listener = function() {
self._state = 'loaded';

// Begin playback.
playHtml5();

Expand Down