當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。