Question

How to intent to system media application?

Because I want to play the video in my application by using system media application.

I trying the following code, but not successfully.

    url = "http://www.ooklnet.com/files/381/381489/video.mp4";
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    intent.addCategory(Intent.CATEGORY_APP_MUSIC);
    startActivity(intent);

But when i trying the following code, it is successfull,

    url = "http://www.ooklnet.com/files/381/381489/video.mp4";
    Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
    startActivity(intent);

However, It needs me to open two steps:

  • First step is show the dialog (Android System & Browser) to choose.

  • Second step : when I choose Android System, it shows the applications can play this video.

I want to press "Play" button, it will run by using system media application,

Please tell me how,

UPDATE after receive the answer from CommonWare :

I can use the following code to intent exactly the system media app guy.

// String type = "audio/mpeg4-generic"; // It works for only Mobo Player
String type = "video/mp4"; // It works for all video application

Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
intent.setDataAndType(Uri.parse(url), type);
startActivity(intent);

My device has existed third media application (Mobo Player, MX Player and Video), The Video application is the system media app, so we can not uninstall it in the Settings.

p/s : I use Android version 2.2.1,

Thanks,

Was it helpful?

Solution

I trying the following code, but not successfully.

There is no activity on your system that both can play a video and is a music player.

First step is show the dialog (Android System & Browser) to choose.

The user can display this video in whatever application they want.

Second step : when I choose Android System, it shows the applications can play this video.

Presumably, that is occurring sometime after the URL has been downloaded or something. You might try using setDataAndType(), supplying the proper MIME type, to streamline this a bit.

I want to press "Play" button, it will run by using system media application,

There is no "system media application". A device may have zero, one, or several applications capable of playing a video from a URL. Those applications can be pre-installed or installed by the user. When you request to play a video using ACTION_VIEW, the OS and the user will decide which application will play the video.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top