android - 安卓webview無法全屏播放iframe騰訊、優酷視頻
問題描述
先上代碼吧
public class MainActivity extends AppCompatActivity { static final String iframeStr = '<iframe frameborder='0' src='http://v.qq.com/iframe/player.html?vid=v0151eygqka&tiny=0&auto=0' allowfullscreen></iframe>'; private WebView videoWebView; private FrameLayout fullScreenView; private View customView; @Override protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);fullScreenView = (FrameLayout) findViewById(R.id.video_fullscreen);videoWebView = (WebView) findViewById(R.id.webView);WebSettings settings = videoWebView.getSettings();settings.setJavaScriptEnabled(true);settings.setJavaScriptCanOpenWindowsAutomatically(true);settings.setDatabaseEnabled(true);settings.setAppCacheEnabled(true);settings.setCacheMode(WebSettings.LOAD_DEFAULT);settings.setPluginState(WebSettings.PluginState.ON);settings.setAllowFileAccess(true);settings.setLoadWithOverviewMode(true);settings.setDomStorageEnabled(true);settings.setUseWideViewPort(true);videoWebView.setWebChromeClient(new MyWebChromeClient());videoWebView.setWebViewClient(new MyWebViewClient());videoWebView.loadData(iframeStr,'text/html','utf-8'); } class MyWebViewClient extends WebViewClient{@Overridepublic boolean shouldOverrideUrlLoading(WebView view, String url) { return false;} } class MyWebChromeClient extends WebChromeClient{private CustomViewCallback customViewCallback;@Overridepublic void onShowCustomView(View view, CustomViewCallback callback) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); videoWebView.setVisibility(View.INVISIBLE); // 如果一個視圖已經存在,那么立刻終止并新建一個 if (customView != null) {callback.onCustomViewHidden();return; } fullScreenView.addView(view); customView = view; customViewCallback = callback; fullScreenView.setVisibility(View.VISIBLE);}@Overridepublic void onHideCustomView() { if (customView == null)// 不是全屏播放狀態return; setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT); customView.setVisibility(View.GONE); fullScreenView.removeView(customView); customView = null; fullScreenView.setVisibility(View.GONE); customViewCallback.onCustomViewHidden(); videoWebView.setVisibility(View.VISIBLE);} } @Override protected void onResume() {super.onResume();if (getRequestedOrientation() != ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE) { setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);}videoWebView.resumeTimers(); } @Override protected void onPause() {super.onPause();videoWebView.pauseTimers(); } @Override protected void onDestroy() {super.onDestroy();videoWebView.destroy(); }}
就是用一個webview顯示一個視頻(不是一個視頻網頁,只是一個視頻),然后我使用的是iframe的鏈接(就是騰訊視頻分享那里的通用代碼)。我參照了網上很多關于全屏顯示的問題,基本代碼都是這樣,但是并沒有用,感覺沒有調用到那兩個函數。還有是不是跟鏈接里限定了大小有關系。這樣的話,需要修改什么才能全屏呢?
問題解答
回答1:樓主有找到解決方法嗎
相關文章:
1. macos - 無法source activate python272. 小白學python的問題 關于%d和%s的區別3. mysql - 在不允許改動數據表的情況下,如何優化以varchar格式存儲的時間的比較?4. 運行python程序時出現“應用程序發生異常”的內存錯誤?5. android - 如何實現QQ pad 點擊右側輸入框,只頂右側的布局,左側布局不動6. css3:flex排版問題7. css - 關于background-position百分比的問題?8. 問題Unknown column ’’ in ’where clause’9. html5 - chrome上的video控制條不同10. github - 求助大神啊,win10 git clone error,折騰了幾天都不行,以前原本好好的,突然就這樣了

網公網安備