嵌入式IFRAME影片继续播放背景Android中退出全屏模式后, [英] Embedded IFRAME video keeps playing in background after exiting fullscreen in Android

查看:961
本文介绍了嵌入式IFRAME影片继续播放背景Android中退出全屏模式后,的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我搜索了很多关于这个问题的修复,但显然我无法找到一个。
那么,顾名思义我有一个简单的Andr​​oid应用程序有一个网页视图。

I've searched a lot for a fix on this problem but apparently i couldn't find one. Well, as the name suggests I have a simple Android app which has a Webview.

public class MainActivity extends Activity {
   protected FrameLayout webViewPlaceholder;
   protected WebView webView;
   final Context myApp = this;
   @Override
   public void onCreate(Bundle savedInstanceState)
   {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);

      // Initialize the UI
      initUI();
   }

   protected void initUI()
   {
    // Retrieve UI elements
    webViewPlaceholder = ((FrameLayout)findViewById(R.id.webViewPlaceholder));

    // Initialize the WebView if necessary
    if (webView == null)
    {
        // Create the webview
        webView = new WebView(this);
        webView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
        webView.getSettings().setSupportZoom(true);
        webView.getSettings().setBuiltInZoomControls(true);
        webView.setScrollBarStyle(WebView.SCROLLBARS_OUTSIDE_OVERLAY);
        webView.setScrollbarFadingEnabled(true);
        webView.getSettings().setLoadsImagesAutomatically(true);

        // Load the URLs inside the WebView, not in the external web browser
        webView.setWebViewClient(new WebViewClient());
        //webView.setWebChromeClient(new CustomChromeClient(this));
        webView.setWebChromeClient(new WebChromeClient() {  
            @Override  
            public boolean onJsAlert(WebView view, String url, String message, final android.webkit.JsResult result)   
            {  
                new AlertDialog.Builder(myApp)  
                    .setTitle("javaScript dialog")  
                    .setMessage(message)  
                    .setPositiveButton(android.R.string.ok,  
                            new AlertDialog.OnClickListener()   
                            {  
                                public void onClick(DialogInterface dialog, int which)   
                                {  
                                    result.confirm();  
                                }  
                            })  
                    .setCancelable(false)  
                    .create()  
                    .show();  

                return true;  
            };
            public void onShowCustomView(View view, CustomViewCallback callback){
                super.onShowCustomView(view, callback);
                Log.i("ChromeCLient", "onshowCustomView");
                new AlertDialog.Builder(myApp)  
                .setTitle("javaScript dialog")  
                .setMessage("ajbdlsakndsland")  
                .setCancelable(true)  
                .create()  
                .show();  
            }
            @Override
            public void onHideCustomView() {
                super.onHideCustomView();
                Log.i("ChromeCLient", "onhideCustomView");
            }
        });  

        webView.getSettings().setJavaScriptEnabled(true);
        if (Build.VERSION.SDK_INT < 8) {
          webView.getSettings().setPluginsEnabled(true);
        } else {
          webView.getSettings().setPluginState(WebSettings.PluginState.ON);
        }
        // Load a page
        webView.loadUrl("http://jsbin.com/ijixe4/3");
    }

    // Attach the WebView to its placeholder
    webViewPlaceholder.addView(webView);
}

@Override
public void onConfigurationChanged(Configuration newConfig)
{
    if (webView != null)
    {
        // Remove the WebView from the old placeholder
        webViewPlaceholder.removeView(webView);
    }

    super.onConfigurationChanged(newConfig);

    // Load the layout resource for the new configuration
    setContentView(R.layout.activity_main);

    // Reinitialize the UI
    initUI();
}

@Override
protected void onSaveInstanceState(Bundle outState)
{
    super.onSaveInstanceState(outState);

    // Save the state of the WebView
    webView.saveState(outState);
}

@Override
protected void onRestoreInstanceState(Bundle savedInstanceState)
{
    super.onRestoreInstanceState(savedInstanceState);

    // Restore the state of the WebView
    webView.restoreState(savedInstanceState);
}
}

我的问题如下。
那就是在web视图加载该网站是其中包含嵌入的YouTube视频简单的iframe的网站。
当我打在YouTube视频全屏按钮,它改变即使我在清单设置我的应用方向:screenOrientation =画像。
当退出全屏,而播放视频继续播放(背景),即使网页流量已经因方向改变重建。
我试着在活动的onDestroy()方法破坏的WebView时方向从横向变为纵向。但它并没有帮助。
我试着设置一个CustomWebChromeClient到web视图和执行onShowCustomView()方法,但onShowCustomView()显然不叫,除非我使用HTML5视频。
我甚至试图通过更改方向保留网页视图的状态。

My problem is as follows. The site that is loaded in the webview is a site which contains a simple iframe embedded youtube video. When i hit the FullScreen button on the youtube video, it changes my app orientation even though i set in my manifest: screenOrientation ="portrait". When exiting the FullScreen, while playing the video keeps playing (in background), even though the webview has been recreated due to the orientation change. I've tried destroying the webview in the onDestroy() method of the activity when the orientation turns from landscape to portrait. but it didn't help. I've tried setting a CustomWebChromeClient to the webview and implementing the onShowCustomView() method, but the onShowCustomView() apparently isn't called unless i use HTML5 videos. I've even tried to retain the state of the webview through the orientation change.

难道你们有解决这个问题/错误的任何其他方式?
我不会真的想要使用HTML5视频标签。
先谢谢了。

Do you guys have any other way of resolving this problem/bug? I wouldn't really want to use the HTML5 video tag. Thanks in advance.

推荐答案

只是覆盖的onPause和onResume方法并调用web视图同样的方法如下:

Just override onPause and onResume methods and call the same methods on the webView as follows.

@Override
protected void onResume() {
    super.onResume();
    this.webView.onResume();
}

@Override
protected void onPause() {
    super.onPause();
    this.webView.onPause();
}

这篇关于嵌入式IFRAME影片继续播放背景Android中退出全屏模式后,的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