1
votes

I need to display in webView in custom dialog. Anyway, I can load youtube site, and navigate trought videos, but when I want to play some video and when I click play nothing happens. Video just get orange flash like it is selected, but doesnt start loading and playing. Whats the problem?

I found tutorial on net, and trying to modify it. Here is the code:

    dialog = new Dialog(this);
    dialog.setContentView(R.layout.dialog);

    pd = (ProgressBar) dialog.findViewById(R.id.web_view_progress_bar);

    webview = (WebView) dialog.findViewById(R.id.web_view);

    webview.getSettings().setPluginState(PluginState.ON);
    webview.getSettings().setJavaScriptEnabled(true);

    webview.setWebChromeClient(new WebChromeClient() {
        public void onProgressChanged(WebView view, int progress) {
            if (progress < 100 && pd.getVisibility() == ProgressBar.GONE) {
                pd.setVisibility(ProgressBar.VISIBLE);
            }
            pd.setProgress(progress);
            if (progress == 100) {
                pd.setVisibility(ProgressBar.GONE);
            }
        }
    });

    webview.setWebViewClient(new YoutubeWebViewClient());
    //shouldOverrideUrlLoading(webview, this.getUrl());
    webview.loadUrl(this.getUrl());

    dialog.show();

}


@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
    if (keyCode == KeyEvent.KEYCODE_BACK && webview.canGoBack()) {
        webview.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}


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

Help?

UPDATE:

I've tried this to do in other way, but again problems...

Im trying to embed youtube html5 player in webView. I only get back field without a youtube video. In right corner of webView is the youtube sign, and thats all of it. Dont have android phone, testing app on android x86 platform. is that a problem?

help :) dont care about a way of implementation, i just need this to work ^^

2
have you updated your flash player of your phone in which you are testing??.. may be because of that your not able to play video. - Dhrumil Shah - dhuma1981

2 Answers

0
votes

i dont know why but webviewclient class causes the problem , we can run it in default browser remove the webviewclient class and simly load the url of youtube you will be able to run it on 2.2 for 2.1 just use intent and through parse method open it through youtube application

startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("http://www.youtube.com/v/%s")))); }

0
votes

this is a kind of bug in android webview as far as i found till now,for me what worked is simply added Hardware Accleration permission in manifest.after that video embedded in my webview started playing .