angular - 在“元素”上执行“请求全屏”失败时出现错误:API 只能由用户手势启动
问题描述
我们有一个 cordova android 应用程序。我们想为我们的自定义 html 视频播放器启动全屏(方向上的视频标签更改为“横向主”)。
我们使用了 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);
}
};
但我们收到错误消息“无法在‘元素’上执行‘requestFullscreen’:API 只能由用户手势启动。”
还尝试以编程方式触发 touchstart 事件,但弹出错误。让我们知道如何实现这些?
解决方案
推荐阅读
- android - 如何在 Android 中使用片段创建可滚动模板
- go - 在不同的 goroutine 中替换字符串的值时是否需要互斥锁?
- sql - 如何分隔字符串并插入表格?
- javascript - 有没有办法在对象解构中使用数组内容
- hortonworks-data-platform - 无法在 HDP 3.0.1 中启动 Apache Kylin
- unit-testing - 需要帮助区分模拟和测试驱动程序
- python - Python matplotlib改变x轴的主要单位比例
- angular - Angular scrollPositionRestoration 反向工作
- asp.net - 无法从 ASP.NET MVC 应用程序调用 API?
- python - 尽管模块安装在 python 环境中,VSCode 给出错误“没有名为 sqlalchemy 的模块”