不能在Web视图玩视频 [英] Not able to play video in Web View

查看:446
本文介绍了不能在Web视图玩视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不能够在Android Web视图播放视频。

i am not able to play video on Android web view.

我一直HTML和视频文件在我的资产文件夹中。

I have kept the html and video file in my assets folder.

每当我加载HTML文件时,它给我的错误

Whenever i load the html file , it gives me the error

05-01 12:31:16.092: E/MediaResourceGetter(17241): Unable to read file: file:///android_asset/MediaBook2%20(2)/2B952499A0E681.mp4

,每当我美元的播放按钮我得到以下错误p $ PSS

And whenever i press on the play button i get the following error

05-01 12:31:23.680: E/chromium(17241): [ERROR:webmediaplayer_android.cc(328)] Not implemented reached in virtual void content::WebMediaPlayerAndroid::setRate(double)
05-01 12:31:23.710: E/MediaPlayer(17241): error (1, -2147483648)
05-01 12:31:23.710: E/MediaPlayer(17241): Error (1,-2147483648)

我能够加载任何远程视频和运行,但问题是当我从加载资产文件夹中的本地视频
code加载的文件和设置Web视图

Am able to load any remote video and run,But problem is when i load the local video from the assets folder Code to load the files and setup the web view

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    // Remove title bar
    requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_webview);
    mContentView = (LinearLayout) findViewById(R.id.linearlayout);
    // Keep the webview setup ready
    setupWebView();


}

public void setupWebView()
{
    webView = (WebView) findViewById(R.id.webView);
    // progressBar = (ProgressBar) findViewById(R.id.progressBarForWebView);

    WebSettings webViewSettings = webView.getSettings();
    webViewSettings.setJavaScriptEnabled(true);
    webViewSettings.setJavaScriptCanOpenWindowsAutomatically(true);
    webViewSettings.setPluginState(PluginState.ON);
    webView.getSettings().setAllowFileAccess(true);
    webView.setSoundEffectsEnabled(true);
    webView.setWebViewClient(new SLCWebViewClient());
    webView.setWebChromeClient(new WebChromeClient());
    loadContentsInWebView();

}
public void loadContentsInWebView()
    {

        String localURL = "file:///android_asset/MediaBook2 (2)/SampleForVideo.html";
        logger.debug("WebView URL: {}", localURL);
        try {
            webView.loadUrl(localURL);
        }
        catch (Exception e) {
            e.printStackTrace();
            logger.error("Error while loading url", e);
        }
    }
    private class SLCWebViewClient extends WebViewClient
{
    @Override
    public boolean shouldOverrideUrlLoading(WebView view, String url)
    {
        view.setWebChromeClient(new WebChromeClient()
        {

            private View mCustomView;

            @Override
            public void onShowCustomView(View view, WebChromeClient.CustomViewCallback callback)
            {
                // if a view already exists then immediately terminate the new one
                if (mCustomView != null) {
                    callback.onCustomViewHidden();
                    return;
                }

                // Add the custom view to its container.
                mCustomViewContainer.addView(view, COVER_SCREEN_GRAVITY_CENTER);
                mCustomView = view;
                mCustomViewCallback = callback;

                // hide main browser view
                mContentView.setVisibility(View.GONE);

                // Finally show the custom view container.
                mCustomViewContainer.setVisibility(View.VISIBLE);
                mCustomViewContainer.bringToFront();
            }

        });

        webView.loadUrl(url);

        return true;
    }

中的样本Video.html code

The Sample For Video.html code

    <!DOCTYPE html>
<html>
<title>Testing for Video</title>
<body>

<video width="320" height="240" controls>
  <source src="2B952499A0E681.mp4">
</video>

</body>
</html>

code的布局文件

Code for the layout file

<?xml version="1.0" encoding="utf-8"?>

<FrameLayout
      android:id="@+id/fullscreen_custom_content"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#FF000000"/>

<LinearLayout 
      android:id="@+id/linearlayout"
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent"> 

 <WebView
       android:id="@+id/webView"
       android:layout_width="fill_parent"
       android:layout_height="fill_parent" />

欢呼声,
Saurav

cheers, Saurav

推荐答案

的file:/// android_asset 协议是一个特定的网页视图的事情。那就是:其他系统组件无法读取这些网址。

The file:///android_asset protocol is a WebView-specific thing. That is: other system components can't read those URLs.

MediaResourceGetter 不使用的WebView网络堆栈,因此并不理解的file:/// android_asset 的协议。

The MediaResourceGetter doesn't use the WebView's network stack and therefore doesn't "understand" the file:///android_asset protocol.

在您的其他问题,你提到你使用一个本地的HTTP服务器 - 尝试从服务于.MP4

In your other question you mentioned you use a local http server - try serving the .mp4 from that.

这篇关于不能在Web视图玩视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