播放存储为 blob 的 MP3 文件

编程入门 行业动态 更新时间:2024-10-25 10:24:28
本文介绍了播放存储为 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).

我尝试过:

  • 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 文件

    本文发布于:2023-11-23 15:42:33,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1621997.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:文件   blob

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!