如何显示弹出帧开始播放视频的WebView安卓 [英] how to display popup frame to play video on webview android
问题描述
我想显示弹出画面时,我的网络视图,而不是弹出框的用户点击视频链接应显示,进入该框架的布局视频面从SD卡并自动与网络驳回后,视频结束帧的排版打我的视频-view再次显示。 我搜索谷歌和计算器也有一定的帮助,但我不知道有工艺来写code。有混乱在我的脑海,我怎么能显示弹出式的FrameLayout以及如何显示的WebView回来。
目前我检查扩展,如果我发现视频扩展比我火了媒体播放器的意图。但我不希望出现这种情况。我想它应该在我的网络视图,但在弹出的一种视频表面的发挥。
下面是我的code和我的布局文件只包含的WebView任何东西的,我从我的资产文件夹加载HTML和我从SD卡播放视频。
任何帮助是pciated AP $ P $
的setContentView(R.layout.activity_main);
的WebView web视图=(web视图)findViewById(R.id.webview);
字符串的HTML =<嵌入SRC = \文件:/// android_asset /+test.html的+\玩= \真正的\循环= \真正的\WIDTH = \100%\ 身高= \100%\><嵌入>中;
。webView.getSettings()setPluginState(WebSettings.PluginState.ON);
。webView.getSettings()setAllowFileAccess(真正的);
webView.getSettings()setJavaScriptEnabled(真)。
webView.loadDataWithBaseURL(文件:/// android_asset /,HTML,text / html的,UTF-8,NULL);
WebViewClient webViewClient =新WebViewClient();
webView.setWebViewClient(webViewClient);
webView.setWebViewClient(新WebViewClient(){
@覆盖
公共无效onPageFinished(web视图查看,字符串URL){
// TODO自动生成方法存根
super.onPageFinished(查看,网址);
}
@覆盖
公共无效onLoadResource(web视图查看,字符串URL){
如果(url.endsWith(。m4v格式)){
意向意图=新的意图(Intent.ACTION_VIEW,乌里
.parse(URL));
intent.setDataAndType(Uri.parse(URL),视频/ *);
。view.getContext()startActivity(意向);
}
其他
{
super.onLoadResource(查看,网址);
}
}
});}
}
下面是HTML文件
< HTML LANG =EN>
< HEAD>
<元字符集= UTF-8'
<冠军>样品HTML5结构与LT; /标题>
< SCRIPT LANGUAGE =JavaScript的>
功能的playVideo(URL){
了window.location = URL;
}
< / SCRIPT>
< /头>
<身体GT;
<视频SRC =文件:///sdcard/kummar.m4vWIDTH =300的onclick =的playVideo(文件:/// SD卡/ KU< P>视频元素的检测和LT; / P>
< /视频>
< /身体GT;
< / HTML>
试试这个定制对话框
对话mVideoDialog;
VideoView mVideoFullScreen;
的MediaController控制器;
在您的increate方法添加此
mVideoDialog =新的对话框(本);
mVideoDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mVideoDialog.setContentView(R.layout.dialog);
mVideoDialog.setOnKeyListener(本);
mVideoFullScreen =(VideoView)mVideoDialog.findViewById(R.id.videoview1);
控制器=新的MediaController(本);
HelloWebViewClient webViewClient =新HelloWebViewClient();
webView.setWebViewClient(webViewClient);
}
私有类HelloWebViewClient扩展WebViewClient
{
@覆盖公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL)
{
如果(url.contentEquals(文件:/// android_asset / 01)){
showVideo(01); //从web视图,并通过INT检查用户点击网址
}
否则,如果(url.contentEquals(文件:/// android_asset / 02))
{
showVideo(02); //通过INT确定要播放的视频
}
其他
{
的System.out.println(DDD URL:+ url.toString()); view.loadUrl(URL);
}
返回true;
}
这是showVideo方法
公共无效showVideo(int i)以{
// TODO自动生成方法存根
如果(我== 01)
{
mVideoDialog.show();
mVideoFullScreen.setVideoPath(文件:/// SD卡/视频文件name.m4v);
controller.setMediaPlayer(mVideoFullScreen);
mVideoFullScreen.setMediaController(控制器);
mVideoFullScreen.requestFocus();
mVideoFullScreen.start();
}其他
{}}
I want to display popup frame when user click video link on my web-view than popup frame should display and into that frame-layout video surface play my video from sd card and after video finish frame-layout is dismiss automatically and web-view is displayed again. I search on google and stackoverflow there are some help but i dont understand there technic to write code. There is confusion in my mind that how can i display popup framelayout and how can i display webview back.
Currently i am checking extension and if i found video extension than i fire media player intent . but i don't want that. i want it should play inside my web-view but in popup kind of video surface.
Here is my code and my layout file only contain webview nothing else in it and i am loading html from my assets folder and i am playing video from sd card..
Any help is appreciated
setContentView(R.layout.activity_main);
WebView webView = (WebView) findViewById(R.id.webview);
String html = "<embed src=\"file:///android_asset/" + "test.html" + " \"play=\"true\" loop=\"true\" width=\"100%\" height=\"100%\"> <embed>";
webView.getSettings().setPluginState(WebSettings.PluginState.ON);
webView.getSettings().setAllowFileAccess(true);
webView.getSettings().setJavaScriptEnabled(true);
webView.loadDataWithBaseURL("file:///android_asset/", html, "text/html", "utf-8", null);
WebViewClient webViewClient = new WebViewClient();
webView.setWebViewClient(webViewClient);
webView.setWebViewClient(new WebViewClient(){
@Override
public void onPageFinished(WebView view, String url) {
// TODO Auto-generated method stub
super.onPageFinished(view, url);
}
@Override
public void onLoadResource(WebView view, String url) {
if (url.endsWith(".m4v")) {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri
.parse(url));
intent.setDataAndType(Uri.parse(url), "video/*");
view.getContext().startActivity(intent);
}
else
{
super.onLoadResource(view, url);
}
}
});}
}
Here is the HTMl file
<html lang="en">
<head>
<meta charset=utf-8>
<title>Sample HTML5 Structure</title>
<SCRIPT LANGUAGE="JavaScript">
function playvideo(url){
window.location=url;
}
</SCRIPT>
</head>
<body>
<video src="file:///sdcard/kummar.m4v" width="300" onclick="playvideo('file:///sdcard/ku<p>testing of video element.</p>
</video>
</body>
</html>
Try Custom dialog for this
Dialog mVideoDialog ;
VideoView mVideoFullScreen;
MediaController controller;
In your increate method add this
mVideoDialog = new Dialog(this);
mVideoDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mVideoDialog.setContentView(R.layout.dialog);
mVideoDialog.setOnKeyListener(this);
mVideoFullScreen = (VideoView) mVideoDialog.findViewById(R.id.videoview1);
controller = new MediaController(this);
HelloWebViewClient webViewClient = new HelloWebViewClient();
webView.setWebViewClient(webViewClient);
}
private class HelloWebViewClient extends WebViewClient
{
@Override public boolean shouldOverrideUrlLoading(WebView view, String url)
{
if (url.contentEquals("file:///android_asset/01")) {
showVideo(01); //check user click url from webview and pass int
}
else if (url.contentEquals("file:///android_asset/02"))
{
showVideo(02);//pass int to determine which video to play
}
else
{
System.out.println("DDD URL: "+url.toString()); view.loadUrl(url);
}
return true;
}
This is showVideo method
public void showVideo(int i) {
// TODO Auto-generated method stub
if(i==01)
{
mVideoDialog.show();
mVideoFullScreen.setVideoPath("file:///sdcard/video file name.m4v");
controller.setMediaPlayer(mVideoFullScreen);
mVideoFullScreen.setMediaController(controller);
mVideoFullScreen.requestFocus();
mVideoFullScreen.start();
}else
{ } }
这篇关于如何显示弹出帧开始播放视频的WebView安卓的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!