本文整理汇总了Java中android.support.v4.media.session.PlaybackStateCompat.getState方法的典型用法代码示例。如果您正苦于以下问题:Java PlaybackStateCompat.getState方法的具体用法?Java PlaybackStateCompat.getState怎么用?Java PlaybackStateCompat.getState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.media.session.PlaybackStateCompat
的用法示例。
在下文中一共展示了PlaybackStateCompat.getState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: onPlaybackStateUpdate
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
@Override
public void onPlaybackStateUpdate(PlaybackStateCompat playbackState) {
mSession.setPlaybackState(playbackState);
int state = playbackState.getState();
if (state == PlaybackStateCompat.STATE_PLAYING) {
Notification notification = postNotification();
startForeground(NOTIFICATION_ID, notification);
mReceiver.register();
} else {
if (state == PlaybackStateCompat.STATE_PAUSED) {
postNotification();
} else {
mNotificationManager.cancel(NOTIFICATION_ID);
}
stopForeground(false);
mReceiver.unregister();
}
}
示例2: playPause
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
@OnClick(R.id.play_pause)
public void playPause(){
lastState=null;
MediaControllerCompat controllerCompat=MediaControllerCompat.getMediaController(getActivity());
PlaybackStateCompat stateCompat=controllerCompat.getPlaybackState();
if(stateCompat!=null){
MediaControllerCompat.TransportControls controls=
controllerCompat.getTransportControls();
switch (stateCompat.getState()){
case PlaybackStateCompat.STATE_PLAYING:
case PlaybackStateCompat.STATE_BUFFERING:
controls.pause();
break;
case PlaybackStateCompat.STATE_NONE:
case PlaybackStateCompat.STATE_PAUSED:
case PlaybackStateCompat.STATE_STOPPED:
controls.play();
break;
default:
Log.d(TAG, "State "+stateCompat.getState());
}
}
}
示例3: onPlaybackStateChange
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChange(PlaybackStateCompat state) {
// Report the state to the MediaSession.
mSession.setPlaybackState(state);
// Manage the started state of this service.
switch (state.getState()) {
case PlaybackStateCompat.STATE_PLAYING:
mServiceManager.moveServiceToStartedState(state);
break;
case PlaybackStateCompat.STATE_PAUSED:
mServiceManager.updateNotificationForPause(state);
break;
case PlaybackStateCompat.STATE_STOPPED:
mServiceManager.moveServiceOutOfStartedState(state);
break;
}
}
示例4: onPlaybackStateChanged
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
playbackState = state;
if (extras != state.getExtras()) {
extras = state.getExtras();
updateTrackFromExtras();
}
if (state.getState() == PlaybackStateCompat.STATE_ERROR) {
isSeeking = false;
onFailed();
} else if (state.getState() == PlaybackStateCompat.STATE_PLAYING) {
isSeeking = false;
updateRecordPlayedState();
updatePlayerView(false);
} else if (state.getState() != PlaybackStateCompat.STATE_REWINDING) {
isSeeking = false;
updatePlayerView(true);
}
}
示例5: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updatePlaybackState(PlaybackStateCompat state) {
mCurrentState = state;
if (state == null
|| state.getState() == PlaybackStateCompat.STATE_PAUSED
|| state.getState() == PlaybackStateCompat.STATE_STOPPED) {
mPlayPause.setImageDrawable(
ContextCompat.getDrawable(this, R.drawable.ic_play_arrow_black_36dp));
} else {
mPlayPause.setImageDrawable(
ContextCompat.getDrawable(this, R.drawable.ic_pause_black_36dp));
}
mPlaybackControls.setVisibility(state == null ? View.GONE : View.VISIBLE);
}
示例6: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updatePlaybackState(PlaybackStateCompat state) {
mCurrentState = state;
if (state == null
|| state.getState() == PlaybackState.STATE_PAUSED
|| state.getState() == PlaybackState.STATE_STOPPED) {
mPlayPause.setImageDrawable(
ContextCompat.getDrawable(this, R.drawable.ic_play_arrow_black_36dp));
} else {
mPlayPause.setImageDrawable(
ContextCompat.getDrawable(this, R.drawable.ic_pause_black_36dp));
}
mPlaybackControls.setVisibility(state == null ? View.GONE : View.VISIBLE);
}
示例7: onPlaybackStateChanged
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
mPlaybackState = state;
Log.i(TAG, "onPlaybackStateChanged: received new play state : " + state);
if (state.getState() == PlaybackStateCompat.STATE_STOPPED ||
state.getState() == PlaybackStateCompat.STATE_NONE) {
stopNotification();
} else {
Notification notification = buildNotification();
if (notification != null) {
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
}
}
示例8: onPlaybackStateChanged
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(@NonNull PlaybackStateCompat state) {
mPlaybackState = state;
if (state.getState() == PlaybackStateCompat.STATE_STOPPED ||
state.getState() == PlaybackStateCompat.STATE_NONE) {
stopNotification();
} else {
Notification notification = createNotification();
if (notification != null) {
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
}
}
开发者ID:AllThatSeries,项目名称:react-native-streaming-audio-player,代码行数:14,代码来源:MediaNotificationManager.java
示例9: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
public void updatePlaybackState(PlaybackStateCompat playbackState){
this.playbackState=playbackState;
if(playbackState.getState()==PlaybackStateCompat.STATE_STOPPED||
playbackState.getState()==PlaybackStateCompat.STATE_NONE){
stopNotification();
}else{
updateNotification();
}
}
示例10: getNotification
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
public Notification getNotification(MediaMetadataCompat metadata,
@NonNull PlaybackStateCompat state,
MediaSessionCompat.Token token) {
boolean isPlaying = state.getState() == PlaybackStateCompat.STATE_PLAYING;
MediaDescriptionCompat description = metadata.getDescription();
NotificationCompat.Builder builder =
buildNotification(state, token, isPlaying, description);
return builder.build();
}
示例11: onPlaybackStateChanged
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
super.onPlaybackStateChanged(state);
// If there's an ongoing animation, stop it now.
if (mProgressAnimator != null) {
mProgressAnimator.cancel();
mProgressAnimator = null;
}
final int progress = state != null
? (int) state.getPosition()
: 0;
setProgress(progress);
Log.d("nicole", "Set progress to: " + (progress / 1000.0f));
// If the media is playing then the seekbar should follow it, and the easiest
// way to do that is to create a ValueAnimator to update it so the bar reaches
// the end of the media the same time as playback gets there (or close enough).
if (state != null && state.getState() == PlaybackStateCompat.STATE_PLAYING) {
final int timeToEnd = (int) ((getMax() - progress) / state.getPlaybackSpeed());
mProgressAnimator = ValueAnimator.ofInt(progress, getMax())
.setDuration(timeToEnd);
mProgressAnimator.setInterpolator(new LinearInterpolator());
mProgressAnimator.addUpdateListener(this);
mProgressAnimator.start();
}
}
示例12: onPlaybackStateChanged
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
super.onPlaybackStateChanged(state);
// If there's an ongoing animation, stop it now.
if (mProgressAnimator != null) {
mProgressAnimator.cancel();
mProgressAnimator = null;
}
final int progress = state != null
? (int) state.getPosition()
: 0;
setProgress(progress);
// If the media is playing then the seekbar should follow it, and the easiest
// way to do that is to create a ValueAnimator to update it so the bar reaches
// the end of the media the same time as playback gets there (or close enough).
if (state != null && state.getState() == PlaybackStateCompat.STATE_PLAYING) {
final int timeToEnd = (int) ((getMax() - progress) / state.getPlaybackSpeed());
mProgressAnimator = ValueAnimator.ofInt(progress, getMax())
.setDuration(timeToEnd);
mProgressAnimator.setInterpolator(new LinearInterpolator());
mProgressAnimator.addUpdateListener(this);
mProgressAnimator.start();
}
}
示例13: update
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
public void update(
MediaMetadataCompat metadata,
PlaybackStateCompat state,
MediaSessionCompat.Token token) {
if (state == null
|| state.getState() == PlaybackStateCompat.STATE_STOPPED
|| state.getState() == PlaybackStateCompat.STATE_NONE) {
mService.stopForeground(true);
try {
mService.unregisterReceiver(this);
} catch (IllegalArgumentException ex) {
// ignore receiver not registered
}
mService.stopSelf();
return;
}
if (metadata == null) {
return;
}
boolean isPlaying = state.getState() == PlaybackStateCompat.STATE_PLAYING;
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(mService);
MediaDescriptionCompat description = metadata.getDescription();
notificationBuilder
.setStyle(
new NotificationCompat.MediaStyle()
.setMediaSession(token)
.setShowActionsInCompactView(0, 1, 2))
.setColor(
mService.getApplication().getResources().getColor(R.color.notification_bg))
.setSmallIcon(R.drawable.ic_notification)
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setContentIntent(createContentIntent())
.setContentTitle(description.getTitle())
.setContentText(description.getSubtitle())
.setLargeIcon(MusicLibrary.getAlbumBitmap(mService, description.getMediaId()))
.setOngoing(isPlaying)
.setWhen(isPlaying ? System.currentTimeMillis() - state.getPosition() : 0)
.setShowWhen(isPlaying)
.setUsesChronometer(isPlaying);
// If skip to next action is enabled
if ((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) {
notificationBuilder.addAction(mPrevAction);
}
notificationBuilder.addAction(isPlaying ? mPauseAction : mPlayAction);
// If skip to prev action is enabled
if ((state.getActions() & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) {
notificationBuilder.addAction(mNextAction);
}
Notification notification = notificationBuilder.build();
if (isPlaying && !mStarted) {
mService.startService(new Intent(mService.getApplicationContext(), MusicService.class));
mService.startForeground(NOTIFICATION_ID, notification);
mStarted = true;
} else {
if (!isPlaying) {
mService.stopForeground(false);
mStarted = false;
}
mNotificationManager.notify(NOTIFICATION_ID, notification);
}
}
示例14: buildNotification
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
public static Notification buildNotification(Context context, MediaSessionCompat session) {
MediaControllerCompat controller = session.getController();
MediaMetadataCompat metadata = controller.getMetadata();
PlaybackStateCompat playbackState = controller.getPlaybackState();
if ((metadata == null) || (playbackState == null)) {
return null;
}
boolean isPlaying = playbackState.getState() == PlaybackStateCompat.STATE_PLAYING;
NotificationCompat.Action action = isPlaying ?
new NotificationCompat.Action(android.R.drawable.ic_media_pause,
context.getString(R.string.pause),
MediaButtonReceiver.buildMediaButtonPendingIntent(context,
PlaybackStateCompat.ACTION_PAUSE)) :
new NotificationCompat.Action(android.R.drawable.ic_media_play,
context.getString(R.string.play),
MediaButtonReceiver.buildMediaButtonPendingIntent(context,
PlaybackStateCompat.ACTION_PLAY));
MediaDescriptionCompat description = metadata.getDescription();
Bitmap albumArt = description.getIconBitmap();
if (albumArt == null) {
albumArt = BitmapFactory.decodeResource(context.getResources(), R.mipmap.ic_launcher);
}
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, MusicService.NOTIFICATION_CHANNEL_ID);
builder.setStyle(new android.support.v4.media.app.NotificationCompat.MediaStyle()
// .setShowActionsInCompactView(new int[]{0})
.setMediaSession(session.getSessionToken()))
.addAction(action)
.setSmallIcon(R.mipmap.ic_launcher)
.setShowWhen(false)
.setContentIntent(controller.getSessionActivity())
.setContentTitle(description.getTitle())
.setContentText(description.getSubtitle())
.setLargeIcon(albumArt)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
return builder.build();
}
示例15: updatePlaybackState
import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
public void updatePlaybackState(PlaybackStateCompat stateCompat){
if(stateCompat==null) return;
lastState=stateCompat;
updateRepeatMode(isActionApplied(stateCompat.getActions(),
PlaybackStateCompat.ACTION_SET_REPEAT_MODE));
updateShuffleMode(isActionApplied(stateCompat.getActions(),
PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE_ENABLED));
//check the state
switch (stateCompat.getState()){
case PlaybackStateCompat.STATE_PLAYING:
playPause.setVisibility(VISIBLE);
if(playPause.isPlay()){
playPause.change(false,true);
}
startSeekBarUpdate();
break;
case PlaybackStateCompat.STATE_PAUSED:
// mControllers.setVisibility(VISIBLE);
// mLoading.setVisibility(INVISIBLE);
playPause.setVisibility(VISIBLE);
if(!playPause.isPlay()){
playPause.change(true,true);
}
stopSeekBarUpdate();
break;
case PlaybackStateCompat.STATE_NONE:
case PlaybackStateCompat.STATE_STOPPED:
playPause.setVisibility(VISIBLE);
if(playPause.isPlay()){
playPause.change(false,true);
}
stopSeekBarUpdate();
break;
case PlaybackStateCompat.STATE_BUFFERING:
playPause.setVisibility(INVISIBLE);
stopSeekBarUpdate();
break;
default:
Log.d(TAG, "Unhandled state "+stateCompat.getState());
}
}