当前位置: 首页>>代码示例>>Java>>正文


Java PlaybackStateCompat.STATE_STOPPED属性代码示例

本文整理汇总了Java中android.support.v4.media.session.PlaybackStateCompat.STATE_STOPPED属性的典型用法代码示例。如果您正苦于以下问题:Java PlaybackStateCompat.STATE_STOPPED属性的具体用法?Java PlaybackStateCompat.STATE_STOPPED怎么用?Java PlaybackStateCompat.STATE_STOPPED使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在android.support.v4.media.session.PlaybackStateCompat的用法示例。


在下文中一共展示了PlaybackStateCompat.STATE_STOPPED属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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:nazmulidris,项目名称:mediasession-mediaplayer,代码行数:18,代码来源:MusicService.java

示例2: onStop

@Override
public void onStop() {
    if (exoPlayer.getPlayWhenReady()) {
        exoPlayer.setPlayWhenReady(false);
        unregisterReceiver(becomingNoisyReceiver);
    }

    if (audioFocusRequested) {
        audioFocusRequested = false;

        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
            audioManager.abandonAudioFocusRequest(audioFocusRequest);
        } else {
            audioManager.abandonAudioFocus(audioFocusChangeListener);
        }
    }

    mediaSession.setActive(false);

    mediaSession.setPlaybackState(stateBuilder.setState(PlaybackStateCompat.STATE_STOPPED, PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1).build());
    currentState = PlaybackStateCompat.STATE_STOPPED;

    refreshNotificationAndForegroundStatus(currentState);

    stopSelf();
}
 
开发者ID:SergeyVinyar,项目名称:AndroidAudioExample,代码行数:26,代码来源:PlayerService.java

示例3: 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

示例4: setNewState

private void setNewState(@PlaybackStateCompat.State int newPlayerState) {
    mState = newPlayerState;

    // Whether playback goes to completion, or whether it is stopped, the
    // mCurrentMediaPlayedToCompletion is set to true.
    if (mState == PlaybackStateCompat.STATE_STOPPED) {
        mCurrentMediaPlayedToCompletion = true;
    }

    // Work around for MediaPlayer.getCurrentPosition() when it changes while not playing.
    final long reportPosition;
    if (mSeekWhileNotPlaying >= 0) {
        reportPosition = mSeekWhileNotPlaying;

        if (mState == PlaybackStateCompat.STATE_PLAYING) {
            mSeekWhileNotPlaying = -1;
        }
    } else {
        reportPosition = mMediaPlayer == null ? 0 : mMediaPlayer.getCurrentPosition();
    }

    final PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder();
    stateBuilder.setActions(getAvailableActions());
    stateBuilder.setState(mState,
                          reportPosition,
                          1.0f,
                          SystemClock.elapsedRealtime());
    mPlaybackInfoListener.onPlaybackStateChange(stateBuilder.build());
}
 
开发者ID:nazmulidris,项目名称:mediasession-mediaplayer,代码行数:29,代码来源:MediaPlayerAdapter.java

示例5: 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

示例6: stop

