我们有一个cordova android应用程序。我们要为自定义html视频播放器启动全屏显示(方向上的视频标签已更改为“ landscape-primary”)。
我们已使用cordova-plugin-screen-orientation检测screen.orientation.type并在下面的代码中添加了
document.addEventListener("deviceready",function()
{
window.addEventListener("orientationchange", function()
{
console.log(screen.orientation.type); // e.g. portrait
if(screen.orientation.type == 'landscape-primary')
{
console.log(video);
video.webkitRequestFullscreen;
$scope.launchFullscreen();
}
if(screen.orientation.type == 'portrait-primary')
{
$scope.exitFullscreen();
}
//alert(screen.orientation.type);
});
})
并在launchFullscreen下面使用
$scope.launchFullscreen = function () {
if(video.requestFullscreen) {
parentdiv.requestFullscreen();
} else if(video.mozRequestFullScreen) {
parentdiv.mozRequestFullScreen();
} else if(video.webkitRequestFullscreen) {
fullScreenButton.style.display = "none";
exitfullScreenButton.style.display = "inline-block";
parentdiv.style.height = "100%";
parentdiv.webkitRequestFullscreen();
videoPlayer.addEventListener('touchstart', function(event) {
if(document.getElementById("custom-video-controls").style.display == "inline-block")
{
angular.element(document.getElementById("custom-video-controls").style.display="none");
}
else
{
angular.element(document.getElementById("custom-video-controls").style.display="inline-block");
}
}, false);
}
};
但是我们收到错误消息,因为“无法在'Element'上执行'requestFullscreen':API只能通过用户手势启动。”
也尝试以编程方式触发touchstart事件,但弹出错误。 让我们知道我们如何实现这些目标?