HTML5的音频文件无法在Safari加载

HTML5的音频文件无法在Safari加载

本文介绍了HTML5的音频文件无法在Safari加载的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含四个音频文件的网页。这些文件担任HTML5 <音频> 与.mp3文件,应该在Safari播放。 (我已经在Firefox和Chrome的.ogg文件没有问题。)

I've got a webpage that contains four audio files. These files are served as HTML5 <audio> with .mp3 files, which should play in Safari. (I've had no trouble with .ogg files in Firefox and Chrome.)

每次我重装一到三个文件加载正确的,其余的页面,加载失败 - 尽管他们不给一个错误,并且正在载入消息消失;这是因为,如果他们有大小0B的加载。哪些文件工作和不似乎完全随机的。我看到他们每个人的装载和他们每个人不能超过一次。

Each time I reload the page, between one and three of the files load properly, and the rest fail to load -- although they don't give an error, and the 'loading' message disappears; it's as if they're loading with a size of 0B. Which files work and which don't seems completely random: I've seen each of them load and each of them fail more than once.

我怎样才能让所有这些文件加载​​正确?

How can I make all these files load properly?

推荐答案

我是有文件不加载,并此解决方案提出了类似的问题。如此看来,HTML5音频/视频可以摆摊,即仅仅是停止加载。幸运的是,有一个大排档事件将触发时发生这种情况。我所做的就是听此事件,并当/如果它触发,只是试图迫使音频再次装入。

I was having a similar issue with files not loading and came up with this solution. It seems that HTML5 audio/video can "stall", meaning that is just stops loading. Luckily, there's a "stall" event that fires when this happens. What I did was listen for this event and when/if it fires, just try to force the audio to load again.

例如使用jQuery:

Example using jQuery:

    // the event is 'onstalled' - 'stalled' in the jquery case
   $("audio").bind("stalled", function() {
        var audio = this;
        audio.load();

        // Threw in these two lines for good measure.
        audio.play();
        audio.pause();
    });

这篇关于HTML5的音频文件无法在Safari加载的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 13:22