1

我想在 android 低版本和更高版本上向您展示管视频。我的代码在 android 3.0 上运行良好,但在 4.0 上它显示您的管视频屏幕,但是当点击播放时它只显示您管视频的进度条。

这是我的代码-

 if(Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB)
        {
            playVideoForBelowVersion();
        }

        else
        {

            playVideoForIcs();
        }
private void playVideoForBelowVersion() 
     {
        String url =  videoLinks[position] + "?autoplay=1";
        webView.getSettings().setJavaScriptEnabled(true);
        webView. getSettings().setJavaScriptCanOpenWindowsAutomatically (false);
        webView. getSettings().setPluginsEnabled (true);
        webView. getSettings().setSupportMultipleWindows (false);
        webView. getSettings().setSupportZoom (false);
        webView. setVerticalScrollBarEnabled (false);
        webView. setHorizontalScrollBarEnabled (false);
        webView.loadUrl(url);
        webView.setWebChromeClient(new WebChromeClient());
        webView.setWebViewClient(new WebViewClient()
        {


            @Override
            public void onPageFinished(WebView view, String url) {
                // TODO Auto-generated method stub
                super.onPageFinished(view, url);
//               progressDialog.dismiss();

            }

            @Override
            public void onPageStarted(WebView view, String url, Bitmap favicon) {
                // TODO Auto-generated method stub
                super.onPageStarted(view, url, favicon);
                 /*progressDialog.setMessage("Loading Video please wait...");
                 progressDialog.show();*/


            }

            @Override
            public void onReceivedError(WebView view, int errorCode,
                    String description, String failingUrl) {
                // TODO Auto-generated method stub
                super.onReceivedError(view, errorCode, description, failingUrl);
                Utilities.showToast(FullVideoAct.this, "Video Error...");
            }

            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                // TODO Auto-generated method stub
                view.loadUrl(url);
                return true;
            }

        });
        webView.requestFocus();
     }

    private void playVideoForIcs() 
     {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED,  WindowManager.LayoutParams.FLAG_HARDWARE_ACCELERATED);
        String strUrl = "http://m.youtube.com/index?&desktop_uri=%2F#/watch?v="+videoLinksIds[position];
//      String strUrl =  videoLinks[position] + "?autoplay=1";
//      String strUrl ="http://www.youtube.com/v/"+videoLinksIds[position]+"?enablejsapi=1&version=3&playerapiid=ytplayer";
        webView.getSettings().setJavaScriptEnabled(true);
        webView. getSettings().setJavaScriptCanOpenWindowsAutomatically (false);
        webView. getSettings().setPluginsEnabled (true);
        webView. getSettings().setSupportMultipleWindows (false);
        webView. getSettings().setSupportZoom (false);
        webView. setVerticalScrollBarEnabled (false);
        webView. setHorizontalScrollBarEnabled (false);
        webView.loadUrl(strUrl);
        //wvVideo.loadData(htmlString, "text/html", "UTF-8");
        webView.setWebChromeClient(new WebChromeClient());

        webView.requestFocus();

     }
4

1 回答 1

2

在 android 清单文件中设置 android:hardwareAccelerated="true" 在应用程序标记中,如此应用程序 android:icon="@drawable/ic_launcher" android:hardwareAccelerated="true" android:label="@string/app_name"

于 2013-02-08T13:19:22.883 回答