How can i play my video files using intent in android

7k Views Asked by At

This code works if mx player is installed if i uninstalled no application will be listed and showing(i have my default player in my phone) EXCEPTION : No Activity found to handle Intent { act=android.intent.action.VIEW in the logical

try {
    Intent mVideoWatch = new Intent(Intent.ACTION_VIEW);
    mVideoWatch.setDataAndType(Uri.parse(mVideosPath[i]), "video/*");
    startActivity(mVideoWatch);
}
catch(Exception e) {
    Log.e(TAG,e.getMessage());
}
3

There are 3 best solutions below

0
On BEST ANSWER

Thank you everyone for your answers

Got the solution

         try {
                mVideosPath[i] = "file://"+mVideosPath[i];
                  // mVideosPath[i] = /storage/emulated/0/Movies/test.mp4 

                Intent mVideoWatch = new Intent(Intent.ACTION_VIEW);
                mVideoWatch.setDataAndType(Uri.parse(mVideosPath[i]),mVideostype[i]);
                startActivity(mVideoWatch);
            }
            catch(Exception e)
            {
                Log.e(TAG,e.getMessage());
            }
0
On
<activity android:configChanges="keyboardHidden|orientation|screenSize"  android:label="@string/movie_view_label" android:name="com.android.gallery3d.app.MovieActivity">
<intent-filter>
   <action android:name="android.intent.action.VIEW"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <data android:scheme="rtsp"/>
</intent-filter>
<intent-filter>
  <action android:name="android.intent.action.VIEW"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <data android:scheme="http"/>
  <data android:scheme="https"/>
  <data android:scheme="content"/>
  <data android:scheme="file"/>
  <data android:mimeType="video/mpeg4"/>
  <data android:mimeType="video/mp4"/>
  <data android:mimeType="video/3gp"/>
  <data android:mimeType="video/3gpp"/>
  <data android:mimeType="video/3gpp2"/>
  <data android:mimeType="video/webm"/>
  <data android:mimeType="video/avi"/>
  <data android:mimeType="application/sdp"/>
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW"/>
  <category android:name="android.intent.category.DEFAULT"/>
  <category android:name="android.intent.category.BROWSABLE"/>
  <data android:scheme="http"/>
  <data android:scheme="https"/>
  <data android:mimeType="audio/x-mpegurl"/>
  <data android:mimeType="audio/mpegurl"/>
  <data android:mimeType="application/vnd.apple.mpegurl"/>
  <data android:mimeType="application/x-mpegurl"/>
 </intent-filter>
 </activity>



/**
 * This method is called when the user clicks the button to play the toady's 
 * special video
 */
 public void playVideo(View view) {
File videoFile = new File (
    videoPath+"/today_special.mp4");
if (videoFile.exists()) {
    Uri fileUri = Uri.fromFile(videoFile);
  Intent intent = new Intent();
  intent.setAction(Intent.ACTION_VIEW);
  intent.setDataAndType(fileUri,                
        URLConnection.guessContentTypeFromName(fileUri.toString()));
  startActivity(intent);
} else {
    Toast.makeText(this, "Video file does not exist", 
        Toast.LENGTH_LONG).show();
}
}

Source: Follow this link

0
On

Before starting a new Intent, check to see if there is an Activity to handle that:

PackageManager packageManager = getPackageManager();
List<ResolveInfo> activities = packageManager.queryIntentActivities(intent, 0);
boolean isIntentSafe = activities.size() > 0;
if( isIntentSafe) {
    startActivity(intent)
}

See android developers docs here.