我想在后台播放媒体播放器。还想在 android 的主要活动中播放、停止、暂停、下一个进程吗?有人有想法吗?
问问题
289 次
1 回答
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();
}
}
于 2012-09-11T08:59:24.967 回答