Android Play video through intent
I created my own media player application and install in a device. I created an other application which has a single button, As soon as i click on button. I should give an option in which player it should play the video.
Manifest file of my media player application:
<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>
Sample Code for raising an Intent:
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: No Activity found to handle Intent { act=android.intent.action.VIEW dat=/sdcard/vid.mp4 typ=video/mp4 (has extras) } E/AndroidRuntime( 1552): at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1512) E/AndroidRuntime( 1552): at android.app.Instrumentation.execStartActivity(Instrumentation.java:1384) E/AndroidRuntime( 1552): at android.app.Activity.startActivityForResult(Activity.java:3190) 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(View.java:3511) E/AndroidRuntime( 1552): at android.view.View.onKeyUp(View.java:6073) E/AndroidRuntime( 1552): at android.widget.TextView.onKeyUp(TextView.java:5586 ) E/AndroidRuntime( 1552): at android.view.KeyEvent.dispatch(KeyEvent.java:2575) E/AndroidRuntime( 1552): at android.view.View.dispatchKeyEvent(View.java:5500) 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): at 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): at a ndroid.view.ViewRootImpl.deliverKeyEventPostIme(ViewRootImpl.java:3327) E/AndroidRuntime( 1552): at android.view.ViewRootImpl.handleFinishedEvent(ViewRootImpl.java:3300) E/AndroidRuntime( 1552): at 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 android.app.ActivityThread.main(ActivityThread.java:4424) E/AndroidRuntime( 1552): at java.lang.reflect.Method.invokeNative(Native Method) 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): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:551) E/AndroidRuntime( 1552): at dalvik.system.NativeStart.main(Native Method) W/ActivityManager( 203): Force finishing activity com.example.videohsltest/ .MainActivityHsl
Can Any one please help me out of this, i am not able to launch the complete action using dialog pop up. What is the reason it may be. Thanks in Advance.
This is how Dolphin Player does it.
<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>
You can remove the unnecessary media formats that your player does not support.
链接地址: http://www.djcxy.com/p/18352.html上一篇: 在完成之前,android sdk能够释放你的内存吗?
下一篇: Android通过意图播放视频