接收binder的service

private static final String TAG = "MediaService";
private MyBinder mMyBinder = new MyBinder();
private MediaPlayer mMediaPlayer;

@Override
public IBinder onBind(Intent arg0) {
// TODO Auto-generated method stub
Log.d(TAG,"onBind()");
        mMediaPlayer.start();
       
return mMyBinder;
}

    @Override 
    public boolean onUnbind(Intent intent) { 
        Log.e(TAG, "start onUnbind~~~"); 
        return super.onUnbind(intent); 
    } 
   
@Override 
    public void onCreate() { 
        Log.e(TAG, "start onCreate~~~"); 
        super.onCreate();
        mMediaPlayer = MediaPlayer.create(MediaService.this, R.raw.yijianmei);

    } 
     
    @Override 
    public void onStart(Intent intent, int startId) { 
        Log.e(TAG, "start onStart~~~"); 
        //super.onStart(intent, startId);
    } 
     
    @Override 
    public void onDestroy() { 
        Log.e(TAG, "start onDestroy~~~"); 
        super.onDestroy(); 
    } 
      
    public String getSystemTime(){ 
        Time t = new Time(); 
        t.setToNow(); 
        return t.toString(); 
    } 
   
    public void stopPlay(){
    mMediaPlayer.stop();
    }
   
    public void seekto(int msec){
    mMediaPlayer.seekTo(msec);
    }

public class MyBinder extends Binder{
public MediaService getService(){
return MediaService.this;
}
}

你可能感兴趣的:(service)