HTML5音频不玩多次在安卓4.0.4设备自带浏览器 [英] HTML5 audio not playing multiple times in Android 4.0.4 device Native Browser

查看:152
本文介绍了HTML5音频不玩多次在安卓4.0.4设备自带浏览器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前工作的一个 HTML5 的项目。

I am currently working on an HTML5 project.

目前在播放相同的音频文件多次在同一个页面中的 Android原生浏览器的问题。这个问题是在的Andr​​oid ICS 4.0.4 版本特别注意。在这个版本中的音频将被播放一次,但在再次发起音频将无法播放。同样的事情是在Android的ICS 4.0.3 版本和较新的 4.1.1 版本可以正常使用。

There is an issue on playing same audio file multiple times in the same page in Android native browser. The issue is specifically noticed on Android ICS 4.0.4 version. In this version the audio will be played once, but when initiated again audio will not be played. The same thing is working perfectly in Android ICS 4.0.3 Version and on the newer 4.1.1 version.

测试的设备:
三星Galaxy Tab(安卓4.0.4):播放第一次才不玩
的HTC One(安卓4.0.4):播放第一次才不玩
索尼选项卡(安卓4.0.3):完全没有问题,播放音频多次
HTC感觉(安卓4.0.3):完全没有问题,播放音频多次
三星Nexus手机(安卓4​​.1.1):完全没有问题,播放音频多次

Tested Devices:
Samsung Galaxy Tab (Android 4.0.4): Playing first time only then it doesn't play
HTC One (Android 4.0.4): Playing first time only then it doesn't play
Sony Tab (Android 4.0.3): Perfectly fine, playing audio multiple times
HTC Sensation (Android 4.0.3): Perfectly fine, playing audio multiple times
Samsung Nexus Phone (Android 4.1.1): Perfectly fine, playing audio multiple times

根据互联网上的一些研究,这似乎是一个问题Android版本4.0.4

Based on some research on Internet it seems like an issue with Android version 4.0.4

请帮我找到了一些解决方案,以使其在所有设备正常工作。

Please help me to find some solution to make it work in all devices.

请使用W3学校HTML5的试奏音频链接

推荐答案

我得到了一个有效的解决方案。

I got a working solution..

这个问题是安卓4.0.4浏览器时,音频播放一次(结束),然后在查找时间将不会被重置以起始位置,它会留在目的本身。 因此,通过设置 currentTime的= 0 音频后的结束将其复位到起始位置,这样我们就可以多次播放同一音频,因为我们希望与任何页面刷新。
经测试可以正常使用中的所有设备。

The problem was in Android 4.0.4 browser when audio is played once(ended) then the seek time will not be reset to starting position, it will stay at the end itself. So by setting currentTime = 0 after the audio ended will reset it to starting position and in this way we can play the same audio as many times as we want with out any page refresh.
Tested working perfectly in all devices.

HTML code:

<audio id="movie_audio">
  <source src="my_audio_location/movie_audio.mp3" type='audio/mpeg; codecs="mp3"' />
  <source src="my_audio_location/movie_audio.ogg" type='audio/ogg; codecs="vorbis"' />  
</audio>

JavaScript的code:

var movie_audio = document.getElementById('movie_audio');  
movie_audio.addEventListener('ended', function(){  
  movie_audio.currentTime = 0;  
}

这篇关于HTML5音频不玩多次在安卓4.0.4设备自带浏览器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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