iframe视频不会在Android网页视图中进入全屏模式

前端之家收集整理的这篇文章主要介绍了iframe视频不会在Android网页视图中进入全屏模式前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在一个基于网站的 Android应用程序.
iOS应用程序已经存在,我必须尊重一些代码的一致性.

一切都已经完成了,但是我刚刚发现了一个有趣的问题:当使用网页视图(我没有显示页面的任何控件)时,对于具有iframe视频(Youtube,Dailymotion)的页面,它不会全屏即使我按下播放器的按钮.

我已经尝试了很多这里发现的一切,但它只是指应用程序,我知道你需要显示哪些页面.

以下是该应用的webActivity部分的代码

  1. public class WebActivity extends Activity {
  2. String targetURL = "";
  3. String title = "";
  4. WebView wv;
  5.  
  6. @Override
  7. public void onResume() { super.onResume(); CookieSyncManager.getInstance().startSync(); }
  8. @Override
  9. public void onPause() { super.onPause(); CookieSyncManager.getInstance().stopSync(); }
  10.  
  11. /** Called when the activity is first created. */
  12. @SuppressLint("SetJavaScriptEnabled")
  13. @Override
  14. public void onCreate(Bundle savedInstanceState) {
  15. super.onCreate(savedInstanceState);
  16. getWindow().requestFeature(Window.FEATURE_PROGRESS);
  17. //getWindow().requestFeature(Window.FEATURE_NO_TITLE);
  18. CookieSyncManager.createInstance(getApplicationContext());
  19. CookieSyncManager.getInstance().startSync();
  20. CookieManager.getInstance().setAcceptCookie(true);
  21. /**
  22. * TODO: WebView Cookie management.
  23. * Right now,a cookie is hardcoded here into the WebView instead of getting it from the API called by HttpClient when retrieving the JSON.
  24. * Need to make things cleaner.
  25. */
  26. CookieManager.getInstance().setCookie("http://www.blabla.fr/mobile/","gbapi=1; Domain=.www.blabla.fr");
  27. /**
  28. * Get parameters
  29. */
  30. Bundle b = getIntent().getExtras();
  31. if(b != null)
  32. {
  33. targetURL = b.getString("url");
  34. title = b.getString("title");
  35. }
  36.  
  37. setTitle(title);
  38. setContentView(R.layout.activity_webview);
  39.  
  40. wv = (WebView) findViewById(R.id.webview);
  41.  
  42. WebSettings wvSettings = wv.getSettings();
  43.  
  44. // WebView options
  45. wvSettings.setDefaultTextEncodingName("utf-8");
  46. wvSettings.setJavaScriptEnabled(true);
  47. wvSettings.setPluginState(PluginState.ON);
  48. wvSettings.setJavaScriptCanOpenWindowsAutomatically(true);
  49. wvSettings.setBuiltInZoomControls(true);
  50. final Activity activity = this;
  51. wv.setWebChromeClient(new WebChromeClient() {
  52. public void onProgressChanged(WebView view,int progress) {
  53. activity.setProgress(progress * 100);
  54. }
  55. });
  56.  
  57. wv.setWebViewClient(new WebViewClient() {
  58. public void onReceivedError(WebView view,int errorCode,String description,String failingUrl) {
  59. Toast.makeText(activity,"Oh snap! " + description,Toast.LENGTH_SHORT).show();
  60. }
  61. });
  62.  
  63. wv.loadUrl(targetURL);
  64. }
  65. }

感谢任何帮助.

解决方法

您将需要创建一个自定义WebChromeClient来处理两个版本的onShowCustomView(这个回调的新版本在API级别14中引入)以及onHideCustomView.基本上会发生什么,当您尝试播放全屏视频时,您将获得视频视频的一些变化.您需要将其附加到全屏FrameLayout,并将其粘贴到布局层次结构的根目录以覆盖整个屏幕.一旦完成,你需要再次删除它.

