本文整理汇总了Java中android.support.v4.media.session.PlaybackStateCompat.STATE_BUFFERING属性的典型用法代码示例。如果您正苦于以下问题:Java PlaybackStateCompat.STATE_BUFFERING属性的具体用法?Java PlaybackStateCompat.STATE_BUFFERING怎么用?Java PlaybackStateCompat.STATE_BUFFERING使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类android.support.v4.media.session.PlaybackStateCompat
的用法示例。
在下文中一共展示了PlaybackStateCompat.STATE_BUFFERING属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: seekTo
@Override
public void seekTo(int position) {
Logger.d(TAG, "seekTo called with ", position);
if (mMediaPlayer == null) {
// If we do not have a current media player, simply update the current position
mCurrentPosition = position;
} else {
if (mMediaPlayer.isPlaying()) {
mState = PlaybackStateCompat.STATE_BUFFERING;
}
registerAudioNoisyReceiver();
mMediaPlayer.seekTo(position);
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
}
}
示例2: onSeekComplete
@Override
public void onSeekComplete(MediaPlayer mp) {
Logger.d(TAG, "onSeekComplete from MediaPlayer:", mp.getCurrentPosition());
mCurrentPosition = mp.getCurrentPosition();
if (mState == PlaybackStateCompat.STATE_BUFFERING) {
registerAudioNoisyReceiver();
mMediaPlayer.start();
mState = PlaybackStateCompat.STATE_PLAYING;
}
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
}
示例3: getView
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MediaBrowserCompat.MediaItem item = getItem(position);
int itemState = MediaItemViewHolder.STATE_NONE;
if (item.isPlayable()) {
String itemMediaId = item.getDescription().getMediaId();
int playbackState = PlaybackStateCompat.STATE_NONE;
if (mCurrentState != null) {
playbackState = mCurrentState.getState();
}
if (mCurrentMetadata != null
&& itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) {
if (playbackState == PlaybackStateCompat.STATE_PLAYING
|| playbackState == PlaybackStateCompat.STATE_BUFFERING) {
itemState = MediaItemViewHolder.STATE_PLAYING;
} else if (playbackState != PlaybackStateCompat.STATE_ERROR) {
itemState = MediaItemViewHolder.STATE_PAUSED;
}
}
}
return MediaItemViewHolder.setupView(
(Activity) getContext(), convertView, parent, item.getDescription(), itemState);
}
示例4: 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());
}
}
}
示例5: 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!";
}
}
示例6: configMediaPlayerState
private void configMediaPlayerState() {
Logger.d(TAG, "configMediaPlayerState. mAudioFocus=", mAudioFocus);
if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
// If we don't have audio focus and can't duck, we have to pause,
if (mState == PlaybackStateCompat.STATE_PLAYING) {
mPlayOnFocusGain = false;
pause();
}
} else { // we have audio focus:
registerAudioNoisyReceiver();
if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet
} else {
if (mMediaPlayer != null) {
mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again
} // else do something for remote client.
}
// If we were playing when we lost focus, we need to resume playing.
if (mPlayOnFocusGain) {
if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
Logger.d(TAG, "configMediaPlayerState startMediaPlayer. seeking to ",
mCurrentPosition);
if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) {
mMediaPlayer.start();
mState = PlaybackStateCompat.STATE_PLAYING;
} else {
mMediaPlayer.seekTo(mCurrentPosition);
mState = PlaybackStateCompat.STATE_BUFFERING;
}
}
mPlayOnFocusGain = false;
}
}
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
}
示例7: onSeekComplete
@Override
public void onSeekComplete(MediaPlayer mediaPlayer) {
Log.i(TAG, "onSeekComplete, current position: " + mCurrentPosition);
mCurrentPosition = mediaPlayer.getCurrentPosition();
if (mPlaybackState == PlaybackStateCompat.STATE_BUFFERING) {
mPlayer.start();
mPlaybackState = PlaybackStateCompat.STATE_PLAYING;
}
if (mCallback != null) {
mCallback.onPlayStateChanged(mPlaybackState);
}
}
示例8: configMediaPlayerState
private void configMediaPlayerState() {
Log.i(TAG, "configMediaPlayerState audio focus = " + mFocusState);
if (mFocusState == AUDIO_NO_FOCUS_NO_DUCK) {
if (mPlaybackState == PlaybackStateCompat.STATE_PLAYING) {
pause();
}
} else {
if (mFocusState == AUDIO_NO_FOCUS_CAN_DUCK) {
if (mPlayer != null) {
mPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK);
}
} else {
if (mPlayer != null) {
mPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL);
}
}
if (mPlayOnFocusGain) {
if (mPlayer != null && !mPlayer.isPlaying()) {
Log.d(TAG, "configMediaPlayerState startMediaPlayer. seeking to "
+ getCurrentStreamPosition());
if (mCurrentPosition == mPlayer.getCurrentPosition()) {
mPlayer.start();
mPlaybackState = PlaybackStateCompat.STATE_PLAYING;
} else {
mPlayer.seekTo(mCurrentPosition);
mPlaybackState = PlaybackStateCompat.STATE_BUFFERING;
}
}
mPlayOnFocusGain = false;
}
}
if (mCallback != null) {
mCallback.onPlayStateChanged(mPlaybackState);
}
}
示例9: seekTo
public void seekTo(int position) {
if (mMediaPlayer == null) {
// If we do not have a current media player, simply update the current position
mCurrentPosition = position;
} else {
if (mMediaPlayer.isPlaying()) {
mState = PlaybackStateCompat.STATE_BUFFERING;
}
registerAudioNoisyReceiver();
mMediaPlayer.seekTo(position);
if (mCallback != null) {
mCallback.onPlaybackStateChanged(mState);
}
}
}
示例10: configMediaPlayerState
/**
* Reconfigures MediaPlayer according to audio focus settings and
* starts/restarts it. This method starts/restarts the MediaPlayer
* respecting the current audio focus state. So if we have focus, it will
* play normally; if we don't have focus, it will either leave the
* MediaPlayer paused or set it to a low volume, depending on what is
* allowed by the current focus settings. This method assumes mPlayer !=
* null, so if you are calling it, you have to do so from a context where
* you are sure this is the case.
*/
private void configMediaPlayerState() {
if (mAudioFocus == AUDIO_NO_FOCUS_NO_DUCK) {
// If we don't have audio focus and can't duck, we have to pause,
if (mState == PlaybackStateCompat.STATE_PLAYING) {
pause();
}
} else { // we have audio focus:
registerAudioNoisyReceiver();
if (mAudioFocus == AUDIO_NO_FOCUS_CAN_DUCK) {
mMediaPlayer.setVolume(VOLUME_DUCK, VOLUME_DUCK); // we'll be relatively quiet
} else {
if (mMediaPlayer != null) {
mMediaPlayer.setVolume(VOLUME_NORMAL, VOLUME_NORMAL); // we can be loud again
} // else do something for remote client.
}
// If we were playing when we lost focus, we need to resume playing.
if (mPlayOnFocusGain) {
if (mMediaPlayer != null && !mMediaPlayer.isPlaying()) {
if (mCurrentPosition == mMediaPlayer.getCurrentPosition()) {
mMediaPlayer.start();
mState = PlaybackStateCompat.STATE_PLAYING;
} else {
mMediaPlayer.seekTo(mCurrentPosition);
mState = PlaybackStateCompat.STATE_BUFFERING;
}
}
mPlayOnFocusGain = false;
}
}
if (mCallback != null) {
mCallback.onPlaybackStateChanged(mState);
}
}
示例11: seekTo
@Override
public void seekTo(int position) {
Log.d(TAG,"Player is null:"+Boolean.toString(player==null));
Log.d(TAG,"Player's position:"+Integer.toString(position));
if(player!=null){
if(player.isPlaying()){
playerState=PlaybackStateCompat.STATE_BUFFERING;
}
registerNoiseReceiver();
player.seekTo(position);
}
}
示例12: updateMediaSession
@TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
private void updateMediaSession(boolean playing) {
if (!isFeatureEnabled(CastConfiguration.FEATURE_LOCKSCREEN)) {
return;
}
if (!isConnected()) {
return;
}
try {
if ((mMediaSessionCompat == null) && playing) {
setUpMediaSession(getRemoteMediaInformation());
}
if (mMediaSessionCompat != null) {
int playState = isRemoteStreamLive() ? PlaybackStateCompat.STATE_BUFFERING
: PlaybackStateCompat.STATE_PLAYING;
int state = playing ? playState : PlaybackStateCompat.STATE_PAUSED;
PendingIntent pi = getCastControllerPendingIntent();
if (pi != null) {
mMediaSessionCompat.setSessionActivity(pi);
}
mMediaSessionCompat.setPlaybackState(new PlaybackStateCompat.Builder()
.setState(state, 0, 1.0f)
.setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE).build());
}
} catch (TransientNetworkDisconnectionException | NoConnectionException e) {
LOGE(TAG, "Failed to set up MediaSessionCompat due to network issues", e);
}
}
示例13: startPlayer
@Override
public void startPlayer() {
createPlayerIfNeeded();
try {
playerState=PlaybackStateCompat.STATE_BUFFERING;
player.setAudioStreamType(AudioManager.STREAM_MUSIC);
player.setDataSource(currentUrl);
player.prepareAsync();
}catch (IOException ex){
ex.printStackTrace();
//notify UI
if(callback!=null) callback.onError();
}
}
示例14: onSeekComplete
@Override
public void onSeekComplete(MediaPlayer mp) {
Log.d(TAG,"State:"+playerState);
if(playerState==PlaybackStateCompat.STATE_BUFFERING){
registerNoiseReceiver();
player.start();
playerState = PlaybackStateCompat.STATE_PLAYING;
}
}
示例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;
}
}