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


Java PlaybackStateCompat.Builder方法代码示例

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


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

示例1: setState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void setState(int state) {
  long position = 0;
  if (mPlayer != null && mPlayer.isPlaying()) {
    position = mPlayer.getCurrentPosition();
  }

  PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder();
  builder.setState(state, position, 1.0f);
  builder.setActions(
      PlaybackStateCompat.ACTION_PLAY |
      PlaybackStateCompat.ACTION_STOP |
      PlaybackStateCompat.ACTION_REWIND |
      PlaybackStateCompat.ACTION_FAST_FORWARD |
      PlaybackStateCompat.ACTION_PAUSE |
      PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
      PlaybackStateCompat.ACTION_SKIP_TO_NEXT);
  mMediaSession.setPlaybackState(builder.build());
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:19,代码来源:AudioService.java

示例2: updatePlaybackState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updatePlaybackState(
        @PlaybackStateCompat.State int state, long playbackActions, int position, int mediaId) {
    PlaybackStateCompat.Builder builder =
            new PlaybackStateCompat.Builder()
                    .setActions(playbackActions)
                    .setActiveQueueItemId(mediaId)
                    .setState(state, position, 1.0f);
    mSession.setPlaybackState(builder.build());
}
 
开发者ID:googlesamples,项目名称:android-PictureInPicture,代码行数:10,代码来源:MediaSessionPlaybackActivity.java

示例3: updatePlaybackState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updatePlaybackState() {
    if (mCallback == null) {
        return;
    }
    PlaybackStateCompat.Builder stateBuilder =
            new PlaybackStateCompat.Builder().setActions(getAvailableActions());

    stateBuilder.setState(
            mState, getCurrentStreamPosition(), 1.0f, SystemClock.elapsedRealtime());
    mCallback.onPlaybackStatusChanged(stateBuilder.build());
}
 
开发者ID:googlecodelabs,项目名称:musicplayer-devices,代码行数:12,代码来源:PlaybackManager.java

示例4: setPlaybackState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void setPlaybackState(int state) {
    long currPosition = getCurrentPosition();

    PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
            .setActions(getAvailableActions(state));
    stateBuilder.setState(state, currPosition, 1.0f);
    mSession.setPlaybackState(stateBuilder.build());
}
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:9,代码来源:PlaybackOverlayFragment.java

示例5: updateMediaSession

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updateMediaSession() {
    if (!mMediaNotificationInfo.supportsPlayPause()) return;

    if (mMediaSession == null) mMediaSession = createMediaSession();

    try {
        // Tell the MediaRouter about the session, so that Chrome can control the volume
        // on the remote cast device (if any).
        // Pre-MR1 versions of JB do not have the complete MediaRouter APIs,
        // so getting the MediaRouter instance will throw an exception.
        MediaRouter.getInstance(mContext).setMediaSessionCompat(mMediaSession);
    } catch (NoSuchMethodError e) {
        // Do nothing. Chrome can't be casting without a MediaRouter, so there is nothing
        // to do here.
    }

    mMediaSession.setMetadata(createMetadata());

    PlaybackStateCompat.Builder playbackStateBuilder =
            new PlaybackStateCompat.Builder().setActions(computeMediaSessionActions());
    if (mMediaNotificationInfo.isPaused) {
        playbackStateBuilder.setState(PlaybackStateCompat.STATE_PAUSED,
                PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f);
    } else {
        // If notification only supports stop, still pretend
        playbackStateBuilder.setState(PlaybackStateCompat.STATE_PLAYING,
                PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN, 1.0f);
    }
    mMediaSession.setPlaybackState(playbackStateBuilder.build());
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:31,代码来源:MediaNotificationManager.java

示例6: updatePlaybackState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updatePlaybackState() {
    PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
            .setActions(getAvailableActions());
    int state = PlaybackStateCompat.STATE_PLAYING;
    if (!mMediaPlayerGlue.isPlaying()) {
        state = PlaybackState.STATE_PAUSED;
    }
    stateBuilder.setState(state, mMediaPlayerGlue.getCurrentPosition(), 1.0f);
    mSession.setPlaybackState(stateBuilder.build());
}
 
开发者ID:googlesamples,项目名称:leanback-homescreen-channels,代码行数:11,代码来源:VideoFragment.java

示例7: updatePlaybackState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
/**
 * Update the current media player state, optionally showing an error message.
 */
public void updatePlaybackState() {
    long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
    if (mPlayback != null ) {
        position = mPlayback.getCurrentPosition();
    }
    long actions =
            PlaybackStateCompat.ACTION_PLAY_PAUSE |
            PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
            PlaybackStateCompat.ACTION_SKIP_TO_NEXT;

    if (mPlayback != null && mPlayback.isPlaying()) {
        actions |= PlaybackStateCompat.ACTION_PAUSE;
    } else {
        actions |= PlaybackStateCompat.ACTION_PLAY;
    }

    int state = mPlayback.getState();

    //noinspection ResourceType
    PlaybackStateCompat.Builder stateBuilder = new PlaybackStateCompat.Builder()
            .setActions(actions)
            .setState(state, position, 1.0f, SystemClock.elapsedRealtime());

    mMediaSession.setPlaybackState(stateBuilder.build());

    Intent intent = new Intent("change-playback-state-event");
    intent.putExtra("state", state);
    LocalBroadcastManager.getInstance(getApplicationContext()).sendBroadcast(intent);
}
 
开发者ID:AllThatSeries,项目名称:react-native-streaming-audio-player,代码行数:33,代码来源:AudioPlayerService.java

示例8: updatePlaybackState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
public void updatePlaybackState(int state){
    long position = playback.getPosition();
    this.lastState=state;
    if (state == PlaybackStateCompat.STATE_PLAYING ||
            state == PlaybackStateCompat.STATE_PAUSED) {
        serviceCallback.onNotificationRequired();
    }
    PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder()
            .setActions(getAvailableActions())
            .setState(state, position, 1.0f, SystemClock.elapsedRealtime());
    serviceCallback.onPlaybackStateUpdated(builder.build());
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:13,代码来源:PlaybackManager.java

示例9: setNewState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
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,代码行数:30,代码来源:MediaPlayerAdapter.java

示例10: updatePlaybackState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
private void updatePlaybackState(
        @PlaybackStateCompat.State int state,
        long position,
        MediaDescriptionCompat description) {
    PlaybackStateCompat.Builder builder =
            new PlaybackStateCompat.Builder()
                    .setActions(AVAILABLE_MEDIA_ACTIONS)
                    .setActiveQueueItemId(Long.parseLong(description.getMediaId()))
                    .setState(state, position, 1.0f);
    mSession.setPlaybackState(builder.build());
}
 
开发者ID:googlesamples,项目名称:leanback-assistant,代码行数:12,代码来源:PlaybackFragment.java

示例11: setNewState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
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,代码行数:30,代码来源:MediaPlayerManager.java

示例12: updatePlaybackState

import android.support.v4.media.session.PlaybackStateCompat; //导入方法依赖的package包/类
public void updatePlaybackState(int errorCode, String errorMsg) {
        Log.d(TAG, "updatePlaybackState, playback state = " + mPlayback.getState());
        long position = PlaybackStateCompat.PLAYBACK_POSITION_UNKNOWN;
        if (mPlayback != null && mPlayback.isConnected()) {
            position = mPlayback.getCurrentStreamPosition();
        }

        long playbackActions = PlaybackStateCompat.ACTION_PLAY
                | PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID;

        if (mPlayback.isPlaying()) {
            playbackActions |= PlaybackStateCompat.ACTION_PAUSE;
        }

        PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder().setActions(playbackActions);

        int state = mPlayback.getState();

        if (errorCode != -1 && errorMsg != null) {
            builder.setErrorMessage(errorCode, errorMsg);
            state = PlaybackStateCompat.STATE_ERROR;
        }

        builder.setState(state, position, SystemClock.elapsedRealtime());

         MediaSessionCompat.QueueItem currentMedia = mQueueManager.getCurrentMedia();
        if (currentMedia != null) {
            builder.setActiveQueueItemId(currentMedia.getQueueId());
        }

//        mSession.setPlaybackState(builder.build());

        mServiceCallback.onPlaybackStateUpdate(builder.build());

//        if (state == PlaybackStateCompat.STATE_PLAYING ||
//                state == PlaybackStateCompat.STATE_PAUSED) {
//            mServiceCallback.onHandleNotification();
//        }

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


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