Skip to content

Commit

Permalink
Fix: don't use a blob URL for unknown MIME types (#3471)
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh authored Jan 8, 2024
1 parent c10cad2 commit 8b1f8bb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,15 @@ class Player<T extends GeneralEventTypes> extends EventEmitter<T> {
}
}

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
}

Expand Down
4 changes: 4 additions & 0 deletions src/webaudio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,10 @@ class WebAudioPlayer extends EventEmitter<WebAudioPlayerEvents> {
}
}

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
Expand Down

0 comments on commit 8b1f8bb

Please sign in to comment.