帮我格式化上面的代码
时间: 2023-08-06 22:26:25 浏览: 38
好的,以下是格式化后的代码:
```
private Button startButton;
private Button pauseButton;
private SeekBar seekbar;
private boolean isBound = false;
private PlayService playService;
private static final String TAG = "MusicActivity";
private final int MUSICDURATION = 0x1;
private final int UPDATE = 0x2;
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.start_button:
playService.start();
break;
case R.id.pause_button:
playService.pause();
break;
}
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
if(fromUser) {
playService.setTo(progress);
}
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
private ServiceConnection connection = new ServiceConnection() {
@Override
public void onServiceConnected(ComponentName name, IBinder service) {
PlayBinder binder = (PlayBinder) service;
playService = binder.getPlayService();
isBound = true;
}
@Override
public void onServiceDisconnected(ComponentName name) {
playService = null;
isBound = false;
}
};
@Override
protected void onStart() {
super.onStart();
Intent intent = new Intent(this, PlayService.class);
bindService(intent, connection, BIND_AUTO_CREATE);
}
@Override
protected void onStop() {
super.onStop();
if(isBound) {
unbindService(connection);
isBound = false;
}
}
class PlayBinder extends Binder {
public PlayService getPlayService() {
return PlayService.this;
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_music);
startButton = findViewById(R.id.start_button);
pauseButton = findViewById(R.id.pause_button);
seekbar = findViewById(R.id.seekbar);
startButton.setOnClickListener(this);
pauseButton.setOnClickListener(this);
seekbar.setOnSeekBarChangeListener(this);
}
```
相关推荐
![xml](https://img-home.csdnimg.cn/images/20210720083646.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)