当前位置: 首页>>代码示例>>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;未经允许,请勿转载。