播放存储为blob的MP3文件 [英] Play MP3 file stored as blob

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

问题描述



我可以访问blob本身: blob (以mime类型切片, audio / mpeg3 ),其URL: blobURL = window.URL.createObjectURL(blob) 。



我曾尝试过:


  1. 一个HTML5音频播放器:

     < audio controls =controls> 
    < source src =[blobURL]type =audio / mp3>
    < / audio>

    但是我在Firebug中得到一个警告,告诉我Firefox不能读取 audio / mpeg3


  2. 多个音频播放器库( SoundManager JPlayer 等),但似乎没有允许blob网址作为输入。 / p>


我做错了吗?或者,有没有人知道一个解决方法或库可以播放blob MP3文件?

解决方案

这似乎对我来说很好,虽然我使用 audio / mpeg 作为MIME类型:

  $ 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();


Put simply, I'd like to play a blob MP3 file in Firefox.

I have access to both the blob itself: blob (sliced with mime type audio/mpeg3), and its URL: blobURL = window.URL.createObjectURL(blob).

I have tried with:

  1. an HTML5 audio player:

    <audio controls="controls">
        <source src="[blobURL]" type="audio/mp3">
    </audio>
    

    but I get a warning in Firebug telling me that Firefox cannot read files of type audio/mpeg3.

  2. multiple audio player libraries (SoundManager, JPlayer, etc.), but none seem to allow blob URLs as input.

Am I doing it wrong? Or does anyone know a workaround or a library that can play MP3 files from blobs?

解决方案

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文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