當前位置: 首頁>>代碼示例>>Java>>正文


Java MediaSession.Token方法代碼示例

本文整理匯總了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();
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:20,代碼來源:BaseActivity.java

示例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();
    }
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:22,代碼來源:FullScreenPlayerActivity.java

示例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));
        }
    };
}
 
開發者ID:googlesamples,項目名稱:android-media-controller,代碼行數:12,代碼來源:MediaAppEntry.java

示例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);
}
 
開發者ID:ErNaveen,項目名稱:UniversalMusicPlayer,代碼行數:11,代碼來源:BaseActivity.java

示例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();
    }
}
 
開發者ID:Tombarr,項目名稱:Noyze,代碼行數:10,代碼來源:RemoteControlLollipop.java

示例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);
}
 
開發者ID:OpenSilk,項目名稱:Orpheus,代碼行數:42,代碼來源:NotificationHelper.java

示例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);
    }
}
 
開發者ID:smitzey,項目名稱:AndroidAutoTourGuide,代碼行數:56,代碼來源:PlaybackControlEventBroadcastReceiver.java

示例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);
    }
}
 
開發者ID:googlecodelabs,項目名稱:android-music-player,代碼行數:62,代碼來源:MediaNotificationManager.java

示例9: getMediaSessionToken

import android.media.session.MediaSession; //導入方法依賴的package包/類
public MediaSession.Token getMediaSessionToken() {
    return mMediaSession.getSessionToken();
}
 
開發者ID:emuneee,項目名稱:MarshmallowFM,代碼行數:4,代碼來源:AudioPlayerService.java

示例10: fromToken

import android.media.session.MediaSession; //導入方法依賴的package包/類
public static Object fromToken(Context context, Object sessionToken) {
    return new MediaController(context, (MediaSession.Token) sessionToken);
}
 
開發者ID:kingargyle,項目名稱:adt-leanback-support,代碼行數:4,代碼來源:MediaControllerCompatApi21.java

示例11: EventUpdateMetadata

import android.media.session.MediaSession; //導入方法依賴的package包/類
public EventUpdateMetadata(@NonNull MediaSession.Token token) {
    super();
    mHandler = new Handler(Looper.getMainLooper());
    mToken = token;
}
 
開發者ID:AChep,項目名稱:AcDisplay,代碼行數:6,代碼來源:MediaController2Lollipop.java

示例12: getSessionToken

import android.media.session.MediaSession; //導入方法依賴的package包/類
public MediaSession.Token getSessionToken() {
    return IMPL.getMediaToken();
}
 
開發者ID:OpenSilk,項目名稱:Orpheus,代碼行數:4,代碼來源:MediaSessionHelper.java

示例13: getMediaToken

import android.media.session.MediaSession; //導入方法依賴的package包/類
MediaSession.Token getMediaToken() {
    return null;
}
 
開發者ID:OpenSilk,項目名稱:Orpheus,代碼行數:4,代碼來源:MediaSessionHelper.java

示例14: setSessionToken

import android.media.session.MediaSession; //導入方法依賴的package包/類
@Override
public void setSessionToken(Object token) {
    super.setSessionToken((MediaSession.Token) token);
}
 
開發者ID:OpenSilk,項目名稱:Orpheus,代碼行數:5,代碼來源:PlaybackServiceL.java

示例15: getSessionToken

import android.media.session.MediaSession; //導入方法依賴的package包/類
public MediaSession.Token getSessionToken() {
    return mSession.getSessionToken();
}
 
開發者ID:OpenSilk,項目名稱:Orpheus,代碼行數:4,代碼來源:MediaSessionHolderL.java


注:本文中的android.media.session.MediaSession.Token方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。