Skip to content

Commit

Permalink
Remove deprecated mozilla player
Browse files Browse the repository at this point in the history
  • Loading branch information
discordier committed Jul 18, 2017
1 parent c54836b commit 794b150
Showing 1 changed file with 10 additions and 42 deletions.
52 changes: 10 additions & 42 deletions src/util/player.es6
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import {text2Uint8Array, Uint32ToUint8Array, Uint16ToUint8Array} from '../util/util.es6';

const ENABLE_DEPRECATED_MOZILLA_AUDIO = false;

/**
*
* @param {AudioContext} context
Expand All @@ -24,33 +22,7 @@ function Play(context, audiobuffer) {
});
}

if (ENABLE_DEPRECATED_MOZILLA_AUDIO) {
function PlayMozilla(context, audiobuffer) {
return new Promise((resolve) => {
function play () {
let written = context.mozWriteAudio(audiobuffer);
let diff = audiobuffer.length - written;
if (diff <= 0) {
resolve(true);
return;
}
let buffer = new Float32Array(diff);
for (let i = 0; i<diff; i++) {
buffer[i] = audiobuffer[i+written];
}
window.setTimeout(function(){
PlayMozilla(context, buffer)
}, 500);
}
window.setTimeout(function() {
play(context, audiobuffer);
}, 0);
});
}
}

let context = null;
let player = null;

/**
* Play an audio buffer.
Expand All @@ -60,27 +32,23 @@ let player = null;
export function PlayBuffer(audiobuffer) {
if (null === context) {
((window) => {
['', 'webkit'].some((prefix) => {
context = ['', 'webkit'].reduce((pre, prefix) => {
if (pre) { return pre;}
const implementation = prefix + 'AudioContext';
if (typeof window[implementation] !== "undefined") {
context = new window[implementation]();
player = Play;
return;
}
if (ENABLE_DEPRECATED_MOZILLA_AUDIO) {
if (typeof Audio !== "undefined") {
context = new Audio();
context.mozSetup(1, 22050);
player = PlayMozilla;
}
return new window[implementation]();
}
});
return null;
}, null);
})(window);
}

if (null === player) { throw new Error('No player available!'); }
if (null === context) {

throw new Error('No player available!');
}

return player(context, audiobuffer);
return Play(context, audiobuffer);
}

/**
Expand Down

0 comments on commit 794b150

Please sign in to comment.