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


Java PlaybackStateCompat.STATE_PAUSED屬性代碼示例

本文整理匯總了Java中android.support.v4.media.session.PlaybackStateCompat.STATE_PAUSED屬性的典型用法代碼示例。如果您正苦於以下問題:Java PlaybackStateCompat.STATE_PAUSED屬性的具體用法?Java PlaybackStateCompat.STATE_PAUSED怎麽用?Java PlaybackStateCompat.STATE_PAUSED使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.support.v4.media.session.PlaybackStateCompat的用法示例。


在下文中一共展示了PlaybackStateCompat.STATE_PAUSED屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: run

@Override
public void run() {
    int state = mediaPlayer.getPlaybackState();
    if (state == ExoPlayer.STATE_READY) {
        long pos = mediaPlayer.getCurrentPosition();
        float speed = mediaPlayer.getPlaybackParameters().speed;

        if (!notificationManager.startNotification()) {
            notificationManager.updateNotification();
        }
        stateBuilder.setBufferedPosition(mediaPlayer.getBufferedPercentage());
        int sessionState = mediaPlayer.getPlayWhenReady() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED;
        mediaSession.setPlaybackState(stateBuilder.setState(sessionState, pos, speed).build());
        if (mediaPlayer.getPlayWhenReady()) {
            progressHandler.postDelayed(progressRunnable, 1000 - (pos % 1000));
        }
    }
}
 
開發者ID:kalikov,項目名稱:lighthouse,代碼行數:18,代碼來源:MediaPlayerService.java

示例2: getDrawableByState

private Drawable getDrawableByState(Context context, int state) {
    switch (state) {
        case PlaybackStateCompat.STATE_NONE:
            Drawable pauseDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play);
            DrawableCompat.setTintList(pauseDrawable, colorPlay);
            return pauseDrawable;
        case PlaybackStateCompat.STATE_PLAYING:
            AnimationDrawable animation = (AnimationDrawable) ContextCompat.getDrawable(context, R.drawable.equalizer);
            DrawableCompat.setTintList(animation, colorPlay);
            animation.start();
            return animation;
        case PlaybackStateCompat.STATE_PAUSED:
            Drawable playDrawable = ContextCompat.getDrawable(context, R.drawable.equalizer);
            DrawableCompat.setTintList(playDrawable, colorPause);
            return playDrawable;
        default:
            Drawable noneDrawable = ContextCompat.getDrawable(context, R.drawable.ic_play);
            DrawableCompat.setTintList(noneDrawable, colorPlay);
            return noneDrawable;
    }
}
 
開發者ID:dibakarece,項目名稱:DMAudioStreamer,代碼行數:21,代碼來源:AdapterMusic.java

示例3: onPlaybackStateChange

@Override
public void onPlaybackStateChange(PlaybackStateCompat state) {
    // Report the state to the MediaSession.
    mSession.setPlaybackState(state);

    // Manage the started state of this service.
    switch (state.getState()) {
        case PlaybackStateCompat.STATE_PLAYING:
            mServiceManager.moveServiceToStartedState(state);
            break;
        case PlaybackStateCompat.STATE_PAUSED:
            mServiceManager.updateNotificationForPause(state);
            break;
        case PlaybackStateCompat.STATE_STOPPED:
            mServiceManager.moveServiceOutOfStartedState(state);
            break;
    }
}
 
開發者ID:fendoudebb,項目名稱:PlayAndroid,代碼行數:18,代碼來源:MusicService.java

示例4: pause

@Override
public void pause() {
    try {
        if (mState == PlaybackStateCompat.STATE_PLAYING) {
            // Pause media player and cancel the 'foreground service' state.
            if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
                mMediaPlayer.pause();
                mCurrentPosition = mMediaPlayer.getCurrentPosition();
            }
            // while paused, retain the MediaPlayer but give up audio focus
            relaxResources(false);
        }
        mState = PlaybackStateCompat.STATE_PAUSED;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        unregisterAudioNoisyReceiver();
    } catch (IllegalStateException ex) {
        Logger.e(TAG, ex, "Exception pause IllegalStateException");
        ex.printStackTrace();
    }
}
 
