回退到默认的,如果来源是音频标签无效 [英] Fallback to the default if source is invalid in AUDIO tag

查看:230
本文介绍了回退到默认的,如果来源是音频标签无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我有一个基本的音频元素。说我有一个单一的MP3音源。我使用的是Firefox浏览器。浏览器看到音频标签,喜欢,场所作为指挥控制,但不喜欢任何来源,因此它不会加载任何声音,但还是忽略了一个较小的浏览器会显示默认的项目。

So I have a basic audio element. Say I have a single mp3 source. I'm using Firefox. The browser sees the audio tag, likes it, places the controls as directed, but doesn't like any sources, so it doesn't load any audio, but still ignores the default items that a lesser browser would have displayed.

可悲的是我preFER浏览器实际显示该点的默认项(比如一个链接,下载的MP3),而不是比显示非工作音频控制。由于没有AudioElement.stuffThatsNotSRC,我们如何做到这一点?

Sadly I'd prefer the browser actually display the default items at that point (say a link to download the mp3) rather than than display the non-working audio controls. Since there is no AudioElement.stuffThatsNotSRC, how do we do this?

所以,我要做的就是有一个checkSources()将触发的onLoad,看起来在networkState,如果找到了0或3它,然后去一个HTML跨度我身边有音频控制,并与非替换其内部HTML -source的东西,这是音频标签内。

So what I do is have a checkSources() that fires onLoad that looks at the networkState and if it finds the 0 or 3 it then goes to a HTML span I have around the audio control and replaces its inner HTML with the non-source stuff that was inside the audio tag.

有没有更好的方法来做到这一点?

Is there a better way to do this?

推荐答案

使用源标记来定义多种文件类型。

Use the source tag to define multiple file types.

<audio controls="true">
    <source src="demo.mp3" type="audio/mp3"> 
    <source src="demo.ogg" type="audio/ogg"> 
    <source src="demo.aac" type="audio/mp4"> 
    <!-- If no support at all. -->
    HTML5 audio not supported 
</audio>

http://msdn.microsoft.com /en-us/library/gg589524(v=vs.85).aspx

这篇关于回退到默认的,如果来源是音频标签无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