我该如何解决:该应用可以在后台播放YouTube视频 [英] How do I fix this: app enables background playing of YouTube videos
问题描述
我制作了一个可播放YouTube视频的phonegap应用. Google已将其从Play商店中撤出,因为该应用可以在后台播放YouTube视频."
I made a phonegap app that plays YouTube videos. Google has pulled it from the play store because the "app enables background playing of YouTube videos."
我不知道那是什么意思.
I have no idea what that means.
有人可以帮助我解决此问题,以使视频不会在后台播放吗?
Can anybody help me fix this so that the videos don't play in the background?
谢谢.
推荐答案
我认为Google意味着您必须在应用处于后台模式(例如触摸设备主屏幕按钮)时暂停youtube视频
I think that Google means that u have to pause the youtube video when the app is in background mode (e.g. touching the device home button)
我解决它的方式,所以注册暂停"事件(当应用程序进入后台时调用)
the way I solve it so register the 'pause' event (called when the app goes to background)
document.addEventListener("pause", pause, false);
function pause (argument) {
if (typeof document.app.player != "undefined") {
document.app.player.pauseVideo();
}
}
播放youtube时,我会保留播放器的引用:
when a youtube is played I keep the reference of the player:
patt=/\/www\.youtube\.com\/watch\?v=(.*)/;
m = patt.exec(url);
if (m.length == 2) {
url = "http://www.youtube.com/embed/"+ m[1] //+ "?autoplay=1"
console.log("url = "+url)
}
YTid = 'yt_'+m[1];
$("#MediaPPSVideo").html(
"<div id='"+YTid+"' width=\"100%\"></div>"
).after(function() {
document.app.player = new YT.Player(YTid, {
height: $(window).height()/2,
width: $(window).width()*0.95,
videoId: m[1],
events: {
'onReady': onPlayerReady,
}
});
})
这很丑但是可以正常工作
this ugly but working
这篇关于我该如何解决:该应用可以在后台播放YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!