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):android.content.ActivityNotFoundException:未发现处理Intent的行为{act = android.intent.action.VIEW dat = / sdcard / vid.mp4 typ = video / mp4(有额外)} E / AndroidRuntime (1552):在android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512)E / AndroidRuntime(1552):在android.app.Instrumentation.execStartActivity(Instrumentation.java:1384)E / AndroidRuntime(1552):在android E / AndroidRuntime(1552):at android.app.Activity.startActivity(Activity.java:3297)E / AndroidRuntime(1552):at com.example.videohsltest.MainActivityHsl .playVideo(MainActivityHsl.java:54)E / AndroidRuntime(1552):at com.example.videohsltest.MainActivityHsl $ 1.onClick(MainActivityHsl.java:30)E / AndroidRuntime(1552):at android.view.View.performClick( E / AndroidRuntime(1552):在android.widget.TextView.onKeyUp(TextView.java:5586):在android.view.onKeyUp(View.java:6073) )E / AndroidRuntime(1552):在android.view.KeyEvent.dispatch(KeyEvent.java:2575)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):在android.view .ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)E / AndroidRuntime(1552):at android.view.ViewGroup.dispatchKeyEvent(ViewGroup.java:1246)E / AndroidRuntime(1552):at 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):在...处 ndroid.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3327)E / AndroidRuntime(1552):在android.view.ViewRootImpl.handleFinishedEvent(ViewRootImpl.java:3300)E / AndroidRuntime(1552):在android.view.ViewRootImpl。在Android.os.Handler.dispatchMessage(Handler.java:99)E / AndroidRuntime(1552):在android.os.Looper.loop(Looper.java: 137)E / AndroidRuntime(1552):在android.app.ActivityThread.main(ActivityThread.java:4424)E / AndroidRuntime(1552):在java.lang.reflect.Method.invokeNative(本地方法)E / AndroidRuntime(1552) ):在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):at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551)E / AndroidRuntime(1552):at dalvik.system.NativeStart.main(Native Method)W / ActivityManager(203):Force整理活动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>
您可以删除播放器不支持的不必要的媒体格式。
链接地址: http://www.djcxy.com/p/18351.html