YouTube的视频不是在玩中的WebView - 机器人 [英] YouTube Video not playing in WebView - Android
问题描述
我绑播放YouTube视频的WebView,web视图显示与播放按钮,视频第一次看,但点击播放按钮后,启动进度条和2-3秒后停止进度条和空白的屏幕与黑色的颜色。
Image1的:视频先来看看与播放按钮
IMAGE2:后点击播放按钮,屏幕变为空白
请!帮我为什么不录像开始。
图像:1
IMAGE:2
这是我的源$ C $ C到的WebView发挥YouTubeVideo ..请帮我...
公共无效的onCreate(包savedInstanceState){
super.onCreate(savedInstanceState);
的setContentView(R.layout.main);
的WebView WV =(web视图)findViewById(R.id.webView1);
wv.getSettings()setJavaScriptEnabled(真)。
wv.getSettings()setPluginsEnabled(真)。
最后弦乐MIMETYPE =text / html的;
最终的字符串编码=UTF-8;
串的HTML = getHTML();
wv.loadDataWithBaseURL(,HTML,MIMETYPE,编码,);
}
公共字符串getHTML(){
字符串的HTML =< IFRAME类= \的YouTube播放器\的风格= \边界:0;宽度:100%;高度:95%;填充:0px;保证金:0px \ID = \ytplayer \型= \text / html的\SRC = \http://www.youtube.com/embed/
+J2fB5XWj6IE
+?FS = 0 \FRAMEBORDER = \0 \> \ N
+< / IFRAME> \ N的;
返回HTML;
}
添加加载HTML内容之前,这些行到你的WebView。
wv.setWebChromeClient(新WebChromeClient(){
});
从文档:
为了支持在应用程序中嵌入HTML5视频,你需要有硬件加速功能开启时,,并设置WebChromeClient 。对于全屏幕支持,onShowCustomView(查看,WebChromeClient.CustomViewCallback)和onHideCustomView()的实现是必需的,getVideoLoadingProgressView()是可选的。
I am tying to play YouTube video in WebView, WebView showing first look of video with play button, But after click on play button start progress bar and after 2-3 seconds stop progress bar and screen blank with black color.
Image1: Video first look with play button
Image2: After click on play button screen goes blank.
Please! help me why video not starting.
IMAGE:1
IMAGE:2
This is my source code to play YouTubeVideo in webview.. Please help me ...
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView wv = (WebView) findViewById(R.id.webView1);
wv.getSettings().setJavaScriptEnabled(true);
wv.getSettings().setPluginsEnabled(true);
final String mimeType = "text/html";
final String encoding = "UTF-8";
String html = getHTML();
wv.loadDataWithBaseURL("", html, mimeType, encoding, "");
}
public String getHTML() {
String html = "<iframe class=\"youtube-player\" style=\"border: 0; width: 100%; height: 95%; padding:0px; margin:0px\" id=\"ytplayer\" type=\"text/html\" src=\"http://www.youtube.com/embed/"
+ "J2fB5XWj6IE"
+ "?fs=0\" frameborder=\"0\">\n"
+ "</iframe>\n";
return html;
}
Add these lines before loading HTML content to your WebView.
wv.setWebChromeClient(new WebChromeClient() {
});
From the documentation:
In order to support inline HTML5 video in your application, you need to have hardware acceleration turned on, and set a WebChromeClient. For full screen support, implementations of onShowCustomView(View, WebChromeClient.CustomViewCallback) and onHideCustomView() are required, getVideoLoadingProgressView() is optional.
这篇关于YouTube的视频不是在玩中的WebView - 机器人的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!