真实的国产乱ⅩXXX66竹夫人,五月香六月婷婷激情综合,亚洲日本VA一区二区三区,亚洲精品一区二区三区麻豆

成都創(chuàng)新互聯(lián)網(wǎng)站制作重慶分公司

Android如何讓W(xué)ebView中的HTML5頁(yè)面實(shí)現(xiàn)視頻全屏播放

前言

創(chuàng)新互聯(lián)建站堅(jiān)持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站建設(shè)、成都網(wǎng)站設(shè)計(jì)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機(jī)端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿(mǎn)足客戶(hù)于互聯(lián)網(wǎng)時(shí)代的濠江網(wǎng)站設(shè)計(jì)、移動(dòng)媒體設(shè)計(jì)的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!

本文主要是將最近工作中遇到的一個(gè)問(wèn)題進(jìn)行總結(jié)分享,主要介紹的是如何讓W(xué)ebView中H5頁(yè)面全屏播放視頻。關(guān)于這個(gè)問(wèn)題,做一下簡(jiǎn)單分析,希望對(duì)大家有所幫助,下面話(huà)不多說(shuō)了,來(lái)看看詳細(xì)的介紹吧。

效果圖

Android如何讓W(xué)ebView中的HTML5頁(yè)面實(shí)現(xiàn)視頻全屏播放
運(yùn)行效果

其實(shí)很簡(jiǎn)單,就是配置問(wèn)題。關(guān)鍵地方配好了,基本沒(méi)什么問(wèn)題了。

  • 硬件加速
  • 設(shè)置WebView

在清單需要配置的AndroidManifest.xml


 
 
  
  
 
 

這里需要注意的是:啟動(dòng)硬件加速可以 在application 啟動(dòng)這個(gè)硬件加速,也可以在對(duì)應(yīng)的activity啟動(dòng)

android:hardwareAccelerated="true"

還有這個(gè)

configChanges="orientation|screenSize|keyboardHidden"

必須是

orientation|screenSize|keyboardHidden

當(dāng)然記得加上網(wǎng)絡(luò)權(quán)限

下面給出全部源碼

activity_webview.xml

<?xml version="1.0" encoding="utf-8"?>


 

WebViewActivity源碼

public class WebViewActivity extends AppCompatActivity {
 private FrameLayout mFrameLayout;
 private WebView mWebView;
 private MyWebChromeClient mMyWebChromeClient;
 private String URL = "http://m.tv.sohu.com/20130704/n380744170.shtml";
 @Override
 protected void onCreate(Bundle savedInstanceState) {
 requestWindowFeature(Window.FEATURE_NO_TITLE);
 super.onCreate(savedInstanceState);
 setContentView(R.layout.activity_webview);
 mFrameLayout = (FrameLayout) findViewById(R.id.mFrameLayout);
 mWebView = (WebView) findViewById(R.id.mWebView);
 initWebView();
 mWebView.loadUrl(URL);
 }
 private void initWebView() {
 WebSettings settings = mWebView.getSettings();
 settings.setJavaScriptEnabled(true);
 settings.setJavaScriptCanOpenWindowsAutomatically(true);
 settings.setPluginState(WebSettings.PluginState.ON);
 settings.setAllowFileAccess(true);
 settings.setLoadWithOverviewMode(true);
 settings.setUseWideViewPort(true);
 settings.setCacheMode(WebSettings.LOAD_NO_CACHE);
 settings.setCacheMode(WebSettings.LOAD_DEFAULT);
 mMyWebChromeClient = new MyWebChromeClient();
 mWebView.setWebChromeClient(mMyWebChromeClient);
 mWebView.setWebViewClient(new WebViewClient() {
  public boolean shouldOverrideUrlLoading(WebView view, String url) {
  view.loadUrl(url);
  return true;
  }

  @Override
  public void onPageFinished(WebView view, String url) {
  super.onPageFinished(view, url);
  }
 });
 }

 private class MyWebChromeClient extends WebChromeClient {
 private View mCustomView;
 private CustomViewCallback mCustomViewCallback;
 @Override
 public void onShowCustomView(View view, CustomViewCallback callback) {
  super.onShowCustomView(view, callback);
  if (mCustomView != null) {
  callback.onCustomViewHidden();
  return;
  }
  mCustomView = view;
  mFrameLayout.addView(mCustomView);
  mCustomViewCallback = callback;
  mWebView.setVisibility(View.GONE);
  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
 }

 public void onHideCustomView() {
  mWebView.setVisibility(View.VISIBLE);
  if (mCustomView == null) {
  return;
  }
  mCustomView.setVisibility(View.GONE);
  mFrameLayout.removeView(mCustomView);
  mCustomViewCallback.onCustomViewHidden();
  mCustomView = null;
  setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
  super.onHideCustomView();
 }
 }
 @Override
 public void onConfigurationChanged(Configuration config) {
 super.onConfigurationChanged(config);
 switch (config.orientation) {
  case Configuration.ORIENTATION_LANDSCAPE:
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  break;
  case Configuration.ORIENTATION_PORTRAIT:
  getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
  getWindow().addFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
  break;
 }
 }
 @Override
 public void onPause() {
 super.onPause();
 mWebView.onPause();
 }

 @Override
 public void onResume() {
 super.onResume();
 mWebView.onResume();
 }

 @Override
 public void onBackPressed() {
 if (mWebView.canGoBack()) {
  mWebView.goBack();
  return;
 }
 super.onBackPressed();
 }

 @Override
 public void onDestroy() {
 super.onDestroy();
 mWebView.destroy();
 }
}

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)各位Android開(kāi)發(fā)者們能帶來(lái)一定的幫助,如果有疑問(wèn)大家可以留言交流,謝謝大家對(duì)創(chuàng)新互聯(lián)的支持。


當(dāng)前名稱(chēng):Android如何讓W(xué)ebView中的HTML5頁(yè)面實(shí)現(xiàn)視頻全屏播放
文章位置:http://weahome.cn/article/psdghh.html

其他資訊

在線(xiàn)咨詢(xún)

微信咨詢(xún)

電話(huà)咨詢(xún)

028-86922220(工作日)

18980820575(7×24)

提交需求

返回頂部