I have built a small remote control service in my app to control the default music player from within my app. I can play, pause, skip and move backwards using the method
private void remoteControl(String CMD) {
Intent i = new Intent("com.android.music.musicservicecommand");
i.putExtra("command", CMD);
getActivity().sendBroadcast(i);
}
and the following commands.
public static final String CMDTOGGLEPAUSE = "togglepause";
public static final String CMDPREVIOUS = "previous";
public static final String CMDNEXT = "next";
public static final String CMDNAME = "command";
public static final String CMDSTOP = "stop";
public static final String CMDPLAY = "play";
and in my manifest I have this permission
<uses-permission android:name="android.permission.WAKE_LOCK"/>
At the moment if my music player is running or is available in the task manager I can use all the controls. However if the user hasn't started the music player process it doesn't work. Is there anyway I can force the music player to start playing even if the process hasn't previously been started without leaving my app.
You apparently can't - reason being that the music player is not required to provide a service for reasons outlined here : Android: Launch music player service from application