如何在 webview android 上播放 html5 视频
我正在尝试在网页视图上加载网页,其中页面中有视频。我可以在网络视图上加载网页,但视频无法播放并且可以听到音频。这是我加载到网络视图的链接。
http://html5videoformatconverter.com/html5-video-tag-example.html
我所做的就是
public class VideoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView mWebView = (WebView) findViewById(R.id.wvVideo);
mWebView.setWebChromeClient(chromeClient);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl("http://html5videoformatconverter.com/html5-video-tag-example.html");
}
private WebChromeClient chromeClient = new WebChromeClient(){
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
// TODO Auto-generated method stub
super.onShowCustomView(view, callback);
if(view instanceof FrameLayout){
FrameLayout frame = (FrameLayout)view;
if(frame.getFocusedChild()instanceof VideoView){
VideoView video = (VideoView)frame.getFocusedChild();
frame.removeView(video);
video.start();
}
}
}
};
}
请帮助我修改我的代码。谢谢
i am trying to load a webpage on a web view where the page has a video in it. i am able to load the web page on the web view but the video is not playing and the audio is heard. this is the link i m loading to a web view.
http://html5videoformatconverter.com/html5-video-tag-example.html
and all i m doing is
public class VideoActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
WebView mWebView = (WebView) findViewById(R.id.wvVideo);
mWebView.setWebChromeClient(chromeClient);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl("http://html5videoformatconverter.com/html5-video-tag-example.html");
}
private WebChromeClient chromeClient = new WebChromeClient(){
@Override
public void onShowCustomView(View view, CustomViewCallback callback) {
// TODO Auto-generated method stub
super.onShowCustomView(view, callback);
if(view instanceof FrameLayout){
FrameLayout frame = (FrameLayout)view;
if(frame.getFocusedChild()instanceof VideoView){
VideoView video = (VideoView)frame.getFocusedChild();
frame.removeView(video);
video.start();
}
}
}
};
}
pls help me modify my code. thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
Android 浏览器和 WebView 在播放 HTML5
视频时存在许多已知问题。
Android webview 无法渲染通过 iframe 嵌入的 YouTube 视频< /a>
除非您可以针对 Android 4.0 或优秀的现代固件,否则当前的解决方法是使用指向视频的缩略图链接,然后此链接将打开视频在原生 Android 视频播放器中。
有关 Android 上 HTML5 视频问题的更多信息,请随时搜索 stackoverflow.com。
Android Browser and WebView has many known problems playing HTML5
<video>
videos.Android webview cannot render youtube video embedded via iframe
Unless you can target Android 4.0 or good modern firmwars, the current workaround is to have a thumbnail image link to a video and then this link opens the video in the native Android video player.
For more information with HTML5 video problems on Android please feel free to search stackoverflow.com.
这对我有用,问题与本地存储视频的文件权限有关。希望有帮助!
This worked for me, problem was to do with file permissions on the locally stored video. Hope it helps!
正如@Mikko 所说,这是一个棘手的领域。
要检查的一件事是您是否启用了硬件加速。当我关闭它时,我遇到了与OP描述的完全相同的症状。
您可以在应用程序或活动级别启用它:
或者
As @Mikko says, this is a tricky area.
One thing to check is that you have hardware acceleration enabled. I encounter the exact same symptoms the OP describes when leaving it turned off.
You can enable it at the application or at the activity level:
OR
当我遇到这个问题时,这是由于压缩类型造成的。对于 Android,我必须使用基本配置文件压缩而不是高级配置文件压缩。 ffmpeg 兼容性 有说明。
我在此处回答了类似的问题。
When I encountered this problem it was due to the compression type. For android I had to use base profile compression rather than high profile compression. ffmpeg compatibility has a description.
I answered a similar question here.
我正在将嵌入 YouTube 的移动网站转换为 Android 应用程序......这个项目帮助我摆脱了将视频在网络视图中全屏显示的麻烦。我所有的问题都解决了。你可以从这里得到一些东西。
https://code.google.com/p/html5webview/
I was converting my mobile website with youtube embeds into android app....this project helped me get rid of getting the video to fullscreen in webview. All my problems were solved. You can get something from here.
https://code.google.com/p/html5webview/