简体   繁体   English

HTML5音频未在Android 2.3.6上运行

[英]HTML5 Audio Not Running on Android 2.3.6

I have developed an Android Audio Application that works perfectly using html5 Audio. 我已经开发了一个可以使用html5 Audio完美运行的Android音频应用程序。 However on some Phones the Audio will simply not play at all. 但是,在某些手机上,音频根本无法播放。

I am using simple HTML5 feature. 我正在使用简单的HTML5功能。

Tried all sort of things, like multiple play() commands, pause() & play, load() etc but nothing happens. 尝试了各种事情,例如多个play()命令,pause()和play,load()等,但没有任何反应。

I have got hold of one such mobile for a day which is running Android 2.3.6 and I am unable to make it work. 我有一天可以使用这样的手机,该手机运行的是Android 2.3.6,但无法正常运行。 Any help would be highly appreciated. 任何帮助将不胜感激。

I have found a solution. 我找到了解决方案。 This is what worked for me: 这对我有用:

sPlay = document.getElementById("audioplayer");
sPlay.src = '';
sPlay.src = "myAudio.mp3";
sPlay.load();
sPlay.addEventListener("load", function() { 
  sPlay.play(); 
}, true);       

I also changed 我也变了

<source src="none" type="audio/mpeg">

to

<source src="none" type="audio/mp3">

My guess is the devices running the old Android version are slow. 我的猜测是运行旧版Android的设备运行缓慢。 When the play() command is issued in a normal manner, the system is still processing the load() command. 以正常方式发出play()命令时,系统仍在处理load()命令。 As the Audio is still not loaded it doesn't get played. 由于仍未加载音频,因此无法播放。 After using an addEventListener for "load" it started working perfectly, as if the problem was not there in the first place :-) 在使用addEventListener进行“加载”后,它开始正常工作,就好像问题一开始就没有出现:-)

Hope this helps others. 希望这对其他人有帮助。

Thanks! 谢谢!

==== UPDATE ======== ====更新========

I have further modified event listener to "canplay" as "load" appears to be working on old devices only: 我将事件侦听器进一步修改为“可以播放”,因为“负载”似乎仅在旧设备上工作:

sPlay.addEventListener("canplay", function() { 

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

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