本文整理匯總了Java中android.support.v4.media.session.MediaSessionCompat.Token方法的典型用法代碼示例。如果您正苦於以下問題:Java MediaSessionCompat.Token方法的具體用法?Java MediaSessionCompat.Token怎麽用?Java MediaSessionCompat.Token使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類android.support.v4.media.session.MediaSessionCompat
的用法示例。
在下文中一共展示了MediaSessionCompat.Token方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: buildNotification
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
public void buildNotification(Context context, final String albumName, final String artistName,
final String trackName, final Long albumId, final Bitmap albumArt,
final boolean isPlaying, MediaSessionCompat.Token mediaSessionToken) {
if (Utils.hasOreo()){
mNotificationManager.createNotificationChannel(AppNotificationChannels.getAudioChannel(context));
}
// Notification Builder
mNotificationBuilder = new NotificationCompat.Builder(mService, AppNotificationChannels.AUDIO_CHANNEL_ID)
.setShowWhen(false)
.setSmallIcon(R.drawable.itunes)
.setContentTitle(artistName)
.setContentText(trackName)
.setContentIntent(getOpenIntent(context))
.setLargeIcon(BitmapFactory.decodeResource(context.getResources(), R.drawable.cover))
.setPriority(Notification.PRIORITY_MAX)
.setStyle(new MediaStyle()
.setMediaSession(mediaSessionToken)
.setShowCancelButton(true)
.setShowActionsInCompactView(0, 1, 2)
.setCancelButtonIntent(retreivePlaybackActions(4)))
.addAction(new android.support.v4.app.NotificationCompat.Action(R.drawable.page_first, ""
, retreivePlaybackActions(3)))
.addAction(new android.support.v4.app.NotificationCompat.Action(isPlaying ? R.drawable.pause : R.drawable.play, ""
, retreivePlaybackActions(1)))
.addAction(new android.support.v4.app.NotificationCompat.Action(R.drawable.page_last, ""
, retreivePlaybackActions(2)));
mService.startForeground(APOLLO_MUSIC_SERVICE, mNotificationBuilder.build());
}
示例2: connectToSession
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException
{
LogHelper.e(TAG, "connectToSession");
MediaControllerCompat mediaController = new MediaControllerCompat(this, token);
MediaControllerCompat.setMediaController(this, mediaController);
mediaController.registerCallback(mMediaControllerCallback);
if (shouldShowControls()) {
showPlaybackControls();
} else {
LogHelper.e(TAG, "connectionCallback.onConnected: hiding controls because metadata is null");
hidePlaybackControls();
}
if (mControlsFragment != null) {
mControlsFragment.onConnected();
}
onMediaControllerConnected();
}
示例3: onMediaItemSelected
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onMediaItemSelected(MediaBrowserCompat.MediaItem item) {
LogHelper.d(TAG, "onMediaItemSelected, mediaId=" + item.getMediaId());
if (item.isPlayable()) {
final MediaControllerCompat mediaController = getSupportMediaController();
if (mediaController != null) {
MediaSessionCompat.Token token = mediaController.getSessionToken();
MediaControllerCompat.TransportControls tc = mediaController.getTransportControls();
mediaController.getTransportControls().playFromMediaId(item.getMediaId(), null);
}
} else if (item.isBrowsable()) {
navigateToBrowser(item.getMediaId());
} else {
LogHelper.w(TAG, "Ignoring MediaItem that is neither browsable nor playable: ",
"mediaId=", item.getMediaId());
}
}
示例4: connectToSession
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void connectToSession(MediaSessionCompat.Token token) {
try {
LogUtils.LOGD(TAG, "Session Token: " + token);
mMediaController = new MediaControllerCompat(this, token);
mMediaController.registerCallback(mMediaControllerCallback);
if (shouldShowControls()) {
showPlaybackControls();
} else {
LogHelper.d(TAG, "connectionCallback.onConnected: " + "hiding controls because metadata is null");
hidePlaybackControls();
}
if (mControlsFragment != null) {
mControlsFragment.onConnected();
}
onMediaControllerConnected();
} catch (RemoteException ex) {
}
}
示例5: connectToSession
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
MediaControllerCompat mediaController = new MediaControllerCompat(this, token);
MediaControllerCompat.setMediaController(this, 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();
}
示例6: connectToSession
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
MediaControllerCompat mediaController = new MediaControllerCompat(
FullScreenPlayerActivity.this, token);
if (mediaController.getMetadata() == null) {
finish();
return;
}
MediaControllerCompat.setMediaController(FullScreenPlayerActivity.this, mediaController);
mediaController.registerCallback(mCallback);
PlaybackStateCompat state = mediaController.getPlaybackState();
updatePlaybackState(state);
MediaMetadataCompat metadata = mediaController.getMetadata();
if (metadata != null) {
updateMediaDescription(metadata.getDescription());
updateDuration(metadata);
}
updateProgress();
if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING ||
state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
scheduleSeekbarUpdate();
}
}
示例7: onMediaItemSelected
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onMediaItemSelected(MediaBrowserCompat.MediaItem item) {
LogUtils.d(TAG, "onMediaItemSelected, mediaId=" + item.getMediaId());
if (item.isPlayable()) {
final MediaControllerCompat mediaController = getSupportMediaController();
if (mediaController != null) {
MediaSessionCompat.Token token = mediaController.getSessionToken();
MediaControllerCompat.TransportControls tc = mediaController.getTransportControls();
mediaController.getTransportControls().playFromMediaId(item.getMediaId(), null);
}
} else if (item.isBrowsable()) {
navigateToBrowser(item.getMediaId());
} else {
LogUtils.w(TAG, "Ignoring MediaItem that is neither browsable nor playable: ",
"mediaId=", item.getMediaId());
}
}
示例8: connectToSession
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void connectToSession(MediaSessionCompat.Token token) {
try {
LogUtils.d(TAG, "Session Token: " + token);
mMediaController = new MediaControllerCompat(this, token);
mMediaController.registerCallback(mMediaControllerCallback);
if (shouldShowControls()) {
showPlaybackControls();
} else {
LogUtils.d(TAG, "connectionCallback.onConnected: " + "hiding controls because metadata is null");
hidePlaybackControls();
}
if (mControlsFragment != null) {
mControlsFragment.onConnected();
}
onMediaControllerConnected();
} catch (RemoteException ex) {
LogUtils.e(TAG, ex.getMessage());
}
}
示例9: connectToSession
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void connectToSession(MediaSessionCompat.Token token) {
try {
mMediaController = new MediaControllerCompat(FullScreenPlayerActivity.this, token);
if (mMediaController.getMetadata() == null) {
finish();
return;
}
mMediaController.registerCallback(mCallback);
PlaybackStateCompat state = mMediaController.getPlaybackState();
updatePlaybackState(state);
MediaMetadataCompat metadata = mMediaController.getMetadata();
if (metadata != null) {
updateMediaDescription(metadata.getDescription());
updateDuration(metadata);
}
updateProgress();
if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING ||
state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
scheduleSeekbarUpdate();
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
示例10: connectToSession
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
MediaControllerCompat controller = new MediaControllerCompat(this, token);
MediaControllerCompat.setMediaController(this, controller);
controller.registerCallback(mMediaControllerCallback);
//// TODO: 2017/9/14 do this in sub class
getFragment().onConnected();
}
示例11: onConnected
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onConnected() {
super.onConnected();
MediaSessionCompat.Token token=browserCompat.getSessionToken();
try {
MediaControllerCompat mediaController =new MediaControllerCompat(getActivity(), token);
// Save the controller
mediaController.registerCallback(controllerCallback);
MediaControllerCompat.setMediaController(getActivity(), mediaController);
//inject the passed query
inject();
}catch (RemoteException ex){
ex.printStackTrace();
}
}
示例12: getNotification
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的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();
}
示例13: onConnected
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onConnected() {
LogHelper.d(TAG, "onConnected");
MediaSessionCompat.Token token = mMediaBrowser.getSessionToken();
if (token == null) {
throw new IllegalArgumentException("No Session token");
}
connectToSession(token);
}
示例14: connectToSession
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
private void connectToSession(MediaSessionCompat.Token token) {
try {
mMediaController = new MediaControllerCompat(FullScreenPlayerActivity.this, token);
if (mMediaController.getMetadata() == null) {
finish();
return;
}
mMediaController.registerCallback(mCallback);
PlaybackStateCompat state = mMediaController.getPlaybackState();
updatePlaybackState(state);
MediaMetadataCompat metadata = mMediaController.getMetadata();
if (metadata != null) {
updateMediaDescription(metadata.getDescription());
updateDuration(metadata);
}
updateProgress();
if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING ||
state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
scheduleSeekbarUpdate();
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
示例15: onConnected
import android.support.v4.media.session.MediaSessionCompat; //導入方法依賴的package包/類
@Override
public void onConnected() {
LogUtils.d(TAG, "onConnected");
MediaSessionCompat.Token token = mMediaBrowser.getSessionToken();
if (token == null) {
throw new IllegalArgumentException("No Session token");
}
connectToSession(token);
}