如何从React中的Blob对象播放音频? [英] How to play audio from blob object in React?

查看:91
本文介绍了如何从React中的Blob对象播放音频?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用ReactJS创建一个录音机应用程序.我使用npm软件包

解决方案

您可以尝试使用此代码: https://www.npmjs.com/package/react-player

从文档中

  class App扩展了组件{使成为 () {返回< ReactPlayer url ='<-您的BLOB->'播放/>}} 

可以在此处找到更详细的示例-尚未测试,因为我必须将您的项目连接起来.但是看看您的blob mime类型,它是该库支持的webm.

I'm trying to create an audio recorder app using ReactJS. I used the npm package react-mic to serve the purpose. But the recordings were saved as a blob object.

How to play the recorded file (blob object) in the browser? And how to upload this as an audio file to online storage? (like firebase)

解决方案

You could try using this: https://www.npmjs.com/package/react-player

From the docs:

class App extends Component {
  render () {
    return <ReactPlayer url='<--YOUR BLOB -->' playing />
  }
}

And a more elaborate example can be found here - not tested though, as I would have to wire your project up. But looking at your blob mime-type, it's webm, which this library supports.

这篇关于如何从React中的Blob对象播放音频?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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