HTML5 音频标签在 Android 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12142084/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 09:52:40  来源:igfitidea点击:

HTML5 audio tag is not working in Android

androidcordova

提问by karthick

I have created a sample phone gap application for android ics . And the index.html has an audio tag like this.

我已经为 android ics 创建了一个示例电话间隙应用程序。index.html 有一个这样的音频标签。

<audio id="player1" controls preload><source src="media/track1.mp3" type="audio/mp3" /></audio>

I am not able to play the audio at all. I saw the stack overflow posts everywhere it's mentioned that the audio tag will work fine after froyo release. But, i am testing it in gingerbeard and in ICS and it's not working anywwhere.

我根本无法播放音频。我看到到处都是堆栈溢出的帖子,提到音频标签在 froyo 发布后可以正常工作。但是,我正在gingerbeard 和ICS 中测试它,但它在任何地方都不起作用。

采纳答案by Andrew Trice

HTML5 Audio support is not consistent across different devices/OSes due to codec licensing issues and OS implementation/support. If you are just playing MP3 files, you can reliably handle those by using PhoneGap's Mediaclass, which will provide consistent and reliable audio programming on all platforms.

由于编解码器许可问题和操作系统实施/支持,HTML5 音频支持在不同设备/操作系统之间不一致。如果您只是播放 MP3 文件,您可以使用 PhoneGap 的Media类可靠地处理这些文件,该类将在所有平台上提供一致且可靠的音频编程。

If you want the ability to preload audio and have more advanced scenarios like polyphony or layering (like video game effects), you can use the LowLatencyAudioPhoneGap native plugin.

如果您希望能够预加载音频并拥有更高级的场景,如和弦或分层(如视频游戏效果),您可以使用LowLatencyAudioPhoneGap 原生插件。

回答by Andrew Trice

Super late to this but type="audio/mp3"is wrong - it should be type="audio/mpeg"

超级迟到但type="audio/mp3"错了 - 应该是type="audio/mpeg"

With that being said, Android is still terrible at playing HTML5 audio - you're required to reset the srcattribute before playing sounds (or they'll only play once) and it's not tolerant of multiple file types (required for other browsers). Nor do they support the WebAudioAPI

话虽如此,Android 在播放 HTML5 音频方面仍然很糟糕 - 您需要src在播放声音之前重置该属性(或者它们只会播放一次)并且它不能容忍多种文件类型(其他浏览器需要)。他们也不支持 WebAudioAPI

回答by Moises

Wish I answered with some findings earlier.

希望我早点回答一些发现。

The following seem to work for me. Android seems very anal about which source comes first. So I had the "mp3" source as on the third line and moved it up so it works for sure now. The controls=controls is because without it IE 11 did not seem to work on regular PC. My thoughts on the matter. Had to make the copy in ogg for Firefox to recognize it.

以下似乎对我有用。Android 似乎对哪个源首先出现非常敏感。所以我有第三行的“mp3”源并将其向上移动,因此它现在可以正常工作。control=controls 是因为没有它 IE 11 似乎无法在普通 PC 上运行。我对此事的看法。必须在 ogg 中制作副本以便 Firefox 识别它。

<audio controls="controls">
<source src="/somefile.mp3" type="audio/mpeg"></source>
<source src="/somefile.ogg" type="audio/ogg">   
Your browser does not support the audio element.
</source></audio>

回答by roncsak

According to html5test.comAndroid 4 only supports mp3 in the audio tag.

根据html5test.comAndroid 4 仅支持音频标签中的 mp3。

回答by Simon MacDonald

It looks like the path to your mp3 is incorrect. If this file is on the SD card the path would be something like:

您的 mp3 路径似乎不正确。如果此文件在 SD 卡上,路径将类似于:

file:///sdcard/media/track1.mp3