如何在android中使用intent播放我的视频文件

时间:2014-11-19 15:41:58

标签: android android-intent android-video-player

如果安装了mx播放器,如果我安装了没有应用程序将会列出并显示(我的手机中有我的默认播放器),此代码有效。例外:没有找到处理Intent的活动{act = android.intent.action.VIEW in逻辑

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 个答案:

答案 0 :(得分:3)

谢谢大家的答案

得到了解决方案

         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());
            }

答案 1 :(得分:1)

<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();
}
}

来源:Follow this link

答案 2 :(得分:0)

在开始新Intent之前,请检查是否有Activity来处理:{/ p>

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

请参阅android开发者文档here