Javascript 退出YouTube全屏后退按钮Cordova关闭应用程序
我在全屏模式下播放YouTube视频,当我按下后退按钮时,它会关闭应用程序,而不是退出全屏模式。我正在将JavaScript与Cordova 6.3.1一起用于Android。这是我的密码:Javascript 退出YouTube全屏后退按钮Cordova关闭应用程序,javascript,android,cordova,Javascript,Android,Cordova,我在全屏模式下播放YouTube视频,当我按下后退按钮时,它会关闭应用程序,而不是退出全屏模式。我正在将JavaScript与Cordova 6.3.1一起用于Android。这是我的密码: document.addEventListener("deviceready", onDeviceReady, false); function onDeviceReady() { document.addEventListener("backbutton", function (e) {
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
document.addEventListener("backbutton", function (e) {
e.preventDefault();
screen.orientation.lock('portrait');
}, false);
}
前面的代码无法按预期工作
提前谢谢。我还没有找到答案,但我现在发布我的发现,希望它能帮助别人 版本:
cordova android
8.1.0
我发现了什么
问题在于,要全屏显示Youtube视频,SystemWebChromeClient
调用CordovaWebViewImpl.showCustomView()
方法。通过这样做,新视图似乎在Cordova能够onDispatchKeyEvent()
并将backbutton
事件发送到JavaScript端之前捕获了backbutton事件
下面是一些日志,为了清晰起见添加了注释
// Video is fullscreen, and then dismissed with the onscreen minimize button
D/CordovaWebViewImpl: showCustomView : showing Custom View + view = android.widget.FrameLayout{a7cc344 V.E...... ......I. 0,0-0,0}
D/CordovaWebViewImpl: hideCustomView : Hiding Custom View : mCustomView = android.widget.FrameLayout{a7cc344 V.E...... .......D 0,0-1080,1704}
// While the video is not displayed fullscreen, the back button event is correctly caught and sent to the JS side
D/CordovaWebViewImpl: onDispatchKeyEvent : isBackButton = true mCustomView = null
// Once again in fullscreen, then click on the back button
D/CordovaWebViewImpl: showCustomView : showing Custom View + view = android.widget.FrameLayout{fa6d336 V.E...... ......I. 0,0-0,0}
// No back button event caught
// A destroy lifecycle event is sent (from the video FrameLayout handling?) and handleDestroy() is called
D/CordovaWebViewImpl: handleDestroy : load about:blank
D/CordovaWebViewImpl: >>> loadUrl(about:blank)
W/cr_AwContents: WebView.destroy() called while WebView is still attached to window.
D/CordovaWebViewImpl: hideCustomView : Hiding Custom View : mCustomView = android.widget.FrameLayout{a7cc344 V.E...... .......D 0,0-1080,1704}
我试过的
- 创建
的子类,并覆盖FrameLayout
和onKeyDown()
,在onkeydup()
showCustomerView()中使用它