开发者

android webview not displaying video using WebViewClient

i want to play a video from youtube on webview.. it displays the video,But i want to play it on the same page i mean i've to use WebViewClient.. but开发者_开发百科 using that it doesn't play the video.. (on pressing play button it doesn't play the video) what should i do? my code is

 setContentView(R.layout.main);
            wvSpecials = (WebView) findViewById(R.id.webView1);
            WebSettings webSettings = wvSpecials.getSettings();
            webSettings.setJavaScriptEnabled(true);
            wvSpecials.loadUrl("http://here.com/is link/");
            wvSpecials.setWebViewClient(new WebViewClient() {
                ProgressDialog progressDialog = new ProgressDialog(
                        specialsActivity.this);
                @Override
                public void onPageStarted(WebView view, String url, Bitmap favicon) {
                    progressDialog.setMessage("Please wait...");
                    progressDialog.show();
                    super.onPageStarted(view, url, favicon);
                }

                @Override
                public void onPageFinished(WebView view, String url) {
                    if (progressDialog.isShowing()) {
                        progressDialog.dismiss();
                    }
                    super.onPageFinished(view, url);
                }
                @Override
                public boolean shouldOverrideUrlLoading(WebView view, String url) {
                     view.loadUrl(url);

                    return super.shouldOverrideUrlLoading(view, url);
                }

            });
}


You may use the below listed code:

public class YouTube extends Activity{

  public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
      WebView myWebView;
      myWebView = (WebView) findViewById( R.id.web);
      myWebView.setWebViewClient(new MyWebViewClient());
  String pre="<iframe class=youtube-player type=text/html width=";
  String height=" height=";
  String suffix=" src=http://www.youtube.com/embed/**xxxxxxxxxxx**?autoplay=1 frameborder=0>"; // replace xxxxxxxxxxx with the specific embed id of your video
      String playVideo=pre+260+height+150+suffix;
      myWebView.getSettings().setPluginsEnabled(true);
      myWebView.getSettings().setJavaScriptEnabled(true);
  myWebView.loadData(playVideo,"text/html","UTF-8");
}
// override default behaviour of the browser

private class MyWebViewClient extends WebViewClient {
        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }


        ProgressDialog dialog = ProgressDialog.show(getApplicationContext(), "", 
                "Loading. Please wait...", true);
        @Override
           public void onPageFinished(WebView view, String url) {
            dialog.dismiss();
          }


    } }
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