Skip to content

Commit 7989731

Browse files
committed
Check for noAudio on setup
Fixes goldfire#619
1 parent 3abbeed commit 7989731

File tree

1 file changed

+27
-28
lines changed

1 file changed

+27
-28
lines changed

src/howler.core.js

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,33 @@
186186
// Automatically begin the 30-second suspend process
187187
self._autoSuspend();
188188

189+
// Check if audio is available.
190+
if (!self.usingWebAudio) {
191+
// No audio is available on this system if noAudio is set to true.
192+
if (typeof Audio !== 'undefined') {
193+
try {
194+
var test = new Audio();
195+
196+
// Check if the canplaythrough event is available.
197+
if (typeof test.oncanplaythrough === 'undefined') {
198+
self._canPlayEvent = 'canplay';
199+
}
200+
} catch(e) {
201+
self.noAudio = true;
202+
}
203+
} else {
204+
self.noAudio = true;
205+
}
206+
}
207+
208+
// Test to make sure audio isn't disabled in Internet Explorer.
209+
try {
210+
var test = new Audio();
211+
if (test.muted) {
212+
self.noAudio = true;
213+
}
214+
} catch (e) {}
215+
189216
// Check for supported codecs.
190217
if (!self.noAudio) {
191218
self._setupCodecs();
@@ -2094,8 +2121,6 @@
20942121
* Setup the audio context when available, or switch to HTML5 Audio mode.
20952122
*/
20962123
var setupAudioContext = function() {
2097-
Howler.noAudio = false;
2098-
20992124
// Check if we are using Web Audio and setup the AudioContext if we are.
21002125
try {
21012126
if (typeof AudioContext !== 'undefined') {
@@ -2109,32 +2134,6 @@
21092134
Howler.usingWebAudio = false;
21102135
}
21112136

2112-
if (!Howler.usingWebAudio) {
2113-
// No audio is available on this system if noAudio is set to true.
2114-
if (typeof Audio !== 'undefined') {
2115-
try {
2116-
var test = new Audio();
2117-
2118-
// Check if the canplaythrough event is available.
2119-
if (typeof test.oncanplaythrough === 'undefined') {
2120-
Howler._canPlayEvent = 'canplay';
2121-
}
2122-
} catch(e) {
2123-
Howler.noAudio = true;
2124-
}
2125-
} else {
2126-
Howler.noAudio = true;
2127-
}
2128-
}
2129-
2130-
// Test to make sure audio isn't disabled in Internet Explorer
2131-
try {
2132-
var test = new Audio();
2133-
if (test.muted) {
2134-
Howler.noAudio = true;
2135-
}
2136-
} catch (e) {}
2137-
21382137
// Check if a webview is being used on iOS8 or earlier (rather than the browser).
21392138
// If it is, disable Web Audio as it causes crashing.
21402139
var iOS = (/iP(hone|od|ad)/.test(Howler._navigator && Howler._navigator.platform));

0 commit comments

Comments
 (0)