您现在的位置是:首页 >学无止境 >Android Radio实战——播放/暂停(十)网站首页学无止境
Android Radio实战——播放/暂停(十)
简介Android Radio实战——播放/暂停(十)
1、方法封装
private static final String KEY_PLAYSTATE = "playstate";
private static final int STATE_PAUSE = 0;
private static final int STATE_PLAY = 1;
// 用于管理当前播放状态,获取状态时直接返回
private int mPlayState;
private CarAudioManager mCarAudioManager;
private static final String HARDCODED_TUNER_ADDRESS = "tuner0";
public void setRadioPlayPause(int state) {
if(state = STATE_PAUSE){
setMuted(true);
} else if(state = STATE_PLAY) {
setMuted(false);
}
// 更新播放状态
mPlayState = state;
// 将状态存入到系统
Settings.System.putInt(mContext.getContentResolver(), KEY_PLAYSTATE, mPlayState);
}
public boolean setMuted(boolean muted) {
synchronized (mMuteLock) {
if (mCarAudioManager == null) {
Log.i(TAG, "汽车尚未连接,延迟操作: " + (muted ? "mute" : "unmute"));
return true;
}
if (mRadioTuner ==
风语者!平时喜欢研究各种技术,目前在从事后端开发工作,热爱生活、热爱工作。