Skip to content

Commit

Permalink
fix: WebAudio create context should try catch
Browse files Browse the repository at this point in the history
  • Loading branch information
06wj committed Mar 13, 2019
1 parent 5912e6f commit b422d08
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/media/WebAudio.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,15 @@
*/
var WebAudio = (function(){

var AudioContext = window.AudioContext || window.webkitAudioContext;
var context = AudioContext ? new AudioContext() : null;
var context = null;
try {
var AudioContext = window.AudioContext || window.webkitAudioContext;
if (AudioContext) {
context = new AudioContext();
}
} catch(e) {
context = null;
}

return Class.create(/** @lends WebAudio.prototype */{
Mixes: EventMixin,
Expand Down Expand Up @@ -316,7 +323,7 @@ return Class.create(/** @lends WebAudio.prototype */{
* @language=zh
* 浏览器是否支持WebAudio。
*/
isSupported: AudioContext != null,
isSupported: context !== null,

/**
* @language=en
Expand Down

0 comments on commit b422d08

Please sign in to comment.