音频的iPad不打 [英] audio not playing in iPad

查看:155
本文介绍了音频的iPad不打的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<audio id="test" controls="controls">
    <source src="1.mp3" type="audio/mpeg" />
    <source src="1.ogg" type="audio/ogg" />
</audio>

JS code播放视频的DOM负载

js code to play video as dom loads

document.getElementById('test').load();
document.getElementById('test').play();

在浏览器中工作,但不是在iPad上,我需要什么设置?

working in browsers but not in iPad, what I need to set?

推荐答案

根据苹果的文档,加载和音频/视频内容的播放必须从用户的操作触发的:

According to apple's documentation, loading and playback of audio/video content has to be triggered from a user's action:

在Safari浏览器在iOS(适用于所有设备,包括iPad的),其中用户可
  是蜂窝网络,并且每个数据单元进行充电,preLOAD和
  自动播放被禁用。没有数据加载,直到用户启动它。
  这意味着JavaScript的play()和load()的方法也是不活跃
  直到用户启动播放,除非play()或load()方法
  由用户操作触发。换句话说,用户启动游戏
  按钮的作品,但在onload =播放()事件不会。

In Safari on iOS (for all devices, including iPad), where the user may be on a cellular network and be charged per data unit, preload and autoplay are disabled. No data is loaded until the user initiates it. This means the JavaScript play() and load() methods are also inactive until the user initiates playback, unless the play() or load() method is triggered by user action. In other words, a user-initiated Play button works, but an onLoad="play()" event does not.

本播放电影:&LT;输入类型=按钮值=播放
  的onClick =document.myMovie.play()&GT;

这什么都不做iOS上:&LT;身体的onLoad =document.myMovie.play()&GT;

This does nothing on iOS: <body onLoad="document.myMovie.play()">

从这里摘自:<一href=\"http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html\">http://developer.apple.com/library/safari/#documentation/AudioVideo/Conceptual/Using_HTML5_Audio_Video/Device-SpecificConsiderations/Device-SpecificConsiderations.html

这篇关于音频的iPad不打的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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