Reputation: 780
i think a simple question but i did not find anything about doing it right.
I want to start a mediaplayer from my app and send that player a file to play(stream).
Would be nice to automatically choose the player associated with the mime type of the file i process to the player.
The only way to start an app is this one. But i wonder if there is a android native way.
Runtime r = Runtime.getRuntime();
try {
if(child != null) {
child.destroy();
child = null;
}
child = r.exec("player");
} catch (Exception e) {
Log.e(TAG, "error: " + e.getMessage(), e);
}
thanks
Upvotes: 1
Views: 384
Reputation: 4152
Launching other applications in Android is a bit weird, at least in my opinion. You generally do that by creating an Intent
object and passing it to Context.startActivity()
. Depending on what you know about the other app etc. you can specify a class that is to be launched or let Android determine what to run for you by providing some other, let's say "less concrete" information.
You probably want to read the Developer guide on Intents and Intent filters and also the documentation of the class Intent
, especially the explanation of explicit and implicit Intents.
Upvotes: 0
Reputation: 1007544
Please do not use the code you have listed above on Android.
You will need to create an ACTION_VIEW
Intent describing the path to the file, along with its MIME type. Then, call startActivity()
on that Intent
. With luck, there will be an application on the device capable of playing that file.
Upvotes: 3