本文介绍了在Android中播放YouTube网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个片段,该片段中有一个videoview.我有一个YouTube影片网址.我尝试了videoview和webview.但这是行不通的.我应该如何在这种布局中播放视频?
I have a fragment and a videoview is present inside that fragment.I have a you tube url for video.I tried videoview as well as webview. But it is not working.How i should play that video inside that layout?
推荐答案
只需使用普通的webview
,一切都会好起来的.
Just use normal a webview
and everything will be fine.
尝试:(经测试可工作)
new Thread(new Runnable() {
@Override
public void run() {
final WebView myWebView = (WebView) findViewById(R.id.webView1);
myWebView.setWebViewClient(new WebViewClient());
myWebView.getSettings().setJavaScriptEnabled(true);
myWebView.setWebChromeClient(new WebChromeClient());
try {
Log.e("Status", "tried url");
myWebView.loadUrl("http://youtube.com/xxxxxxxxx");
handler.post(new Runnable() {
@Override
public void run() {
Log.e("Status", "In Run():");
}
});
} catch (Exception e) {
e.printStackTrace();
Log.e("Status", "exception");
}
}
}).start();
这篇关于在Android中播放YouTube网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!