packagecom.iceskysl.PlayService;importandroid.app.Service;importandroid.content.Intent;importandroid.media.MediaPlayer;importandroid.os.IBinder;publicclassMusicextendsService{privateMediaPlayerplayer;@OverridepublicIBinderonBind(Intentintent){//TODOAuto-generatedmethodstubreturnnull;}publicvoidonStart(Intentintent,intstartId){super.onStart(intent,startId);player=MediaPlayer.create(this,R.raw.gequ);player.start();}publicvoidonDestroy(){super.onDestroy();player.stop();}}
packagecom.iceskysl.PlayService;importandroid.app.Activity;importandroid.content.Intent;importandroid.os.Bundle;importandroid.view.View;importandroid.view.View.OnClickListener;importandroid.widget.Button;publicclassPlayServiceextendsActivity{/**Calledwhentheactivityisfirstcreated.*/
@OverridepublicvoidonCreate(BundlesavedInstanceState){super.onCreate(savedInstanceState);setContentView(R.layout.main);Buttonbutton1=(Button)findViewById(R.id.start);button1.setOnClickListener(startIt);Buttonbutton2=(Button)findViewById(R.id.stop);button2.setOnClickListener(stopIt);}privateOnClickListenerstartIt=newOnClickListener(){publicvoidonClick(Viewv){startService(newIntent("com.iceskysl.PlayService.START_AUDIO_SERVICE"));}};privateOnClickListenerstopIt=newOnClickListener(){publicvoidonClick(Viewv){stopService(newIntent("com.iceskysl.PlayService.START_AUDIO_SERVICE"));finish();}};}
docin/p-204315267.htmlwenku.baidu/view/191e423c0912a21614792979.html