本文整理汇总了Java中android.media.session.MediaSession.Token方法的典型用法代码示例。如果您正苦于以下问题:Java MediaSession.Token方法的具体用法?Java MediaSession.Token怎么用?Java MediaSession.Token使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.media.session.MediaSession
的用法示例。
在下文中一共展示了MediaSession.Token方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: connectToSession
import android.media.session.MediaSession; //导入方法依赖的package包/类
private void connectToSession(MediaSession.Token token) {
MediaController mediaController = new MediaController(this, token);
setMediaController(mediaController);
mediaController.registerCallback(mMediaControllerCallback);
if (shouldShowControls()) {
showPlaybackControls();
} else {
LogHelper.d(TAG, "connectionCallback.onConnected: " +
"hiding controls because metadata is null");
hidePlaybackControls();
}
if (mControlsFragment != null) {
mControlsFragment.onConnected();
}
onMediaControllerConnected();
}
示例2: connectToSession
import android.media.session.MediaSession; //导入方法依赖的package包/类
private void connectToSession(MediaSession.Token token) {
MediaController mediaController = new MediaController(FullScreenPlayerActivity.this, token);
if (mediaController.getMetadata() == null) {
finish();
return;
}
setMediaController(mediaController);
mediaController.registerCallback(mCallback);
PlaybackState state = mediaController.getPlaybackState();
updatePlaybackState(state);
MediaMetadata metadata = mediaController.getMetadata();
if (metadata != null) {
updateMediaDescription(metadata.getDescription());
updateDuration(metadata);
}
updateProgress();
if (state != null && (state.getState() == PlaybackState.STATE_PLAYING ||
state.getState() == PlaybackState.STATE_BUFFERING)) {
scheduleSeekbarUpdate();
}
}
示例3: fromSessionToken
import android.media.session.MediaSession; //导入方法依赖的package包/类
public static MediaAppEntry fromSessionToken(MediaSession.Token sessionToken,
String appName,
String packageName,
Drawable appIcon) {
return new MediaAppEntry(appName, packageName, appIcon) {
@Override
public void getSessionToken(Context context, SessionTokenAvailableCallback callback) {
callback.onSuccess(MediaSessionCompat.Token.fromToken(sessionToken));
}
};
}
示例4: onConnected
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void onConnected() {
LogHelper.d(TAG, "onConnected");
MediaSession.Token token = mMediaBrowser.getSessionToken();
if (token == null) {
throw new IllegalArgumentException("No Session token");
}
connectToSession(token);
}
示例5: unregister
import android.media.session.MediaSession; //导入方法依赖的package包/类
private void unregister() {
for (Map.Entry<MediaSession.Token, Pair<MediaController, MediaController.Callback>> entry : mControllers.entrySet()) {
Pair<MediaController, MediaController.Callback> pair = entry.getValue();
pair.first.unregisterCallback(pair.second);
}
synchronized (mControllers) {
mControllers.clear();
}
}
示例6: buildNotification
import android.media.session.MediaSession; //导入方法依赖的package包/类
/**
* Call this to build the {@link Notification}.
*/
public void buildNotification(final String albumName, final String artistName,
final String trackName, final Bitmap albumArt,
final boolean isPlaying, MediaSession.Token mediaToken) {
{
// Default notfication layout
mNotificationTemplate = new RemoteViews(mService.getPackageName(),
R.layout.notification_template_base);
// Set up the content view
initCollapsedLayout(trackName, artistName, albumArt);
// Notification Builder
mNotification = new NotificationCompat.Builder(mService)
.setSmallIcon(R.drawable.stat_notify_music)
.setContentIntent(getPendingIntent())
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setCategory(NotificationCompat.CATEGORY_TRANSPORT)
.setContent(mNotificationTemplate)
.build();
// Control playback from the notification
initPlaybackActions(isPlaying);
if (VersionUtils.hasJellyBean()) {
// Expanded notifiction style
mExpandedView = new RemoteViews(mService.getPackageName(),
R.layout.notification_template_expanded_base);
mNotification.bigContentView = mExpandedView;
// Control playback from the notification
initExpandedPlaybackActions(isPlaying);
// Set up the expanded content view
initExpandedLayout(trackName, albumName, artistName, albumArt);
}
}
mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
mService.startForeground(APOLLO_MUSIC_SERVICE, mNotification);
}
示例7: update
import android.media.session.MediaSession; //导入方法依赖的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);
}
}
示例8: update
import android.media.session.MediaSession; //导入方法依赖的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);
}
}
示例9: getMediaSessionToken
import android.media.session.MediaSession; //导入方法依赖的package包/类
public MediaSession.Token getMediaSessionToken() {
return mMediaSession.getSessionToken();
}
示例10: fromToken
import android.media.session.MediaSession; //导入方法依赖的package包/类
public static Object fromToken(Context context, Object sessionToken) {
return new MediaController(context, (MediaSession.Token) sessionToken);
}
示例11: EventUpdateMetadata
import android.media.session.MediaSession; //导入方法依赖的package包/类
public EventUpdateMetadata(@NonNull MediaSession.Token token) {
super();
mHandler = new Handler(Looper.getMainLooper());
mToken = token;
}
示例12: getSessionToken
import android.media.session.MediaSession; //导入方法依赖的package包/类
public MediaSession.Token getSessionToken() {
return IMPL.getMediaToken();
}
示例13: getMediaToken
import android.media.session.MediaSession; //导入方法依赖的package包/类
MediaSession.Token getMediaToken() {
return null;
}
示例14: setSessionToken
import android.media.session.MediaSession; //导入方法依赖的package包/类
@Override
public void setSessionToken(Object token) {
super.setSessionToken((MediaSession.Token) token);
}
示例15: getSessionToken
import android.media.session.MediaSession; //导入方法依赖的package包/类
public MediaSession.Token getSessionToken() {
return mSession.getSessionToken();
}