douliang4858 2016-05-19 21:49
浏览 395

加载流音频文件html5音频播放器

I've written a service in golang with two endpoints - one requires the user to authorize in order to access it - the other requires no authorization.

I'm retrieving a stream from a music streaming API on the server and writing it back to the client as a response in both cases.

The content type on the response in both cases seems to be application/octet-stream. I've tried setting the content type to audio/mpeg but it seems to make no difference.

When I try to call load on the html5 audio player I'm using (just the straight up element) after setting the source to the return of my web service call to the response from the service, I get an error - undefined:1 Uncaught (in promise) DOMException: Failed to load because no supported source was found.

Here's how I'm retrieving the stream :

callApi: function() {
$.ajax({
  context: this,
  url: 'http://localhost:3001/secured/ping',
  method: 'GET'
}).then(function(data, textStatus, jqXHR) {
  alert("The request to the secured endpoint was successful");
  this.setState({audioSrc: data});
  this.refs.audio.play();
}, function() {
  alert("You need to download the server seed and start it to call this API");
});

}

The HTML5 audio element looks like -

<div className="logged-in-box auth0-box logged-in">
          <h1 id="logo"><img src="https://cdn.auth0.com/blog/auth0_logo_final_blue_RGB.png" /></h1>
          <audio ref="audio" src={this.state.audioSrc} autoPlay controls></audio>
          <img src={this.state.profile.picture} />
          <h2>Welcome {this.state.profile.nickname}</h2>
          <button onClick={this.callApi} className="btn btn-lg btn-primary">Call API</button>
        </div>

I'm using react as the client side framework for data binding etc... I'm not sure what that error is all about however I have a feeling it has to do with my response coming back as binary which the audio player can't handle.

Any ideas on how to fix this?

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥35 平滑拟合曲线该如何生成
    • ¥100 c语言,请帮蒟蒻写一个题的范例作参考
    • ¥15 名为“Product”的列已属于此 DataTable
    • ¥15 安卓adb backup备份应用数据失败
    • ¥15 eclipse运行项目时遇到的问题
    • ¥15 关于#c##的问题:最近需要用CAT工具Trados进行一些开发
    • ¥15 南大pa1 小游戏没有界面,并且报了如下错误,尝试过换显卡驱动,但是好像不行
    • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
    • ¥50 成都蓉城足球俱乐部小程序抢票
    • ¥15 yolov7训练自己的数据集