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


Java PlaybackState.getActions方法代碼示例

本文整理匯總了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);
    }
}
 
開發者ID:smitzey,項目名稱:AndroidAutoTourGuide,代碼行數:56,代碼來源:PlaybackControlEventBroadcastReceiver.java

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


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