diff --git a/src/player.ts b/src/player.ts index cfbc1c43d..f9f1228d9 100644 --- a/src/player.ts +++ b/src/player.ts @@ -63,11 +63,15 @@ class Player extends EventEmitter { } } + private canPlayType(type: string): boolean { + return this.media.canPlayType(type) !== '' + } + protected setSrc(url: string, blob?: Blob) { const src = this.getSrc() if (src === url) return this.revokeSrc() - const newSrc = blob instanceof Blob ? URL.createObjectURL(blob) : url + const newSrc = blob instanceof Blob && this.canPlayType(blob.type) ? URL.createObjectURL(blob) : url this.media.src = newSrc } diff --git a/src/webaudio.ts b/src/webaudio.ts index b18bc8acd..eae98ff9e 100644 --- a/src/webaudio.ts +++ b/src/webaudio.ts @@ -188,6 +188,10 @@ class WebAudioPlayer extends EventEmitter { } } + public canPlayType(mimeType: string) { + return /^(audio|video)\//.test(mimeType) + } + /** Get the GainNode used to play the audio. Can be used to attach filters. */ public getGainNode(): GainNode { return this.gainNode