Skip to content

Commit

Permalink
update ios interrupt
Browse files Browse the repository at this point in the history
  • Loading branch information
BenzLeung committed Jan 22, 2021
1 parent b939559 commit 5a91bdf
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/RecorderControl.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ const AudioContext = window.AudioContext || window.webkitAudioContext || window.
let ctx = null;
let isSupport = true;

if (AudioContext) {
ctx = new AudioContext();
} else {
if (!AudioContext) {
isSupport = false;
console.warn('Web Audio API is Unsupported.');
}
Expand All @@ -32,7 +30,10 @@ export default class RecorderControl {
_curSourceNode = null;

playPcm (samples, sampleRate, onEnded, startPos) {
if (ctx.state === 'interrupted') {
if (!ctx || ctx.state === 'closed') {
ctx = new AudioContext();
}
if (ctx.state === 'interrupted' || ctx.state === 'suspended') {
ctx.resume();
}

Expand Down Expand Up @@ -165,11 +166,11 @@ export default class RecorderControl {
}

static getCtxSampleRate() {
return ctx.sampleRate;
return ctx && ctx.sampleRate || 0;
}

static getCtxTime() {
return ctx.currentTime;
return ctx && ctx.currentTime || 0;
}

static decodeAudioArrayBufferByContext(array) {
Expand Down

0 comments on commit 5a91bdf

Please sign in to comment.