Android Radio实战——播放/暂停(十)

一、功能实现

方法封装

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 (mRadioT

猜你喜欢

转载自blog.csdn.net/c19344881x/article/details/130752108
今日推荐