不能让HTML5音频标签在移动浏览器工作 [英] Can't make HTML5 Audio Tag to work on mobile browsers

查看:95
本文介绍了不能让HTML5音频标签在移动浏览器工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用HTML5的标签的web应用程序,由于某种原因,同时它适用于Windows和Mac电脑精不iOS和Android上工作。
这里是我的code的相关片段:

I have a web app that uses the HTML5 tag and for some reason while it works fine on Windows and Mac PCs it doesn't work on iOS and Android. Here's a relevant snippet of my code:

使用Javascript:

Javascript:

            var audioElement = document.querySelector('#audioplayer');
            var source = document.querySelector('#mp3');
            source.src = tokObject._url;
            audioElement.load();
            audioElement.play();

HTML

            <center><audio id="audioplayer" style="width:480px;">
            <source id="mp3" src="random-placeholder" type="audio/mp3" />
            </audio>
            </center>

欢呼和感谢!

推荐答案

您通常不能自动播放移动设备上的音频或视频文件,这往往是由操作系统,如Android和iOS的限制,从巨大的下载网站停止媒体文件和自动播放它们。

You normally can't autoplay audio or video files on mobile devices, this is often a restriction by the OSes such as Android and iOS to stop sites from downloading huge media files and autoplaying them.

如果这样code是从点击​​或触摸处理程序内调用,它可能会工作,但目前尚未你正在做的方式。

If such code is called from within a click or touch handler, it will probably work, but not the way you are currently doing it.

此外,&LT;中心方式&gt; 元素已经去precated,你不应该再使用它

Also, the <center> element has been deprecated and you shouldn't use it anymore.

这篇关于不能让HTML5音频标签在移动浏览器工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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