1

I'm trying to give an option to the user to play video in MX Player but seems like it just opens the app instead of actually playing the video, so can someone help me out here, please?

My Code:


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
        }
    }
}
Bashir
  • 2,057
  • 5
  • 19
  • 44
Meggan Sam
  • 319
  • 1
  • 4
  • 17

2 Answers2

0

try to create intent by calling new Intent(Intent.ACTION_VIEW)

Here is the corrected code :

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
        }
    }
}
TheKarlo95
  • 1,144
  • 9
  • 17
Nilay Dani
  • 896
  • 6
  • 24
-1

Final answer works for me, hope it helps

Intent intent;

PackageManager packageManager=getPackageManager();
intent=new Intent(packageManager.getLaunchIntentForPackage("com.mxtech.videoplayer.pro").ACTION_VIEW);              
Zahra
  • 2,231
  • 3
  • 21
  • 41
JxClarynx
  • 1
  • 1