下面列出了android.media.RemoteControlClient#PLAYSTATE_PAUSED 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void playbackStateUpdate(int state) {
boolean active;
switch (state) {
case RemoteControlClient.PLAYSTATE_PLAYING:
active = true;
break;
case RemoteControlClient.PLAYSTATE_ERROR:
case RemoteControlClient.PLAYSTATE_PAUSED:
default:
active = false;
break;
}
if (active != mActive) {
mActive = active;
refreshState();
if (DEBUG) log(getKey() + ": playbackStateUpdate("+state+")");
}
}
static int getStateFromPlayState(PlayState playState) {
switch (playState) {
case BUFFERING:
return RemoteControlClient.PLAYSTATE_BUFFERING;
case ERROR:
return RemoteControlClient.PLAYSTATE_ERROR;
case FAST_FORWARDING:
return RemoteControlClient.PLAYSTATE_FAST_FORWARDING;
case PAUSED:
return RemoteControlClient.PLAYSTATE_PAUSED;
case PLAYING:
return RemoteControlClient.PLAYSTATE_PLAYING;
case REWINDING:
return RemoteControlClient.PLAYSTATE_REWINDING;
case SKIPPING_BACKWARDS:
return RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS;
case SKIPPING_FORWARDS:
return RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS;
case STOPPED:
return RemoteControlClient.PLAYSTATE_STOPPED;
default:
return RemoteControlClient.PLAYSTATE_ERROR;
}
}
public boolean wasPlayingRecently() {
switch (mState) {
case RemoteControlClient.PLAYSTATE_PLAYING:
case RemoteControlClient.PLAYSTATE_FAST_FORWARDING:
case RemoteControlClient.PLAYSTATE_REWINDING:
case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS:
case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS:
case RemoteControlClient.PLAYSTATE_BUFFERING:
// actively playing or about to play
return true;
case RemoteControlClient.PLAYSTATE_STOPPED:
case RemoteControlClient.PLAYSTATE_PAUSED:
case RemoteControlClient.PLAYSTATE_ERROR:
return ((SystemClock.elapsedRealtime() - mStateChangeTimeMs) < DISPLAY_TIMEOUT_MS);
default:
LOGE("PlaybackInfo", "Unknown playback state " + mState + " in wasPlayingRecently()");
return false;
}
}
static int getStateFromPlayState(PlayState playState) {
switch (playState) {
case BUFFERING:
return RemoteControlClient.PLAYSTATE_BUFFERING;
case ERROR:
return RemoteControlClient.PLAYSTATE_ERROR;
case FAST_FORWARDING:
return RemoteControlClient.PLAYSTATE_FAST_FORWARDING;
case PAUSED:
return RemoteControlClient.PLAYSTATE_PAUSED;
case PLAYING:
return RemoteControlClient.PLAYSTATE_PLAYING;
case REWINDING:
return RemoteControlClient.PLAYSTATE_REWINDING;
case SKIPPING_BACKWARDS:
return RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS;
case SKIPPING_FORWARDS:
return RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS;
case STOPPED:
return RemoteControlClient.PLAYSTATE_STOPPED;
default:
return RemoteControlClient.PLAYSTATE_ERROR;
}
}
public boolean wasPlayingRecently() {
switch (mState) {
case RemoteControlClient.PLAYSTATE_PLAYING:
case RemoteControlClient.PLAYSTATE_FAST_FORWARDING:
case RemoteControlClient.PLAYSTATE_REWINDING:
case RemoteControlClient.PLAYSTATE_SKIPPING_FORWARDS:
case RemoteControlClient.PLAYSTATE_SKIPPING_BACKWARDS:
case RemoteControlClient.PLAYSTATE_BUFFERING:
// actively playing or about to play
return true;
case RemoteControlClient.PLAYSTATE_STOPPED:
case RemoteControlClient.PLAYSTATE_PAUSED:
case RemoteControlClient.PLAYSTATE_ERROR:
return ((SystemClock.elapsedRealtime() - mStateChangeTimeMs) < DISPLAY_TIMEOUT_MS);
default:
LOGE("PlaybackInfo", "Unknown playback state " + mState + " in wasPlayingRecently()");
return false;
}
}
@Override
public void setPlaybackState(final int state, int index, int queueSize) {
if(mRemoteControl == null) {
return;
}
long position = -1;
if(state == RemoteControlClient.PLAYSTATE_PLAYING || state == RemoteControlClient.PLAYSTATE_PAUSED) {
position = downloadService.getPlayerPosition();
}
mRemoteControl.setPlaybackState(state, position, 1.0f);
}
public void pausePlaying() {
if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
mPlayState = RemoteControlClient.PLAYSTATE_PAUSED;
mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
}
dropAudioFocus();
}
public void pausePlaying() {
if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
mPlayState = RemoteControlClient.PLAYSTATE_PAUSED;
mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
}
dropAudioFocus();
}
public void pausePlaying() {
if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
mPlayState = RemoteControlClient.PLAYSTATE_PAUSED;
mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
}
dropAudioFocus();
}
public void pausePlaying() {
if (mPlayState == RemoteControlClient.PLAYSTATE_PLAYING) {
mPlayState = RemoteControlClient.PLAYSTATE_PAUSED;
mRemoteControl.setPlaybackState(RemoteControlClient.PLAYSTATE_PAUSED);
}
dropAudioFocus();
}
@Override
public void setPlaybackState(int state, int index, int queueSize) {
PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder();
int newState = PlaybackStateCompat.STATE_NONE;
switch(state) {
case RemoteControlClient.PLAYSTATE_PLAYING:
newState = PlaybackStateCompat.STATE_PLAYING;
break;
case RemoteControlClient.PLAYSTATE_STOPPED:
newState = PlaybackStateCompat.STATE_STOPPED;
break;
case RemoteControlClient.PLAYSTATE_PAUSED:
newState = PlaybackStateCompat.STATE_PAUSED;
break;
case RemoteControlClient.PLAYSTATE_BUFFERING:
newState = PlaybackStateCompat.STATE_BUFFERING;
break;
}
long position = -1;
if(state == RemoteControlClient.PLAYSTATE_PLAYING || state == RemoteControlClient.PLAYSTATE_PAUSED) {
position = downloadService.getPlayerPosition();
}
builder.setState(newState, position, 1.0f);
DownloadFile downloadFile = downloadService.getCurrentPlaying();
Entry entry = null;
boolean isSong = true;
if(downloadFile != null) {
entry = downloadFile.getSong();
isSong = entry.isSong();
}
builder.setActions(getPlaybackActions(isSong, index, queueSize));
if(entry != null) {
addCustomActions(entry, builder);
builder.setActiveQueueItemId(entry.getId().hashCode());
}
PlaybackStateCompat playbackState = builder.build();
mediaSession.setPlaybackState(playbackState);
previousState = state;
}