MX Player打开而不是通过Intent播放视频

时间:2019-08-19 10:16:58

标签: java android

我正在尝试给用户一个选项,使其可以在MX Player中播放视频,但似乎只是打开应用程序而不是实际播放视频,所以有人可以在这里帮助我吗?

我的代码:


                        String videoStreamUrl = null;
                                Intent intent;

                                if (type.equals("movie")) {
                                    if (listDirector.get(0).getStremURL() != null) {
                                        videoStreamUrl = commonVideoUrl;
                                    }
                                }else{
                                    videoStreamUrl = commonVideoUrl;
                                }
                                if(videoStreamUrl!=null) {
                                    PackageManager packageManager=getPackageManager();
                                    try {
                                        intent= packageManager.getLaunchIntentForPackage("com.mxtech.videoplayer.pro");
                                        if (null != intent)
                                            intent.setDataAndType(Uri.parse(videoStreamUrl), "video/*");
                                        startActivity(intent);
                                    }
                                    catch (ActivityNotFoundException e) {
                                        //MX Player pro isn't installed
                                        try{
                                            intent= packageManager.getLaunchIntentForPackage("com.mxtech.videoplayer.ad");
                                            if (null != intent)
                                                intent.setDataAndType(Uri.parse(videoStreamUrl), "video/*");
                                            startActivity(intent);
                                        }
                                        catch (ActivityNotFoundException er) {
                                            //No version of MX Player is installed.You should let the user know
                                        }
                                    }
                                }

2 个答案:

答案 0 :(得分:1)

尝试通过调用new Intent(Intent.ACTION_VIEW)

来创建意图

这是更正的代码:

String videoStreamUrl = null;
Intent intent;

if (type.equals("movie")) {
    if (listDirector.get(0).getStremURL() != null) {
        videoStreamUrl = commonVideoUrl;
    }
} else {
    videoStreamUrl = commonVideoUrl;
}
if(videoStreamUrl!=null) {
    PackageManager packageManager=getPackageManager();
    try {
        intent= new Intent(Intent.ACTION_VIEW);
        intent.setClassName(context,"com.mxtech.videoplayer.pro");
        if (null != intent)
            intent.setDataAndType(Uri.parse(videoStreamUrl), "video/*");
        startActivity(intent);
    }
    catch (ActivityNotFoundException e) {
        //MX Player pro isn't installed
        try{
            intent= new Intent(Intent.ACTION_VIEW);
            intent.setClassName(context,"com.mxtech.videoplayer.ad");
            if (null != intent)
                intent.setDataAndType(Uri.parse(videoStreamUrl), "video/*");
            startActivity(intent);
        }
        catch (ActivityNotFoundException er) {
            //No version of MX Player is installed.You should 
            let the user know
        }
    }
}

答案 1 :(得分:-1)

最终答案对我有用,希望能帮到你?

Intent intent;

PackageManager packageManager=getPackageManager();
intent=new Intent(packageManager.getLaunchIntentForPackage("com.mxtech.videoplayer.pro").ACTION_VIEW);