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


Java MediaSessionCompat.Token方法代碼示例

本文整理匯總了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());
}
 
開發者ID:PhoenixDevTeam,項目名稱:Phoenix-for-VK,代碼行數:31,代碼來源:NotificationHelper.java

示例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();
}
 
開發者ID:teocci,項目名稱:YouTube-In-Background,代碼行數:22,代碼來源:MainActivity.java

示例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());
    }
}
 
開發者ID:SoumyaParida,項目名稱:MyGaana-Universal,代碼行數:18,代碼來源:MusicPlayerActivity.java

示例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) {

        }
    }
 
開發者ID:SoumyaParida,項目名稱:MyGaana-Universal,代碼行數:27,代碼來源:BaseActivity.java

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

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

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

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

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

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

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

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

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

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

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


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