亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

退出 YouTube 全屏后退按鈕 Cordova 關閉應用

退出 YouTube 全屏后退按鈕 Cordova 關閉應用

料青山看我應如是 2021-11-12 16:06:17
我在全屏模式下播放 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);}前面的代碼沒有按預期工作。提前致謝。
查看完整描述

1 回答

?
Cats萌萌

TA貢獻1805條經驗 獲得超9個贊

我還沒有找到答案,但到目前為止我正在發布我的發現,希望它可以幫助某人。


版本:cordova-android8.1.0


我發現了什么

問題來自這樣一個事實,即要全屏顯示 Youtube 視頻,SystemWebChromeClient調用CordovaWebViewImpl.showCustomView()方法。通過這樣做,新視圖似乎在 Cordova 能夠onDispatchKeyEvent()將backbutton事件發送到 JavaScript 端之前捕獲后退按鈕事件。


這是一些日志,為了清楚起見,添加了注釋


// 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()和onKeyUp(),將其用于showCustomerView()

然后視頻不再顯示。


文檔

https://developer.android.com/reference/android/widget/FrameLayout


查看完整回答
反對 回復 2021-11-12
  • 1 回答
  • 0 關注
  • 263 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號