Android通过意图播放视频

问题描述:

我创建了自己的媒体播放器应用程序并安装在设备中。 我创建了一个只有一个按钮的应用程序,只要我点击按钮。我应该给出一个选项,让玩家可以播放视频。Android通过意图播放视频

我的媒体播放器应用程序的清单文件:

<application 
    android:allowBackup="true" 
    android:icon="@drawable/ic_launcher" 
    android:label="@string/app_name" 
    android:theme="@style/NoActionBar" > 
    <activity 
     android:name="com.example.player.MainPlayerActivity" 
     android:label="@string/app_name" > 
     <intent-filter> 
      <action android:name="android.intent.action.MAIN" /> 

      <category android:name="android.intent.category.LAUNCHER" /> 
     </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="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" /> 
      <data android:mimeType="video/x-ms-wmv" /> 
      <data android:mimeType="video/x-msvideo" /> 
      <data android:mimeType="video/mpeg" /> 
     </intent-filter> 
     <intent-filter> 
      !-- HTTP live support --> 
      <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: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> 
</application> 

示例代码抛出一个意图:

public class MainActivityHsl extends Activity { 
private String url = "/sdcard/vid.mp4"; 

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.activity_main_activity_hsl); 


    Button button = (Button) findViewById(R.id.button1); 

    button.setOnClickListener(new OnClickListener() { 

     @Override 
     public void onClick(View view) { 

      playVideo(MainActivityHsl.this, Uri.parse("/sdcard/vid.mp4"), "SUKESH"); 
     } 
    }); 
} 

public void playVideo(Activity activity, Uri uri, String title) { 

    Intent intent = new Intent(Intent.ACTION_VIEW) 
    .setDataAndType(uri, "video/mp4"); 
    intent.putExtra(Intent.EXTRA_TITLE, title); 
    activity.startActivity(intent); 
}} 

的logcat:

E/AndroidRuntime(1552):机器人。 content.ActivityNotFoundException:未发现处理Intent的活动{act = android.intent.action.VIEW dat =/sdcard/vid.mp4 typ = video/mp4(有额外功能)} E/AndroidRuntime(1552):at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) E/AndroidRuntime(1552):android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512) E/AndroidRuntime (1552):在android.app.Activity.startActivityForResult(Activity.java:3190) E/AndroidRuntime(1552):在android.app.Activity.startActivity(Activity.java:3297) E/AndroidRuntime(1552): E/AndroidRuntime(1552):at com.example.videohsltest.MainActivityHsl $ 1.onClick(MainActivityHsl.java:30) E/AndroidRuntime(1552)在com.example.videohsltest.MainActivityHsl.playVideo(MainActivityHsl.java:54) E/:at android.view.View.performClick(View.java:3511) E/AndroidRuntime(1552):at android.view.View.onKeyUp(View.java:6073)E/AndroidRuntime(1552):at android.view.KeyEvent.dispatch(KeyEvent.java:2575) E/AndroidRuntime(1552):android.widget.TextView.onKeyUp(TextView.java:5586) E/AndroidRuntime (1552):在android.view.View.dispatchKeyEvent(View.java:5500) E/AndroidRuntime(1552):在android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246) E/AndroidRuntime(1552):在Android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246) E/AndroidRuntime(1552):at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246) E/AndroidRuntime(1552):at android.view .ViewGroup.dispatchKeyEvent(ViewGroup.java:1246) E/AndroidRuntime(1552):在com.android.internal.policy.impl.PhoneWindow $ DecorView.superDispatchKeyEvent(PhoneWindow.java:1879) E/AndroidRuntime(1552):at com.android.internal.policy.impl.PhoneWindow.superDispatchKeyEvent(PhoneWindow.java:1361) E/AndroidRuntime(1552):at android.app.Activity.dispatchKeyEvent(Activity.java: 2324) E/AndroidRuntime(1552):at com.android.internal.policy.impl.PhoneWindow $ DecorView.dispatchKeyEvent(PhoneWindow.java:1806) E/AndroidRuntime(1552):at android.view.ViewRootImpl.deliverKeyEventPostIme( E/AndroidRuntime(1552):android.view.ViewRootImpl.handleMessage(ViewRootImpl.java: 2460) E/AndroidRuntime(1552):at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(1552):at android.os.Looper.loop(Looper.java:137)E/AndroidRuntime(1552):at java.lang.reflect.Method.invokeNative(Native Method) E/AndroidRuntime(1552):android.app.ActivityThread.main(ActivityThread.java:4424) E/AndroidRuntime 1552):at java.lang.reflect.Method.invoke(Method.java:511) E/AndroidRuntime(1552):at com.android.internal.os.ZygoteInit $ MethodAndArgsCaller.run(ZygoteInit.java:784) E/AndroidRuntime(1552):在com.android.internal.os.ZygoteInit.main(ZygoteInit。Java的:551) E/AndroidRuntime(1552):在dalvik.system.NativeStart.main(本机方法) W/ActivityManager(203):强制完成活动com.example.videohsltest/.MainActivityHsl

