Mobile Audio 11--Music Playback page

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.