public void stop() {
    mState = PlaybackStateCompat.STATE_STOPPED;
    updatePlaybackState();
    // Give up Audio focus
    mAudioManager.abandonAudioFocus(this);
    // Relax all resources
    releaseMediaPlayer();
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:8,代码来源:PlaybackManager.java

示例7: 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

示例8: onPlaybackStateChanged

@Override
public void onPlaybackStateChanged(PlaybackStateCompat state) {
    mPlaybackState = state;
    Log.i(TAG, "onPlaybackStateChanged: received new play state : " + state);
    if (state.getState() == PlaybackStateCompat.STATE_STOPPED ||
            state.getState() == PlaybackStateCompat.STATE_NONE) {
        stopNotification();
    } else {
        Notification notification = buildNotification();
        if (notification != null) {
            mNotificationManager.notify(NOTIFICATION_ID, notification);
        }
    }

}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:15,代码来源:NovaNotificationManager.java

示例9: stop

@Override
public void stop() {
    mPlaybackState = PlaybackStateCompat.STATE_STOPPED;
    if (mCallback != null) {
        mCallback.onPlayStateChanged(mPlaybackState);
    }
    mCurrentPosition = getCurrentStreamPosition();
    giveUpAudioFocus();
    unregisterNoisyReceiver();
    releaseResource(true);
}
 
开发者ID:Jaysaw,项目名称:NovaMusicPlayer,代码行数:11,代码来源:LocalPlayback.java

示例10: setNewState

private void setNewState(@PlaybackStateCompat.State int newPlayerState) {
    mState = newPlayerState;

    // Whether playback goes to completion, or whether it is stopped, the
    // mCurrentMediaPlayedToCompletion is set to true.
    if (mState == PlaybackStateCompat.STATE_STOPPED) {
        mCurrentMediaPlayedToCompletion = true;
    }

    // Work around for MediaPlayer.getCurrentPosition() when it changes while not playing.
    final long reportPosition;
    if (mSeekWhileNotPlaying >= 0) {
        reportPosition = mSeekWhileNotPlaying;

        if (mState == PlaybackStateCompat.STATE_PLAYING) {
            mSeekWhileNotPlaying = -1;
        }
    } else {
        reportPosition = mMediaPlayer == null ? 0 : mMediaPlayer.getCurrentPosition();
    }

    final PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder();
    stateBuilder.setActions(getAvailableActions());
    stateBuilder.setState(mState,
            reportPosition,
            1.0f,
            SystemClock.elapsedRealtime());
    mPlaybackInfoListener.onPlaybackStateChange(stateBuilder.build());
}
 
开发者ID:fendoudebb,项目名称:PlayAndroid,代码行数:29,代码来源:MediaPlayerManager.java

示例11: onPlaybackStateChanged

@Override
public void onPlaybackStateChanged(@NonNull PlaybackStateCompat state) {
    mPlaybackState = state;
    if (state.getState() == PlaybackStateCompat.STATE_STOPPED ||
            state.getState() == PlaybackStateCompat.STATE_NONE) {
        stopNotification();
    } else {
        Notification notification = createNotification();
        if (notification != null) {
            mNotificationManager.notify(NOTIFICATION_ID, notification);
        }
    }
}
 
开发者ID:AllThatSeries,项目名称:react-native-streaming-audio-player,代码行数:13,代码来源:MediaNotificationManager.java

示例12: 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

示例13: stopPlayer

@Override
public void stopPlayer() {
    playerState=PlaybackStateCompat.STATE_STOPPED;
    if (player != null) {
        player.release();
        player=null;
    }
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:8,代码来源:MediaPlayback.java

示例14: updatePlaybackState

public void updatePlaybackState(PlaybackStateCompat playbackState){
    this.playbackState=playbackState;
    if(playbackState.getState()==PlaybackStateCompat.STATE_STOPPED||
            playbackState.getState()==PlaybackStateCompat.STATE_NONE){
        stopNotification();
    }else{
        updateNotification();
    }
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:9,代码来源:TrackNotification.java

示例15: updatePlaybackState

@Override
public void updatePlaybackState(int state) {
    Logger.e("updatePlaybackState: ", "" + state);
    switch (state) {
        case PlaybackStateCompat.STATE_PLAYING:
            pgPlayPauseLayout.setVisibility(View.INVISIBLE);
            btn_play.Play();
            if (currentSong != null) {
                currentSong.setPlayState(PlaybackStateCompat.STATE_PLAYING);
                notifyAdapter(currentSong);
            }
            break;
        case PlaybackStateCompat.STATE_PAUSED:
            pgPlayPauseLayout.setVisibility(View.INVISIBLE);
            btn_play.Pause();
            if (currentSong != null) {
                currentSong.setPlayState(PlaybackStateCompat.STATE_PAUSED);
                notifyAdapter(currentSong);
            }
            break;
        case PlaybackStateCompat.STATE_NONE:
            currentSong.setPlayState(PlaybackStateCompat.STATE_NONE);
            notifyAdapter(currentSong);
            break;
        case PlaybackStateCompat.STATE_STOPPED:
            pgPlayPauseLayout.setVisibility(View.INVISIBLE);
            btn_play.Pause();
            audioPg.setValue(0);
            if (currentSong != null) {
                currentSong.setPlayState(PlaybackStateCompat.STATE_NONE);
                notifyAdapter(currentSong);
            }
            break;
        case PlaybackStateCompat.STATE_BUFFERING:
            pgPlayPauseLayout.setVisibility(View.VISIBLE);
            if (currentSong != null) {
                currentSong.setPlayState(PlaybackStateCompat.STATE_NONE);
                notifyAdapter(currentSong);
            }
            break;
    }
}
 
开发者ID:dibakarece,项目名称:DMAudioStreamer,代码行数:42,代码来源:MusicActivity.java


注:本文中的android.support.v4.media.session.PlaybackStateCompat.STATE_STOPPED属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。