2017-07-14 131 views
7

我的全屏視頻web視圖幾乎總是在打開後立即關閉,有時會起作用。幾乎每次我點擊YouTube視頻上的全屏按鈕時,您都可以看到屏幕全屏閃爍並回到原始畫面。這可能是什麼原因?爲什麼我的全屏webview在打開後不斷關閉?

該webview顯示在tablayout/viewpager設置與其他片段。

我已經使用這個代碼顯示視頻: https://github.com/cprcrack/VideoEnabledWebView

現在我用這一個https://github.com/GoogleChrome/chromium-webview-samples/blob/master/fullscreen-video-sample/app/src/main/java/fullscreenvideosample/android/chrome/google/com/fullscreenvideosample/MainActivity.java

他們產生相同的行爲。

日誌時全屏失敗開放後恢復到正常的權利:當全屏成功

07-14 17:41:06.694 D/[email protected][GroupActivity]: ViewPostImeInputStage processPointer 0 
07-14 17:41:06.786 D/[email protected][GroupActivity]: ViewPostImeInputStage processPointer 1 
07-14 17:41:06.803 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392 
07-14 17:41:07.512 D/[email protected][GroupActivity]: ViewPostImeInputStage processPointer 0 
07-14 17:41:07.592 D/[email protected][GroupActivity]: ViewPostImeInputStage processPointer 1 
07-14 17:41:07.615 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392 
07-14 17:41:07.709 V/InputMethodManager: Starting input: [email protected] nm : com.linkhubapp ic=null 
07-14 17:41:07.709 I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus 
07-14 17:41:07.713 D/InputTransport: Input channel constructed: fd=152 
07-14 17:41:07.714 D/InputTransport: Input channel destroyed: fd=159 
07-14 17:41:07.714 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392 
07-14 17:41:07.751 D/[email protected][GroupActivity]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x1 surface={isValid=true -1176543232} surfaceGenerationChanged=false 
07-14 17:41:07.911 D/[email protected][GroupActivity]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x7 surface={isValid=true -1273339904} surfaceGenerationChanged=true 
07-14 17:41:07.921 D/mali_winsys: EGLint new_window_surface(egl_winsys_display*, void*, EGLSurface, EGLConfig, egl_winsys_surface**, egl_color_buffer_format*, EGLBoolean) returns 0x3000, [1440x2560]-format:1 
07-14 17:41:07.922 D/[email protected][GroupActivity]: mHardwareRenderer.updateSurface() mSurface={isValid=true -1273339904} 
07-14 17:41:07.974 D/SurfaceView: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,875][1440,1685] result=0x7 surface={Surface(name=null)/@0xb9ffb70 isValid=true -1178691584} 
07-14 17:41:08.047 D/SurfaceView: Relayout returned: oldFrame=[0,875][1440,1685] newFrame=[0,875][1440,1685] result=0x5 surface={Surface(name=null)/@0xb9ffb70 isValid=false 0} 
07-14 17:41:08.095 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392 
07-14 17:41:08.163 D/[email protected][GroupActivity]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x1 surface={isValid=true -1273339904} surfaceGenerationChanged=false 
07-14 17:41:08.232 V/InputMethodManager: Starting input: [email protected] nm : com.linkhubapp ic=null 
07-14 17:41:08.232 I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus 
07-14 17:41:08.233 D/InputTransport: Input channel constructed: fd=173 
07-14 17:41:08.233 D/InputTransport: Input channel destroyed: fd=152 

日誌:

