简体   繁体   English

更改音频标签的User-Agent

[英]Change User-Agent of audio tag

I'm working on a HTML5 (no flash) SHOUTCast client. 我正在研究HTML5(无闪存)SHOUTCast客户端。 For some streams, I can set an <audio> tag's src to the MP3 stream and it plays just fine. 对于某些流,我可以将<audio>标签的src设置为MP3流,它播放得很好。

But there is one stream that doesn't work that way. 但是有一个流不能以这种方式工作。 This is because the URL for the stream is the same as the steam's index.html page. 这是因为流的URL与steam的index.html页面相同。 It uses the User-Agent. 它使用User-Agent。 If it's a browser, you get an HTML page; 如果它是一个浏览器,你会得到一个HTML页面; if it's not, you get an MP3 stream. 如果不是,你会得到一个MP3流。

So, how can I edit the request headers sent by the browser when requesting the resource for the <audio> tag? 那么,在请求<audio>标签的资源时,如何编辑浏览器发送的请求标头? I don't want it to send the User-Agent. 我不希望它发送用户代理。

I don't think there's a way to change the User-Agent. 我认为没有办法改变用户代理。 But you can force SHOUTcast to serve the stream by adding a Semicolon ; 但是你可以强制SHOUTcast通过添加一个Semicolon来提供服务; to the end of the URL. 到URL的末尾。 SHOUTcast will then ignore the User-Agent. 然后SHOUTcast将忽略User-Agent。

HTML5 example: HTML5示例:

<!DOCTYPE html>
<html>
  <body>
    <audio controls>
      <source src="http://72.13.82.82:5100/;"/>
      <em>Sorry, your browser doesn't support HTML5 audio.</em>
    </audio>
  </body>
</html>

You can also verify the workaround by visiting http://72.13.82.82:5100/; 您还可以访问http://72.13.82.82:5100/;来验证解决方法http://72.13.82.82:5100/; directly in browser. 直接在浏览器中 You should see some ICY-metadata followed by the mpeg stream. 您应该看到一些ICY元数据,后跟mpeg流。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM