本文介绍了播放存储为 blob 的 MP3 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

简单地说,我想在 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).

我尝试过:

  1. HTML5 音频播放器:

  1. 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.

多个音频播放器库(SoundManagerJPlayer 等),但似乎都不允许 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 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-26 01:52