開發者ID:dibakarece,項目名稱:DMAudioStreamer,代碼行數:22,代碼來源:AudioPlaybackListener.java

示例5: onPlaybackStateUpdate

@Override
public void onPlaybackStateUpdate(PlaybackStateCompat playbackState) {
    mSession.setPlaybackState(playbackState);

    int state = playbackState.getState();

     if (state == PlaybackStateCompat.STATE_PLAYING) {
        Notification notification = postNotification();
        startForeground(NOTIFICATION_ID, notification);
        mReceiver.register();
    } else {
        if (state == PlaybackStateCompat.STATE_PAUSED) {
            postNotification();
        } else {
            mNotificationManager.cancel(NOTIFICATION_ID);
        }
        stopForeground(false);
        mReceiver.unregister();
    }
}
 
開發者ID:Jaysaw,項目名稱:NovaMusicPlayer,代碼行數:20,代碼來源:MusicService.java

示例6: playPause

@OnClick(R.id.play_pause)
public void playPause(){
    lastState=null;
    MediaControllerCompat controllerCompat=MediaControllerCompat.getMediaController(getActivity());
    PlaybackStateCompat stateCompat=controllerCompat.getPlaybackState();
    if(stateCompat!=null){
        MediaControllerCompat.TransportControls controls=
                controllerCompat.getTransportControls();
        switch (stateCompat.getState()){
            case PlaybackStateCompat.STATE_PLAYING:
            case PlaybackStateCompat.STATE_BUFFERING:
                controls.pause();
                break;
            case PlaybackStateCompat.STATE_NONE:
            case PlaybackStateCompat.STATE_PAUSED:
            case PlaybackStateCompat.STATE_STOPPED:
                controls.play();
                break;
            default:
                Log.d(TAG, "State "+stateCompat.getState());
        }
    }
}
 
開發者ID:vpaliyX,項目名稱:Melophile,代碼行數:23,代碼來源:TrackFragment.java

示例7: updatePlaybackState

/**
 * 更新播放狀態,播放/暫停/拖動進度條時調用
 */
public void updatePlaybackState() {
    int state = isPlaying() ? PlaybackStateCompat.STATE_PLAYING : PlaybackStateCompat.STATE_PAUSED;
    mMediaSession.setPlaybackState(
            new PlaybackStateCompat.Builder()
                    .setActions(MEDIA_SESSION_ACTIONS)
                    .setState(state, getCurrentPosition(), 1)
                    .build());
}
 
開發者ID:DuanJiaNing,項目名稱:Musicoco,代碼行數:11,代碼來源:MediaSessionManager.java

示例8: playbackStateToName

private String playbackStateToName(final int playbackState) {
    switch (playbackState) {
        case PlaybackStateCompat.STATE_NONE:
            return "STATE_NONE";
        case PlaybackStateCompat.STATE_STOPPED:
            return "STATE_STOPPED";
        case PlaybackStateCompat.STATE_PAUSED:
            return "STATE_PAUSED";
        case PlaybackStateCompat.STATE_PLAYING:
            return "STATE_PLAYING";
        case PlaybackStateCompat.STATE_FAST_FORWARDING:
            return "STATE_FAST_FORWARDING";
        case PlaybackStateCompat.STATE_REWINDING:
            return "STATE_REWINDING";
        case PlaybackStateCompat.STATE_BUFFERING:
            return "STATE_BUFFERING";
        case PlaybackStateCompat.STATE_ERROR:
            return "STATE_ERROR";
        case PlaybackStateCompat.STATE_CONNECTING:
            return "STATE_CONNECTING";
        case PlaybackStateCompat.STATE_SKIPPING_TO_PREVIOUS:
            return "STATE_SKIPPING_TO_PREVIOUS";
        case PlaybackStateCompat.STATE_SKIPPING_TO_NEXT:
            return "STATE_SKIPPING_TO_NEXT";
        case PlaybackStateCompat.STATE_SKIPPING_TO_QUEUE_ITEM:
            return "STATE_SKIPPING_TO_QUEUE_ITEM";
        default:
            return "!Unknown State!";
    }
}
 
