1. Create the service and create the corresponding aidl file
1_ Create service Musicplayerservice.java, based on this class changed to Imusicplayerservice.aidl, the name must be changed
Create a aidl file in Android Studio and compile it when you recognize it
public class Musicplayerservice extends Service {@Override public void onCreate () {super.oncreate (); }/** * Opens an audio based on location and plays * * @param position */public void Openaudio (int position) {/** * start playing audio */PU Blic void Start () {}/** * pauses */public void pause () {}/** * Gets the name of the song */public String getaudioname () { Return ""; }/** * Get the name of the singer */public String Getartistname () {return ""; }/** * Get the current playback progress of the song */public int getcurrentposition () {return 0; }/** * Get the current total progress of the song */public int getduration () {return 0; }/** * Play next song */public void Next () {}/** * Play previous song */public void Pre () {}/** * get playback mode */Public I NT Getplaymode () {return 0; }/** * Set playback mode */public void Setplaymode (int mode) {} @Override public ibinder onbind (Intent Intent) {retur n stub; } imusicplayerservice.stubstub = new Imusicplayerservice.stub () {musicplayerserviceservice = MusicPlayerService.this; @Override public void Stop () throws RemoteException {service.stop (); } @Override public void Start () throws RemoteException {Service.start (); } @Override public void Setplaymode (int mode) throws RemoteException {Service.setplaymode (mode); } @Override public void Pre () throws RemoteException {Service.pre (); } @Override public void Pause () throws RemoteException {Service.pause (); } @Override public void Openaudio (int position) throws RemoteException {Service.openaudio (position); } @Override public void Next () throws RemoteException {Service.next (); } @Override public int getplaymode () throws RemoteException {//TODO auto-generated method stub retur n Service.getplaymode (); } @Override public int getduration () throws RemoteException {//TODO auto-generated method stub retur n Service.getduration (); } @OVerride public int getcurrentposition () throws RemoteException {//TODO auto-generated method stub return Service.getcurrentposition (); } @Override Public String getaudioname () throws RemoteException {//TODO auto-generated method stub R Eturn Service.getaudioname (); } @Override Public String getartistname () throws RemoteException {//TODO auto-generated method stub return Service.getartistname (); } };}
2_aidl file Remove the method body
Package Com.atguigu.mobileplayer.audio;interface Imusicplayerservice { /** * Open an audio based on location and play * @param Position * /void Openaudio (int position); /** * Start playing audio * /void Start (); /** * Pause * /Void pause (); /** * Stop * /Void Stop (); /** * Get the name of the song * * String getaudioname (); /** * Get the name of the song singer * /String getartistname (); /** * Get the current playback progress of the song * /int getcurrentposition (); /** * Get the current total progress of the song * /int getduration (); /** * Play next song * /void Next (); /** * Play previous song * /Voidpre (); /** * Get playback mode * /int getplaymode (); /** * Set playback mode * /void Setplaymode (int mode);
Mobile Audio 11--Music Playback page