2012-09-11 83 views

回答

0
public class MusicService extends Service { 

    private static final String TAG = "MyService"; 
    public static MediaPlayer mediaplayer; 
    String musicfile; 

    @Override 
    public IBinder onBind(Intent intent) { 
     Log.i(" ibinder ", ""); 
     return null; 
    } 

    @Override 
    public void onCreate() { 
     // Toast.makeText(this, "My Service Created", 0).show(); 
     Log.i(TAG, "onCreate"); 

     mediaplayer = new MediaPlayer(); 
     mediaplayer.setAudioStreamType(AudioManager.STREAM_MUSIC); 
    } 

    @Override 
    public void onDestroy() { 
     Toast.makeText(this, "My Service Stopped", 0).show(); 
     Log.w(TAG, "onDestroy"); 
     mediaplayer.stop(); 
    } 

    @Override 
    public void onStart(Intent intent, int startid) { 
     Toast.makeText(this, 
     "My Service Started :" + intent + " start id :" + startid, 0) 
     .show(); 

     mediaplayer.start(); 

    } 


}