标签:并且 pac string bind intent new http music get

1_创建服务MusicPlayerService.java,基于此类改成IMusicPlayerService.aidl,名字一定要改
在Android studio创建aidl文件,识别时要编译一下
public class MusicPlayerService extends Service {
@Override
public void onCreate() {
super.onCreate();
}
/**
* 根据位置打开一个音频并且播放
*
* @param position
*/
public void openAudio(int position) {
/**
* 开始播放音频
*/
public void start() {
}
/**
* 暂停
*/
public void pause() {
}
/**
* 得到歌曲的名称
*/
public String getAudioName() {
return "";
}
/**
* 得到歌曲演唱者的名字
*/
public String getArtistName() {
return "";
}
/**
* 得到歌曲的当前播放进度
*/
public int getCurrentPosition() {
return 0;
}
/**
* 得到歌曲的当前总进度
*/
public int getDuration() {
return 0;
}
/**
* 播放下一首歌曲
*/
public void next() {
}
/**
* 播放上一首歌曲
*/
public void pre() {
}
/**
* 得到播放模式
*/
public int getPlayMode() {
return 0;
}
/**
* 设置播放模式
*/
public void setPlayMode(int mode) {
}
@Override
public IBinder onBind(Intent intent) {
return 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
return service.getPlayMode();
}
@Override
public int getDuration() throws RemoteException {
// TODO Auto-generated method stub
return 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
return service.getAudioName();
}
@Override
public String getArtistName() throws RemoteException {
// TODO Auto-generated method stub
return service.getArtistName();
}
};
}
2_AIDL文件把方法体去掉
package com.atguigu.mobileplayer.audio;
interface IMusicPlayerService {
/**
* 根据位置打开一个音频并且播放
* @param position
*/
void openAudio(int position);
/**
* 开始播放音频
*/
void start();
/**
* 暂停
*/
void pause();
/**
* 停止
*/
void stop();
/**
* 得到歌曲的名称
*/
String getAudioName();
/**
* 得到歌曲演唱者的名字
*/
String getArtistName();
/**
* 得到歌曲的当前播放进度
*/
int getCurrentPosition();
/**
* 得到歌曲的当前总进度
*/
int getDuration();
/**
* 播放下一首歌曲
*/
void next();
/**
* 播放上一首歌曲
*/
voidpre();
/**
* 得到播放模式
*/
int getPlayMode();
/**
* 设置播放模式
*/
void setPlayMode(int mode);
}
标签:并且 pac string bind intent new http music get
原文地址:http://www.cnblogs.com/ganchuanpu/p/6078727.html