这是一个我用来播放视频的版本

  1. private class DerpChromeClient extends WebChromeClient implements MediaPlayer.OnCompletionListener,MediaPlayer.OnErrorListener {
  2. //@Override
  3. public void onShowCustomView(View view,int requestedOrientation,CustomViewCallback callback) {
  4. log.warn("onShowCustomView");
  5. showCustomView(view,callback);
  6. }
  7.  
  8. private View mVideoProgressView;
  9.  
  10. @Override
  11. public void onHideCustomView() {
  12. super.onHideCustomView();
  13.  
  14. activity.removeFullscreenView();
  15. webView.setVisibility(View.VISIBLE);
  16.  
  17. try {
  18. mCustomViewCallback.onCustomViewHidden();
  19. } catch (NullPointerException npe) {
  20. // occasionally Android likes to freak out and throw an unhandled NPE if it can't play the video
  21. // therefore we are not going to do anything but eat this exception so it fails gracefully
  22. }
  23.  
  24. mCustomView = null;
  25. mVideoView = null;
  26. }
  27.  
  28. @Override
  29. public void onShowCustomView(View view,CustomViewCallback callback) {
  30. super.onShowCustomView(view,callback);
  31. log.warn("onShowCustomView");
  32. showCustomView(view,callback);
  33. }
  34.  
  35. private void showCustomView(View view,CustomViewCallback callback) {
  36. if (mCustomView != null) {
  37. callback.onCustomViewHidden();
  38. return;
  39. }
  40.  
  41. mCustomView = view;
  42. mCustomViewCallback = callback;
  43. webView.setVisibility(View.GONE);
  44.  
  45. if (view instanceof FrameLayout) {
  46. if (((FrameLayout)view).getFocusedChild() instanceof VideoView) {
  47. mVideoView = (VideoView)((FrameLayout)view).getFocusedChild();
  48. }
  49. }
  50.  
  51. view.setLayoutParams(new FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT,FrameLayout.LayoutParams.MATCH_PARENT));
  52. view.setBackgroundColor(Color.BLACK);
  53. activity.displayFullscreenView(view);
  54. }
  55.  
  56. @Override
  57. public boolean onConsoleMessage(ConsoleMessage cm) {
  58. log.warn("Console Message: " + cm.message() + " on line " + cm.lineNumber() + " of " + cm.sourceId());
  59. return super.onConsoleMessage(cm);
  60. }
  61.  
  62. @Override
  63. public void onProgressChanged(WebView view,int newProgress) {
  64. super.onProgressChanged(view,newProgress);
  65.  
  66. if (newProgress < 100) {
  67. if (loadingProgress.getVisibility() == ProgressBar.GONE) {
  68. loadingProgress.setVisibility(ProgressBar.VISIBLE);
  69. }
  70. loadingProgress.setProgress(newProgress);
  71. } else if (newProgress >= 100) {
  72. loadingProgress.setVisibility(ProgressBar.GONE);
  73. }
  74. }
  75.  
  76. @Override
  77. public View getVideoLoadingProgressView() {
  78. if (mVideoProgressView == null) {
  79. LayoutInflater inflater = LayoutInflater.from(KnowledgeBaseFragment.this.getActivity().getApplicationContext());
  80. mVideoProgressView = inflater.inflate(R.layout.video_loading_progress,null);
  81. }
  82.  
  83. return mVideoProgressView;
  84. }
  85.  
  86. @Override
  87. public boolean onError(MediaPlayer mp,int what,int extra) {
  88. // TODO Auto-generated method stub
  89. return false;
  90. }
  91.  
  92. @Override
  93. public void onCompletion(MediaPlayer mp) {
  94. this.onHideCustomView();
  95. }
  96. }

请注意,我在片段中进行此操作,因此为了使其真正全屏,我必须将其与活动紧密耦合,以便将FrameLayout附加到整个视图层次结构的根目录,而不仅仅是片段.

以下是这些功能

  1. @Override
  2. public void displayFullscreenView(View customView) {
  3. parentLayout.addView(customView);
  4. this.customView = customView;
  5. }
  6.  
  7. @Override
  8. public void removeFullscreenView() {
  9. if (customView != null) {
  10. customView.setVisibility(View.GONE);
  11. parentLayout.removeView(customView);
  12. }
  13.  
  14. customView = null;
  15. }

这是另一个像你的问题:WebView and HTML5 <video>

猜你在找的HTML相关文章