開發者ID:googlesamples,項目名稱:android-media-controller,代碼行數:30,代碼來源:MediaAppControllerActivity.java

示例9: getAvailableActions

/**
 * Set the current capabilities available on this session. Note: If a capability is not
 * listed in the bitmask of capabilities then the MediaSession will not handle it. For
 * example, if you don't want ACTION_STOP to be handled by the MediaSession, then don't
 * included it in the bitmask that's returned.
 */
@PlaybackStateCompat.Actions
private long getAvailableActions() {
    long actions = PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID
            | PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH
            | PlaybackStateCompat.ACTION_SKIP_TO_NEXT
            | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
    switch (mState) {
        case PlaybackStateCompat.STATE_STOPPED:
            actions |= PlaybackStateCompat.ACTION_PLAY
                    | PlaybackStateCompat.ACTION_PAUSE;
            break;
        case PlaybackStateCompat.STATE_PLAYING:
            actions |= PlaybackStateCompat.ACTION_STOP
                    | PlaybackStateCompat.ACTION_PAUSE
                    | PlaybackStateCompat.ACTION_SEEK_TO;
            break;
        case PlaybackStateCompat.STATE_PAUSED:
            actions |= PlaybackStateCompat.ACTION_PLAY
                    | PlaybackStateCompat.ACTION_STOP;
            break;
        default:
            actions |= PlaybackStateCompat.ACTION_PLAY
                    | PlaybackStateCompat.ACTION_PLAY_PAUSE
                    | PlaybackStateCompat.ACTION_STOP
                    | PlaybackStateCompat.ACTION_PAUSE;
    }
    return actions;
}
 
開發者ID:fendoudebb,項目名稱:PlayAndroid,代碼行數:34,代碼來源:MediaPlayerManager.java

示例10: onPlayStateChanged

@Override
public void onPlayStateChanged(PlaybackGlue glue) {
    super.onPlayStateChanged(glue);
    Log.d(TAG, "PlayerCallback: onPlayStateChanged()");
    int state =
            glue.isPlaying()
                    ? PlaybackStateCompat.STATE_PLAYING
                    : PlaybackStateCompat.STATE_PAUSED;
    mMediaSessionCallback.updatePlaybackState(
            state,
            mPlayerGlue.getCurrentPosition(),
            mPlaylistAdapter.getCurrentItem());
    Log.d(TAG, "PlayerCallback: playback state: " + state);
}
 
開發者ID:googlesamples,項目名稱:leanback-assistant,代碼行數:14,代碼來源:PlaybackFragment.java

示例11: updatePlaybackState

