0

我在 JSP 页面中嵌入了一个小型 swf 播放器,该播放器在 Chrome 和 FF 中运行良好,它也适用于 IE,但仅在第一次访问时,如果我在第一次访问后再次打开音频文件,音频不会播放,除非我按下暂停然后再次播放,要让它再次工作,我必须清除浏览器缓存。

我尝试阻止浏览器缓存(设置 Pragma,Cache-Control ...)但它也不起作用!

4

1 回答 1

1

有两种方法可以解决这个问题:

更改请求 mp3 的代码或更改提供 mp3 文件的服务器的代码。

1-更改请求代码,以便每次请求某些内容时,它看起来像是对缓存的不同请求。这将取决于您的 mp3 播放器。有些玩家允许这样做,有些则不允许。

<param name="url-to-mp3" value="mymp3.mp3?<%=System.currentTimeMillis() %>" />

2-更改服务器代码。前任。在 Servlet 中尝试添加以下标头以让浏览器知道您不希望缓存 mp3。

        // Set to expire far in the past.
        response.setHeader("Expires", "Sat, 6 May 1995 12:00:00 GMT");
        // Set standard HTTP/1.1 no-cache headers.
        response.setHeader("Cache-Control", "no-store, no-cache, must-revalidate");
        // Set IE extended HTTP/1.1 no-cache headers (use addHeader).
        response.addHeader("Cache-Control", "post-check=0, pre-check=0");
        // Set standard HTTP/1.0 no-cache header.
        response.setHeader("Pragma", "no-cache");

我希望这有帮助。

于 2012-12-03T15:31:05.893 回答