开发者

Youtube video cant start playing in webView Android

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.setVisibili开发者_Python百科ty(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 ^^


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")))); }


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 .

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