简单地说,我想在 Firefox 中播放一个 blob MP3 文件.
Put simply, I'd like to play a blob MP3 file in Firefox.
我可以访问 blob 本身:blob(用 MIME 类型 audio/mpeg3 切片)及其 URL:blobURL = window.URL.createObjectURL(blob).
I have access to both the blob itself: blob (sliced with mime type audio/mpeg3), and its URL: blobURL = window.URL.createObjectURL(blob).
我尝试过:
HTML5 音频播放器:
an HTML5 audio player: <audio controls="controls"> <source src="[blobURL]" type="audio/mp3"> </audio>
但我在 Firebug 中收到一条警告,告诉我 Firefox 无法读取 audio/mpeg3 类型的文件.
but I get a warning in Firebug telling me that Firefox cannot read files of type audio/mpeg3.
多个音频播放器库(SoundManager、JPlayer 等),但似乎都不允许 blob URL 作为输入.
multiple audio player libraries (SoundManager, JPlayer, etc.), but none seem to allow blob URLs as input.
我做错了吗?或者有人知道可以从 blob 播放 MP3 文件的解决方法或库吗?
Am I doing it wrong? Or does anyone know a workaround or a library that can play MP3 files from blobs?
推荐答案这对我来说似乎很好用,虽然我使用 audio/mpeg 作为 MIME 类型:
This seems to work fine for me, although I'm using audio/mpeg as the MIME Type:
$scope.player = new window.Audio(); var xhr = new XMLHttpRequest(); xhr.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { $scope.player.src = window.URL.createObjectURL(this.response); $scope.player.play(); } }; xhr.open('GET', url); xhr.responseType = 'blob'; xhr.send();更多推荐
播放存储为 blob 的 MP3 文件
发布评论