退出 YouTube 全屏后退按钮 Cordova 关闭应用

我在全屏模式下播放 YouTube 视频,当我按下后退按钮时,它会关闭应用程序而不是退出全屏模式。我正在将JavaScript 与 Cordova 6.3.1 for Android 一起使用。这是我的代码:


document.addEventListener("deviceready", onDeviceReady, false);


function onDeviceReady() {

   document.addEventListener("backbutton", function (e) {

     e.preventDefault();

       screen.orientation.lock('portrait');

     }, false);

}

前面的代码没有按预期工作。


提前致谢。


料青山看我应如是
浏览 228回答 1
1回答

Cats萌萌

我还没有找到答案,但到目前为止我正在发布我的发现,希望它可以帮助某人。版本:cordova-android8.1.0我发现了什么问题来自这样一个事实,即要全屏显示 Youtube 视频,SystemWebChromeClient调用CordovaWebViewImpl.showCustomView()方法。通过这样做,新视图似乎在 Cordova 能够onDispatchKeyEvent()将backbutton事件发送到 JavaScript 端之前捕获后退按钮事件。这是一些日志,为了清楚起见,添加了注释// Video is fullscreen, and then dismissed with the onscreen minimize buttonD/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 sideD/CordovaWebViewImpl: onDispatchKeyEvent : isBackButton = true mCustomView = null// Once again in fullscreen, then click on the back buttonD/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 calledD/CordovaWebViewImpl: handleDestroy : load about:blankD/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()和onKeyUp(),将其用于showCustomerView()然后视频不再显示。文档https://developer.android.com/reference/android/widget/FrameLayout
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript