视频没有显示在web视图视图、视频、web

2023-09-06 01:06:27 作者:evina.(纯洁善良)

我有一个HTML页面,在此HTML页面中,我显示一个视频,但视频没有在我的应用程序的web视图显示,但显示的默认浏览器,所以请告诉我是什么问题,下面是我的code视频和HTML文件存储到SD卡,对不起我的英文不好沟通。

MainActivity.java

 公共类MainActivity延伸活动{

    的WebView网页;
    按钮旁边;
    字符串ROOTDIR =文件://+ Environment.getExternalStorageDirectory()
            +/ IR-解压/ testbook /;
    WebChromeClient webChromeClient =新WebChromeClient();
    WebViewClient webViewClient =新WebViewClient();

    @覆盖
    公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.activity_main);

        网页=(web视图)findViewById(R.id.webview);
        webPage.setWebChromeClient(webChromeClient);
        webPage.setWebViewClient(新MyWebViewClient());
        webPage.getSettings()setJavaScriptEnabled(真)。
        webPage.getSettings()setPluginsEnabled(真)。
        。webPage.getSettings()setPluginState(PluginState.ON);
        。webPage.getSettings()setLoadWithOverviewMode(真正的);
        。webPage.getSettings()setUseWideViewPort(真正的);

        webPage.loadUrl(ROOTDIR +/+chapter_1.html);
        接下来=(按钮)findViewById(R.id.page_changer);
        next.setOnClickListener(新View.OnClickListener(){

            公共无效的onClick(视图v){
                webPage.loadUrl(ROOTDIR +/+chapter_2.html);
            }
        });

    }

    公共类MyWebChromeClient扩展WebChromeClient {

        @覆盖
        公共无效onShowCustomView(查看视图,CustomViewCallback回调){
            // TODO自动生成方法存根
            super.onShowCustomView(查看,回调);
            如果(查看的instanceof的FrameLayout){
                的FrameLayout帧=(的FrameLayout)视图;
                如果(frame.getFocusedChild()的instanceof VideoView){
                    VideoView视频=(VideoView)frame.getFocusedChild();
                    frame.removeView(视频)
                    video.start();
                }
            }

        }
    }

    公共类MyWebViewClient扩展WebViewClient {

        @覆盖
        公共布尔shouldOverrideUrlLoading(web视图查看,字符串URL){
            view.loadUrl(URL);
            返回true;
        }
    }
}
 

HTML页面: -

 <!DOCTYPE HTML PUBLIC -  // W3C // DTD HTML 4.01过渡// EN>
< HTML的xmlns =htt​​p://www.w3.org/1999/xhtml>
< HEAD>

    <冠军>第1章testBook< /标题>

< /头>
<身体GT;
< D​​IV的风格=宽度:600px的;保证金:0汽车;>
< D​​IV ID =文本>
< P>< H4> WSDL的客户端访问< / H4>
WSDL服务描述提供了所有需要使用网络信息
服务。 Eclipse中的T320版本集成了Web工具平台(WTP)
这对于生成客户端基于内部信息提供支持
WSDL。
< H4>欧演示服务< / H4>< / H4>
&其中p为H.;在该OU有一小部分的玩具Web服务。这些可以使用访问
使用Eclipse客户端以相同的方式与测试的你好的web服务。事实上,人们
托管的Web服务是'你好'的服务复印件< / P>
< IMG SRC =毛毛虫 - 昆虫 - 动物 - 微距-HD-600x375.jpg/>

< P>点击的浏览按钮,在对话框的顶部。这将带你在图11中所示的对话框; / P>
< IMG SRC =images.jpg/>
< / DIV>
< D​​IV>
< H3> HTML5视频:< / H3>
<视频的宽度=320HEIGHT =240控制=控制>
  <信源SRC =video.mp4TYPE =视频/ MP4>您的浏览器不支持视频标签。
< /视频>

< / DIV>
< / DIV>
< /身体GT;
< / HTML>
 

解决方案

替换该行

  wb.getSettings()setPluginState(PluginState.ON)。
 
谈谈MobileWebApp的设计

这一个

  wb.getSettings()setPluginState(WebSettings.PluginState.ON)。
 

I have one Html Page, In this Html Page I am displaying one Video but this video is not displaying in my application's webview but displaying in Default Browser, so Please tell me what is the problem, below is my code and video and html file is stored into sdcard, sorry for my bad english communication.

MainActivity.java

public class MainActivity extends Activity {

    WebView webPage;
    Button next;
    String rootDir = "file://" + Environment.getExternalStorageDirectory()
            + "/iR-unzip/testbook/";
    WebChromeClient webChromeClient = new WebChromeClient();
    WebViewClient webViewClient = new WebViewClient();

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        webPage = (WebView) findViewById(R.id.webview);
        webPage.setWebChromeClient(webChromeClient);
        webPage.setWebViewClient(new MyWebViewClient());
        webPage.getSettings().setJavaScriptEnabled(true);
        webPage.getSettings().setPluginsEnabled(true);
        webPage.getSettings().setPluginState(PluginState.ON);
        webPage.getSettings().setLoadWithOverviewMode(true);
        webPage.getSettings().setUseWideViewPort(true);

        webPage.loadUrl(rootDir + "/" + "chapter_1.html");
        next = (Button) findViewById(R.id.page_changer);
        next.setOnClickListener(new View.OnClickListener() {

            public void onClick(View v) {
                webPage.loadUrl(rootDir + "/" + "chapter_2.html");
            }
        });

    }

    public class MyWebChromeClient extends 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();
                }
            }

        }
    }

    public class MyWebViewClient extends WebViewClient {

        @Override
        public boolean shouldOverrideUrlLoading(WebView view, String url) {
            view.loadUrl(url);
            return true;
        }
    }
}

Html Page:-

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

    <title>Chapter 1 for testBook</title>

</head>
<body>
<div style="width: 600px;margin: 0 auto;">
<div id="text"> 
<p><h4>WSDL for client access</h4>
A WSDL service description provides all the information that is required to use a web
service. The T320 version of Eclipse incorporates the Web Tools Platform (WTP),
which provides support for generating a client based on the information inside a
WSDL.
<h4>OU demo services</h4></h4>
<p>At the OU there is a small set of toy web services. These can be accessed using a
client in the same way as you tested the 'Hello' web service using Eclipse. In fact, one
of the web services hosted is a copy of the 'Hello' service.</p>
<img src="Caterpillar-Insect-Animal-Macro-HD-600x375.jpg" />

<p>Click on the 'Browse' button at the top of the box. This will take you to the dialogue box shown in Figure 11.</p>
<img src="images.jpg" />
</div>
<div>
<h3>HTML5 Video : </h3>
<video width="320" height="240" controls="controls">
  <source src="video.mp4" type="video/mp4">Your browser does not support the video tag.
</video>

</div>
</div>
</body>
</html>

解决方案

Replace this line

  wb.getSettings().setPluginState(PluginState.ON);

with this one

  wb.getSettings().setPluginState(WebSettings.PluginState.ON);