简体   繁体   English

流音频在Android上不起作用

[英]Streaming Audio Not Working on Android

I have a simple web page that is using the HTML 5 audio tag for streaming. 我有一个使用HTML 5音频标签进行流式传输的简单网页。 I've set up an IIS7 rewrite rule so that browsers can't directly download the MP3 file, but it can still be streamed via the audio control. 我已经设置了IIS7重写规则,以使浏览器无法直接下载MP3文件,但仍可以通过音频控件对其进行流传输。 This works fine on my desktop (Chrome 37.0.2062.124 m) but not on my Android device (Samsung Galaxy S5). 这在我的台式机(Chrome 37.0.2062.124 m)上运行良好,但在我的Android设备(三星Galaxy S5)上却无法正常运行。 I can't download the file on Android but I can't stream it either. 我无法在Android上下载文件,但也无法流式传输。 When I disable the rewrite rule, the streaming works fine on both devices but of course the file can be downloaded directly as well. 当我禁用重写规则时,流在两台设备上都可以正常工作,但是当然也可以直接下载文件。

Here is my page: 这是我的页面:

    <div>
        <h3>
            Audio
        </h3>

        <audio controls="controls" preload="auto">
            <source src="audio.mp3" type="audio/mpeg">
        </audio>
    </div>

Here is my web.config: 这是我的web.config:

    <rewrite>
        <rules>
            <rule name="Prevent MP3 Hotlinking" enabled="true">
                <match url=".*\.(mp3)$" />
                <conditions>
                    <add input="{HTTP_REFERER}" pattern="^$" negate="true" />
                    <add input="{HTTP_REFERER}" pattern="http://www.example.com/.*" negate="true" />
                </conditions>
                <action type="Rewrite" url="http://www.example.com" />
            </rule>
        </rules>
    </rewrite>

Any ideas? 有任何想法吗?

Thanks! 谢谢!

EDIT: I've set up my phone to use my PC as a proxy so I can use Fiddler2 to monitor the traffic. 编辑:我已经设置好手机以将PC用作代理,以便可以使用Fiddler2监视流量。 Some strange things are happening. 一些奇怪的事情正在发生。

From my PC (which works), the browser initates a GET of the MP3 file and correctly receives an HTTP 206 response. 从我的PC(正常工作),浏览器启动MP3文件的GET,并正确接收HTTP 206响应。 From my phone (which doesn't work), it first issues a GET to the mp3 file, receives a 206 response, but then immediately initiates another GET of the mp3 file without an HTTP_REFERER, which of course causes it to fail due to the URL rewrite. 从我的手机(不起作用)起,它首先向mp3文件发出GET,收到206响应,然后立即启动没有HTTP_REFERER的mp3文件的另一个GET,这当然会导致由于网址重写。 I'm not sure what else I can do, is this simply a problem with the Chrome browser on my phone? 我不确定还能做什么,这仅仅是手机上的Chrome浏览器出现问题吗?

Is your server doing any redirects? 您的服务器是否进行任何重定向? If so, are you following those redirects in the Android client? 如果是这样,您是否在Android客户端中遵循这些重定向? If not, that may be your issue. 如果没有,那可能是您的问题。

I may have figured this out. 我可能已经知道了。 Try adding the following to your conditions: 尝试将以下内容添加到您的条件中:

<add input="{HTTP_USER_AGENT}" pattern="iPhone" negate="true" /> . <add input="{HTTP_USER_AGENT}" pattern="iPhone" negate="true" />

Change the iPhone user agent to whatever is appropriate for your Galaxy S5. 将iPhone用户代理更改为适合您的Galaxy S5的任何内容。 This worked for me, although I'm not doing a redirect, but a custom response, such as "file not found." 这对我有用,尽管我没有进行重定向,但是有一个自定义响应,例如“找不到文件”。 I'm also not using an empty referrer pattern as you are. 我也没有像您一样使用空的引荐来源网址模式。

I found this on the Apple Support site 在Apple支持网站上找到了这个

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

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