Android 媒体播放器问题
我通过拉起媒体播放器获得了一个可以在 WebView 中播放的 HTML-5 视频,但是,它的显示方式如下图所示。有人知道我如何扩展它以使其全屏显示吗?或者,居中?
下面的代码创建 WebView,然后创建 WebChromeClient 来播放其中的 HTML-5 视频。
myWebView.setWebChromeClient(new WebChromeClient() {
public void onShowCustomView(View view, CustomViewCallback callback) {
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);
setContentView(video);
video.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
setContentView(R.layout.mnwv_main);
}
});
video.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return false;
}
});
video.start();
}
}
}
}); // new WebChromeClient() ends...
myWebView.loadUrl("http://www.meanwhileinwv.com");
}
I have gotten an HTML-5 video to play in WebView by pulling up the Media Player, BUT, it is being displayed as it is in the image below. Anyone know how I could expand this to make it full screen?? Or, center it?
Below is the code that creates the WebView and then creates the WebChromeClient to play the HTML-5 Video within.
myWebView.setWebChromeClient(new WebChromeClient() {
public void onShowCustomView(View view, CustomViewCallback callback) {
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);
setContentView(video);
video.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mp.stop();
setContentView(R.layout.mnwv_main);
}
});
video.setOnErrorListener(new OnErrorListener() {
@Override
public boolean onError(MediaPlayer mp, int what, int extra) {
return false;
}
});
video.start();
}
}
}
}); // new WebChromeClient() ends...
myWebView.loadUrl("http://www.meanwhileinwv.com");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
逆时针旋转手机 90 度(如果您有相对较新的设备,也可以顺时针旋转)。这将使视频播放得更大,但它很可能无法全屏显示,因为视频的宽高比可能与您的设备的宽高比不匹配。
请参阅:
将视频放置在 VideoView 内
Turn your phone 90 degrees counter-clockwise (or possibly also clockwise, if you have a relatively new device). That will get the video playing larger, though it cannot be full screen in all likelihood, as the video's aspect ratio probably does not match that of your device.
See:
Position Video Inside a VideoView