private void updatePlaybackState(PlaybackStateCompat state) {
    mCurrentState = state;
    if (state == null
            || state.getState() == PlaybackStateCompat.STATE_PAUSED
            || state.getState() == PlaybackStateCompat.STATE_STOPPED) {
        mPlayPause.setImageDrawable(
                ContextCompat.getDrawable(this, R.drawable.ic_play_arrow_black_36dp));
    } else {
        mPlayPause.setImageDrawable(
                ContextCompat.getDrawable(this, R.drawable.ic_pause_black_36dp));
    }
    mPlaybackControls.setVisibility(state == null ? View.GONE : View.VISIBLE);
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:13,代碼來源:MusicPlayerActivity.java

示例12: onClick

@Override
public void onClick(View v) {
    final int state =
            mCurrentState == null
                    ? PlaybackStateCompat.STATE_NONE
                    : mCurrentState.getState();
    if (state == PlaybackStateCompat.STATE_PAUSED
            || state == PlaybackStateCompat.STATE_STOPPED
            || state == PlaybackStateCompat.STATE_NONE) {

        if (mCurrentMetadata == null) {
            mCurrentMetadata =
                    MusicLibrary.getMetadata(
                            MusicPlayerActivity.this,
                            MusicLibrary.getMediaItems().get(0).getMediaId());
            updateMetadata(mCurrentMetadata);
        }

        // TODO: [5] Remove the following line for playback in a Service
        mPlaybackManager.play(mCurrentMetadata);

        // TODO: [5] Uncomment the following block for playback in a Service
        /*
        MediaControllerCompat.getMediaController(MusicPlayerActivity.this)
                .getTransportControls()
                .playFromMediaId(
                        mCurrentMetadata.getDescription().getMediaId(), null);
        */
    } else {
        // TODO: [6] Remove the following line for playback in a Service
        mPlaybackManager.pause();

        // TODO: [6] Uncomment the following block for playback in a Service
        /*
        MediaControllerCompat.getMediaController(MusicPlayerActivity.this)
                .getTransportControls()
                .pause();
        */
    }
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:40,代碼來源:MusicPlayerActivity.java

示例13: pause

public void pause() {
    if (isPlaying()) {
        mMediaPlayer.pause();
        mAudioManager.abandonAudioFocus(this);
    }
    mState = PlaybackStateCompat.STATE_PAUSED;
    updatePlaybackState();
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:8,代碼來源:PlaybackManager.java

示例14: onAudioFocusChange

/**
 * Called by AudioManager on audio focus changes. Implementation of {@link
 * AudioManager.OnAudioFocusChangeListener}
 */
@Override
public void onAudioFocusChange(int focusChange) {
    boolean gotFullFocus = false;
    boolean canDuck = false;
    if (focusChange == AudioManager.AUDIOFOCUS_GAIN) {
        gotFullFocus = true;

    } else if (focusChange == AudioManager.AUDIOFOCUS_LOSS
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT
            || focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK) {
        // We have lost focus. If we can duck (low playback volume), we can keep playing.
        // Otherwise, we need to pause the playback.
        canDuck = focusChange == AudioManager.AUDIOFOCUS_LOSS_TRANSIENT_CAN_DUCK;
    }

    if (gotFullFocus || canDuck) {
        if (mMediaPlayer != null) {
            if (mPlayOnFocusGain) {
                mPlayOnFocusGain = false;
                mMediaPlayer.start();
                mState = PlaybackStateCompat.STATE_PLAYING;
                updatePlaybackState();
            }
            float volume = canDuck ? 0.2f : 1.0f;
            mMediaPlayer.setVolume(volume, volume);
        }
    } else if (mState == PlaybackStateCompat.STATE_PLAYING) {
        mMediaPlayer.pause();
        mState = PlaybackStateCompat.STATE_PAUSED;
        updatePlaybackState();
    }
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:36,代碼來源:PlaybackManager.java

示例15: getAvailableActions

/**
 * Set the current capabilities available on this session. Note: If a capability is not
 * listed in the bitmask of capabilities then the MediaSession will not handle it. For
 * example, if you don't want ACTION_STOP to be handled by the MediaSession, then don't
 * included it in the bitmask that's returned.
 */
@PlaybackStateCompat.Actions
private long getAvailableActions() {
    long actions = PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID
                   | PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH
                   | PlaybackStateCompat.ACTION_SKIP_TO_NEXT
                   | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS;
    switch (mState) {
        case PlaybackStateCompat.STATE_STOPPED:
            actions |= PlaybackStateCompat.ACTION_PLAY
                       | PlaybackStateCompat.ACTION_PAUSE;
            break;
        case PlaybackStateCompat.STATE_PLAYING:
            actions |= PlaybackStateCompat.ACTION_STOP
                       | PlaybackStateCompat.ACTION_PAUSE
                       | PlaybackStateCompat.ACTION_SEEK_TO;
            break;
        case PlaybackStateCompat.STATE_PAUSED:
            actions |= PlaybackStateCompat.ACTION_PLAY
                       | PlaybackStateCompat.ACTION_STOP;
            break;
        default:
            actions |= PlaybackStateCompat.ACTION_PLAY
                       | PlaybackStateCompat.ACTION_PLAY_PAUSE
                       | PlaybackStateCompat.ACTION_STOP
                       | PlaybackStateCompat.ACTION_PAUSE;
    }
    return actions;
}
 
開發者ID:nazmulidris,項目名稱:mediasession-mediaplayer,代碼行數:34,代碼來源:MediaPlayerAdapter.java


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