的WebView和HTML5<视频> [英] WebView and HTML5 <video>

查看:132
本文介绍了的WebView和HTML5<视频>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我拼凑一个小气鬼的应用程序,除其他事项外框我们的一些网站... pretty的简单与WebViewClient ......直到我打的录像。

I'm piecing together a cheapo app that amongst other things "frames" some of our websites... Pretty simple with the WebViewClient... until I hit the video.

该视频是作为HTML5元素,而这些做工精细和花花公子的浏览器,iPhone手机,而现在,我们固定的编码问题,它的伟大工程在Android上......在本地浏览器。

The video is done as HTML5 elements, and these work fine and dandy on Chrome, iPhones, and now that we fixed the encoding issues it works great on Android... in the native browser.

现在的困难:web视图不喜欢它。在所有。我可以点击海报图像上,并没有任何反应。

Now the rub: WebView doesn't like it. At all. I can click on the poster image, and nothing happens.

谷歌搜索,我发现<一href="http://www.$c$clark.com/2010/05/12/android-viewing-video-from-embedded-webview/">http://www.$c$clark.com/2010/05/12/android-viewing-video-from-embedded-webview/这是接近的,但似乎不是视频元素是基于一个链接(如在A HREF ...)。 (onDownloadListener没有出现在视频元素被调用...)

Googling, I found http://www.codelark.com/2010/05/12/android-viewing-video-from-embedded-webview/ which is close, but seems to be based on a 'link' (as in a href...) instead of a video element. (onDownloadListener does not appear to get invoked on video elements...)

我也看到引用覆盖onShowCustomView,但似乎没有得到所谓的视频元素......也不会shouldOverrideUrlLoading ..

I also see references to overriding onShowCustomView, but that seems to not get called on video elements... nor does shouldOverrideUrlLoading..

我宁愿不进入从服务器获取XML,重新格式化的应用程序......通过保持故事的布局在服务器上,我可以控制的内容,而迫使人们不断更新的应用程序会好一点。所以,如果我能说服的WebView处理标签,如原生浏览器,这将是最好的。

I would rather not get into "pull xml from the server, reformat it in the app".. by keeping the story layout on the server, I can control the content a bit better without forcing people to keep updating an app. So if I can convince WebView to handle tags like the native browser, that would be best.

我清楚地失去了一些东西明显..但我不知道是什么。

I'm clearly missing something obvious.. but I have no clue what.

推荐答案

我回答这个话题,以防万一有人读它,有兴趣的结果。 它可以查看一个web视图中的视频元素(视频HTML5标签),但我必须说,我必须处理它几天。这些都是我要遵循的步骤至今:

I answer this topic just in case someone read it and is interested on the result. It is possible to view a video element (video html5 tag) within a WebView, but I must say I had to deal with it for few days. These are the steps I had to follow so far:

- 查找正确的连接codeD的视频

-Find a properly encoded video

- 当初始化web视图,设置的JavaScript,插件WebViewClient和WebChromeClient。

-When initializing the WebView, set the JavaScript, Plug-ins the WebViewClient and the WebChromeClient.


url = new String("http://broken-links.com/tests/video/"); 
mWebView = (WebView) findViewById(R.id.webview);
mWebView.setWebChromeClient(chromeClient);
mWebView.setWebViewClient(wvClient);
mWebView.getSettings().setJavaScriptEnabled(true);
mWebView.getSettings().setPluginsEnabled(true);
mWebView.loadUrl(url);

-Handle的onShowCustomView在WebChromeClient对象。

-Handle the onShowCustomView in the WebChromeClient object.

@Override
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);
            a.setContentView(video);
            video.setOnCompletionListener(this);
            video.setOnErrorListener(this);
            video.start();
        }
    }
}

-Handle的onCompletion和onerror的事件的视频,以获得回Web视图。

-Handle the onCompletion and the onError events for the video, in order to get back to the web view.

public void onCompletion(MediaPlayer mp) {
    Log.d(TAG, "Video completo");
    a.setContentView(R.layout.main);
    WebView wb = (WebView) a.findViewById(R.id.webview);
    a.initWebView();
}

但现在我应该说还是有一个重要的问题。我可以玩一次。第二次我点击视频分配器(无论是海报或一些播放按钮),它什么都不做。

But now I should say there are still an important issue. I can play it only once. The second time I click on the video dispatcher (either the poster or some play button), it does nothing.

我也想在视频中的WebView框架内的发挥,而不是打开媒体播放器的窗口,但是这对我来说是次要的问题。

I would also like the video to play inside the WebView frame, instead of opening the Media Player window, but this is for me a secondary issue.

我希望它可以帮助别人,而我也感谢任何意见或建议。

I hope it helps somebody, and I would also thank any comment or suggestion.

Saludos,terrícolas。

这篇关于的WebView和HTML5&LT;视频&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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