灿任何人都可以帮我解决这个问题,我无法使用弹出的对话框启动完整的操作。这可能是什么原因?提前致谢。

这就是Dolphin Player这样做。

<activity android:name="com.example.player.MainPlayerActivity"" android:label="@string/app_name" 
       android:configChanges="orientation|keyboardHidden" 
        android:screenOrientation="landscape"> 
        <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:mimeType="video/*" /> 
    <data android:mimeType="application/x-quicktimeplayer*" /> 
    <data android:mimeType="application/x-mpeg" /> 
    <data android:mimeType="application/vnd.dvd*" /> 
    <data android:mimeType="application/vnd.3gp*" /> 
    <data android:mimeType="application/3gpp*" /> 
    <data android:mimeType="application/vnd.rn-realmedia*" /> 
    <data android:mimeType="application/mp4*" /> 
    <data android:mimeType="application/mpeg*" /> 
    <data android:mimeType="application/sdp" /> 
    <data android:mimeType="application/vnd.wap.mms-message" /> 

    <data android:pathPattern=".*mkv" /> 
    <data android:pathPattern=".*MKV" /> 

    <data android:pathPattern=".*flv" /> 
    <data android:pathPattern=".*FLV" /> 

    <data android:pathPattern=".*wmv" /> 
    <data android:pathPattern=".*WMV" /> 

    <data android:pathPattern=".*ts" /> 
    <data android:pathPattern=".*TS" /> 

    <data android:pathPattern=".*rm" /> 
    <data android:pathPattern=".*RM" /> 

    <data android:pathPattern=".*rmvb" /> 
    <data android:pathPattern=".*RMVB" /> 

    <data android:pathPattern=".*webm" /> 
    <data android:pathPattern=".*WEBM" /> 

    <data android:pathPattern=".*mov" /> 
    <data android:pathPattern=".*MOV" /> 

    <data android:pathPattern=".*mpg" /> 
    <data android:pathPattern=".*MPG" /> 

    <data android:pathPattern=".*dat" /> 
    <data android:pathPattern=".*DAT" /> 

    <data android:pathPattern=".*vstream" /> 
    <data android:pathPattern=".*VSTREAM" /> 

    <data android:pathPattern=".*mpeg" /> 
    <data android:pathPattern=".*MPEG" /> 

    <data android:pathPattern=".*f4v" /> 
    <data android:pathPattern=".*F4V" /> 

    <data android:pathPattern=".*avi" /> 
    <data android:pathPattern=".*AVI" /> 

    <data android:pathPattern=".*ogv" /> 
    <data android:pathPattern=".*OGV" /> 

    <data android:pathPattern=".*dv" /> 
    <data android:pathPattern=".*DV" /> 

    <data android:pathPattern=".*divx" /> 
    <data android:pathPattern=".*DIVX" /> 

    <data android:pathPattern=".*vob" /> 
    <data android:pathPattern=".*VOB" /> 

    <data android:pathPattern=".*asf" /> 
    <data android:pathPattern=".*ASF" /> 

    <data android:pathPattern=".*3gp" /> 
    <data android:pathPattern=".*3GP" /> 

    <data android:pathPattern=".*3gpp" /> 
    <data android:pathPattern=".*3GPP" />  

    <data android:pathPattern=".*h264" /> 
    <data android:pathPattern=".*H264" /> 

    <data android:pathPattern=".*h261" /> 
    <data android:pathPattern=".*H261" /> 

    <data android:pathPattern=".*h263" /> 
    <data android:pathPattern=".*H263" /> 
    </intent-filter> 
    </activity> 

您可以删除播放器不支持的不必要的媒体格式。

+0

感谢您的回复,我已添加到我的媒体播放器中,但我无法启动它。它正在返回相同的异常 – user1948220 2013-04-04 10:00:21

+0

您是否可以添加此意图过滤器并删除所有其他过滤器并再试一次? – asloob 2013-04-04 10:01:32

+0

它正在返回相同的异常。 – user1948220 2013-04-04 10:06:28