android 6.0webview视频,android - 安卓webview无法全屏播放iframe腾讯、优酷视频

先上代码吧

public class MainActivity extends AppCompatActivity {

static final String iframeStr = "";

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{

@Override

public boolean shouldOverrideUrlLoading(WebView view, String url) {

return false;

}

}

class MyWebChromeClient extends WebChromeClient{

private CustomViewCallback customViewCallback;

@Override

public 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);

}

@Override

public 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的链接(就是腾讯视频分享那里的通用代码)。我参照了网上很多关于全屏显示的问题,基本代码都是这样,但是并没有用,感觉没有调用到那两个函数。还有是不是跟链接里限定了大小有关系。这样的话,需要修改什么才能全屏呢?

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值