本文整理汇总了Java中android.media.session.PlaybackState.getActions方法的典型用法代码示例。如果您正苦于以下问题:Java PlaybackState.getActions方法的具体用法?Java PlaybackState.getActions怎么用?Java PlaybackState.getActions使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.PlaybackState
的用法示例。
在下文中一共展示了PlaybackState.getActions方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: update
import android.media.session.PlaybackState; //导入方法依赖的package包/类
public void update(MediaMetadata metadata, PlaybackState state, MediaSession.Token token) {
if (state == null || state.getState() == PlaybackState.STATE_STOPPED ||
state.getState() == PlaybackState.STATE_NONE) {
muziKarMusicService.stopForeground(true);
try {
muziKarMusicService.unregisterReceiver(this);
} catch (IllegalArgumentException ex) {
Log.w ( TAG, "update metadata=" + metadata) ;
}
muziKarMusicService.stopSelf();
return;
}
if (metadata == null) {
return;
}
boolean isPlaying = state.getState() == PlaybackState.STATE_PLAYING;
Notification.Builder notificationBuilder = new Notification.Builder(muziKarMusicService);
MediaDescription description = metadata.getDescription();
notificationBuilder
.setContentTitle(description.getTitle())
.setVisibility(Notification.VISIBILITY_PUBLIC)
.setOngoing(isPlaying)
.setWhen(isPlaying ? System.currentTimeMillis() - state.getPosition() : 0)
.setShowWhen(isPlaying)
.setUsesChronometer(isPlaying)
.setContentText(description.getSubtitle())
.setLargeIcon(LocalMusicSource.getAlbumBitmap(muziKarMusicService, description.getMediaId()))
.setStyle(new Notification.MediaStyle().setMediaSession(token).setShowActionsInCompactView(0, 1, 2))
.setColor(muziKarMusicService.getApplication().getResources().getColor(R.color.colorPrimary))
.setSmallIcon(R.drawable.art);
if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) {
notificationBuilder.addAction(previousAction);
}
notificationBuilder.addAction(isPlaying ? pauseAction : playAction);
if ((state.getActions() & PlaybackState.ACTION_SKIP_TO_NEXT) != 0) {
notificationBuilder.addAction(nextAction);
}
Notification notification = notificationBuilder.build();
if (isPlaying && !runningFlag) {
muziKarMusicService.startService(new Intent(muziKarMusicService.getApplicationContext(), MuziKarMusicService.class));
muziKarMusicService.startForeground(NOTIFICATION_ID, notification);
runningFlag = true;
} else {
if (!isPlaying) {
muziKarMusicService.stopForeground(false);
runningFlag = false;
}
notificationManager.notify(NOTIFICATION_ID, notification);
}
}
示例2: update
import android.media.session.PlaybackState; //导入方法依赖的package包/类
public void update(MediaMetadata metadata, PlaybackState state, MediaSession.Token token) {
if (state == null || state.getState() == PlaybackState.STATE_STOPPED ||
state.getState() == PlaybackState.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() == PlaybackState.STATE_PLAYING;
Notification.Builder notificationBuilder = new Notification.Builder(mService);
MediaDescription description = metadata.getDescription();
notificationBuilder
.setStyle(new Notification.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() & PlaybackState.ACTION_SKIP_TO_PREVIOUS) != 0) {
notificationBuilder.addAction(mPrevAction);
}
notificationBuilder.addAction(isPlaying ? mPauseAction : mPlayAction);
// If skip to prev action is enabled
if ((state.getActions() & PlaybackState.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);
}
}