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

问题描述 投票:0回答:2

我试图为用户提供在 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
        }
    }
}
java android
2个回答
0
投票

尝试通过调用

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
投票

最终答案对我有用,希望有帮助😊

Intent intent;

PackageManager packageManager=getPackageManager();
intent=new Intent(packageManager.getLaunchIntentForPackage("com.mxtech.videoplayer.pro").ACTION_VIEW);              
© www.soinside.com 2019 - 2024. All rights reserved.