07-14 17:41:27.987 D/[email protected][GroupActivity]: ViewPostImeInputStage processPointer 0 
07-14 17:41:28.023 D/[email protected][GroupActivity]: ViewPostImeInputStage processPointer 1 
07-14 17:41:28.048 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392 
07-14 17:41:28.496 D/[email protected][GroupActivity]: ViewPostImeInputStage processPointer 0 
07-14 17:41:28.571 D/[email protected][GroupActivity]: ViewPostImeInputStage processPointer 1 
07-14 17:41:28.616 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392 
07-14 17:41:28.719 V/InputMethodManager: Starting input: [email protected] nm : com.linkhubapp ic=null 
07-14 17:41:28.719 I/InputMethodManager: [IMM] startInputInner - mService.startInputOrWindowGainedFocus 
07-14 17:41:28.725 D/InputTransport: Input channel constructed: fd=155 
07-14 17:41:28.725 D/InputTransport: Input channel destroyed: fd=173 
07-14 17:41:28.725 D/InputMethodManager: HSI from window - flag : 0 Pid : 6392 
07-14 17:41:28.766 D/[email protected][GroupActivity]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x1 surface={isValid=true -1273339904} surfaceGenerationChanged=false 
07-14 17:41:28.956 D/[email protected][GroupActivity]: Relayout returned: oldFrame=[0,0][1440,2560] newFrame=[0,0][1440,2560] result=0x1 surface={isValid=true -1273339904} surfaceGenerationChanged=false 
07-14 17:41:29.036 D/SurfaceView: Relayout returned: oldFrame=[0,0][0,0] newFrame=[0,875][1440,1685] result=0x7 surface={Surface(name=null)/@0xc360d2 isValid=true -1273337856} 
07-14 17:41:29.089 D/SurfaceView: Relayout returned: oldFrame=[0,875][1440,1685] newFrame=[0,875][1440,1685] result=0x1 surface={Surface(name=null)/@0xc360d2 isValid=true -1311279104} 

編輯: 這似乎是在YouTube上只發生。測試Vimeo與YouTube。 Vimeo每次打開。

+0

它發生在特定設備上還是嘗試過其他設備? –

+0

現在它只在三星Galaxy S6上測試過。我試着在明天做一些測試。 – CantThinkOfAnything

+0

相關:https://stackoverflow.com/questions/15768837/playing-html5-video-on-fullscreen-in-android-webview –

回答

1

我能想到的最好的事情就是你的設備沒有內存。所以我有一些建議給你。

  • 首先,當您的設備上的所有內存都空閒並檢查結果時,請在設備上進行測試。

  • 其次,你提到你有一個Galaxy S6和一個Galaxy S3,在兩個設備上運行你的應用程序。

  • 此外,如果您可以在另一個Galaxy S6上測試您的應用程序並查看它是否重複,則它非常有幫助。

收集這些信息後,您可能能夠找到解決問題的方法。

你可以測試的另一件事是使用android:hardwareAccelerated="true"並檢查它是否有幫助。

+0

在S3,S6和S7上的行爲是相同的。 「android:hardwareAccelerated =」true「」我已經設置好了。 – CantThinkOfAnything

1

這不直接回答你的問題,但提供了一個替代方案。

根據您的使用情況,將視頻顯示在YouTube應用程序中而不是在WebView內可能是可以接受的。 大多數Android設備(如果不是全部)都安裝了YouTube應用程序。

public void playVideo(String key){ 

    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + key)); 

    // Check if the youtube app exists on the device 
    if (intent.resolveActivity(getPackageManager()) == null) { 
     // If the youtube app doesn't exist, then use the browser 
     intent = new Intent(Intent.ACTION_VIEW, 
       Uri.parse("http://www.youtube.com/watch?v=" + key)); 
    } else { 
     startActivity(intent); 
    } 
} 

它將要求用戶點擊「返回」以後返回到您的應用程序。 但它可能會給用戶帶來更好的視頻體驗。

+0

是的,我知道我可以通過YouTube的應用程序打開它,但它不符合這個項目的要求。無論如何thnx – CantThinkOfAnything

1

在我們與@CantThinkOfAnything討論過程中,我們發現了確切的問題,並提出瞭解決方案。看起來這是三星手機的內部問題。他們有自己的WebView實現,它與Chrome WebView的某些細節和方法有所不同。努力克服與三星設備的網頁視圖問題之前(話說克服 - 我的意思是用另一種方法,而不是web視圖)嘗試:什麼樣的WebView實現您正在使用開發

  • 更新您的Web視圖
  • 檢查選項 - > WebView的實施在這裏,你可以切換它

在這種情況下,我們只有在播放YouTube視頻時遇到問題。因此,只要使用YouTube SDK之前,你可以嘗試建立自己的球員:

<iframe width="300" height=".." src="http://www.youtube.com/embed/M68lNfqmTNk" frameborder="0" allowfullscreen></iframe> 

您將需要加載這個作爲一個獨立的HTML到您的網頁流量。這是一種骯髒的方法,並有很多缺點。可能你不應該用這個。所以我們結束了使用Youtube SDK的解決方案,這比iframe好得多。 @CantThinkOfAnything - 請糾正我,如果我錯過了什麼。

P.S. - 在其他情況下,三星webview適合我們。

+0

你走了。謝謝! :d – CantThinkOfAnything