在web视图打开视频播放器? [英] Open video player in webview?

查看:155
本文介绍了在web视图打开视频播放器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Web应用程序均与web视图。在这些网页我有一些链接到视频(MP4,3GP ...)。 当我点击链接,没有什么happend?有人可以helpme有关这个案子的?

I've an WebApp showed with Webview. In those pages I've some links to videos (MP4, 3GP...). When I click on the link, nothing happend ? Can somebody helpme about this case ?

public class luxgateway extends Activity {

WebView myWebView;
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);     

    myWebView = (WebView) findViewById(R.id.webview);
    myWebView.getSettings().setJavaScriptEnabled(true);
    myWebView.getSettings().setAllowFileAccess(true); 

    WebViewClient webViewClient = new MyWebViewClient();
    myWebView.setWebViewClient(webViewClient);

    myWebView.loadUrl("http://www.XXX.com/demo.html");
}

public boolean onKeyDown(int keyCode, KeyEvent event) {
    if ((keyCode == KeyEvent.KEYCODE_BACK) && myWebView.canGoBack()) {
        myWebView.goBack();
        return true;
    }
    return super.onKeyDown(keyCode, event);
}

private class MyWebViewClient extends WebViewClient {
    public boolean shouldOverrideUrlLoading(WebView view, String url) {
        if (url.endsWith(".3gp")) {
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
            view.getContext().startActivity(intent);    
            return true;
        } else {
            return super.shouldOverrideUrlLoading(view, url);
        }
    }
}

我发现在此服务器上的此code某些部分,但它一点儿也不帮我。

I've found some parts on this code on this server, but it does'nt help me.

        if (url.endsWith(".3gp")) {
            Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
            view.getContext().startActivity(intent);    
            return true;
        } else {
            return super.shouldOverrideUrlLoading(view, url);
        }

在这种情况下,我仅限于3GP文件,但I'don't知道哪些扩展将放在本网站上。

In this case I'm limited to 3GP files, but I'don't know which extension will be place on the WEBsite.

我trye​​d这code thisout测试,只能看视频,可以播放(或录像机开始只有这code

I've tryed this code thisout the test, only to see if the video could be played (or videoplayer start with only this code

                Intent intent = new Intent("android.intent.action.VIEW", Uri.parse(url));
            view.getContext().startActivity(intent);    
            return true;

在此情况下,视频仅dowloaded。我想有样品互动为webrowser。当我点击视频链接,浏览器要求至极球员,我想用户对这部影片。

In this case, the video is only dowloaded. I want to have the sample interaction as the webrowser. When I click on the video link, the browser ask wich player I want to user for this video.

感谢的对你有所帮助。

推荐答案

您可能有更好的运气,如果你指定的URI包含视频:

You may have better luck if you specify that the uri contains video:

Intent intent = new Intent(Intent.ACTION_VIEW) //I encourage using this instead of specifying the string "android.intent.action.VIEW"
intent.setDataAndType(Uri.parse(url), "video/3gpp");
view.getContext().startActivity(intent);  

由于我们没有指定一个特定的包来处理上述意图,它被称为一个隐含的意图。对于隐含的意图,如果有多个包处理您指定的内容类型,你会被要求在它们之间做出选择。这应该给你你想要的行为。

Because we haven't specified a specific package to handle the above intent, it is called an implicit intent. For implicit intents, if there are multiple packages that handle the content type that you specify, you will be asked to choose between them. This should give you your desired behavior.

这篇关于在web视图打开视频播放器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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