先上代码吧
public class MainActivity extends AppCompatActivity {
static final String iframeStr = "<iframe frameborder=\"0\" width=\"640\" height=\"498\" 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{
@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的链接(就是腾讯视频分享那里的通用代码)。我参照了网上很多关于全屏显示的问题,基本代码都是这样,但是并没有用,感觉没有调用到那两个函数。还有是不是跟链接里限定了大小有关系。这样的话,需要修改什么才能全屏呢?
Has the poster found a solution