1
触摸红色播放按钮视频不播放,触摸视频播放它的任何地方。iframe - phonegap - 触摸/点击红色播放按钮视频不播放
我在IOS和Android测试使用我的PhoneGap应用程序(虽然我敢肯定,它发生在常规浏览器一样)
这种情况仅触摸即用鼠标单击模拟器无法重现错误。
任何想法如何解决它?
触摸红色播放按钮视频不播放,触摸视频播放它的任何地方。iframe - phonegap - 触摸/点击红色播放按钮视频不播放
我在IOS和Android测试使用我的PhoneGap应用程序(虽然我敢肯定,它发生在常规浏览器一样)
这种情况仅触摸即用鼠标单击模拟器无法重现错误。
任何想法如何解决它?
此代码是一个工作围绕创建的iframe与youtube iframe api和比onPlayerReady其设置单击处理程序上的红色按钮点击
时,不幸的是它会尽快YouTube的改变打破播放视频红色按钮的类,让希望他们届时能解决这个问题。
patt = /www\.youtube\.com\/watch\?.*v=([^&]*)/;
m = patt.exec(url);
if (m != null && m.length == 2) {
url = "http://www.youtube.com/embed/" + m[1] //+ "?autoplay=1"
console.log("url = " + url)
YTid = 'yt_'+m[1];
$("#mediaContentVideo").html(
"<div id='"+YTid+"'></div>"
).after(function() {
player = new YT.Player(YTid, {
height: $(window).height()/2,
width: $(window).width()*0.95,
videoId: m[1],
events: {
'onReady': onPlayerReady,
}
});
})
}
的HTML
<script>
// 2. This code loads the IFrame Player API code asynchronously.
var tag = document.createElement('script');
tag.src = "https://www.youtube.com/iframe_api";
var firstScriptTag = document.getElementsByTagName('script')[0];
firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);
// 3. This function creates an <iframe> (and YouTube player)
// after the API code downloads.
var player;
function onYouTubeIframeAPIReady() {
}
// 4. The API will call this function when the video player is ready.
function onPlayerReady(event) {
console.log("hey Im ready");
$.each($('iframe'),function(i, iframe) {
d=$(iframe).get(0).contentDocument
$(".ytp-large-play-button",d).click(function() {
player.playVideo();
})
});
}
</script>
<div id="mediaContentVideo" >
</div>
红色播放按钮为我工作。是否有关移动环境的限制,视频播放必须由用户活动发起?请参阅https://developers.google.com/youtube/iframe_api_reference#Mobile_considerations – shawnzhu 2014-12-05 03:17:14