本文整理汇总了Java中android.support.v4.media.session.MediaControllerCompat.getPlaybackState方法的典型用法代码示例。如果您正苦于以下问题:Java MediaControllerCompat.getPlaybackState方法的具体用法?Java MediaControllerCompat.getPlaybackState怎么用?Java MediaControllerCompat.getPlaybackState使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.media.session.MediaControllerCompat
的用法示例。
在下文中一共展示了MediaControllerCompat.getPlaybackState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: playPause
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@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());
}
}
}
示例2: onConnected
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
public void onConnected()
{
MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
LogHelper.e(TAG, "onConnected, mediaController==null? ", controller == null);
if (controller != null) {
controller.registerCallback(mCallback);
onPlaybackStateChanged(controller.getPlaybackState());
onMetadataChanged(controller.getMetadata());
PlaybackStateCompat state = controller.getPlaybackState();
updatePlaybackState(state);
MediaMetadataCompat metadata = controller.getMetadata();
if (metadata != null) {
updateMediaDescription(metadata.getDescription());
updateDuration(metadata);
}
updateProgress();
if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING ||
state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
scheduleSeekbarUpdate();
}
}
}
示例3: shouldShowControls
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
/**
* Check if the MediaSession is active and in a "playback-able" state
* (not NONE and not STOPPED).
*
* @return true if the MediaSession's state requires playback controls to be visible.
*/
protected boolean shouldShowControls()
{
LogHelper.e(TAG, "shouldShowControls");
MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(this);
if (mediaController == null ||
mediaController.getMetadata() == null ||
mediaController.getPlaybackState() == null) {
return false;
}
switch (mediaController.getPlaybackState().getState()) {
case PlaybackStateCompat.STATE_ERROR:
case PlaybackStateCompat.STATE_NONE:
case PlaybackStateCompat.STATE_STOPPED:
return false;
default:
return true;
}
}
示例4: shouldShowControls
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
/**
* Check if the MediaSession is active and in a "playback-able" state
* (not NONE and not STOPPED).
*
* @return true if the MediaSession's state requires playback controls to be visible.
*/
protected boolean shouldShowControls() {
MediaControllerCompat mediaController = mMediaController;
if (mediaController == null ||
mediaController.getMetadata() == null ||
mediaController.getPlaybackState() == null) {
return false;
}
switch (mediaController.getPlaybackState().getState()) {
case PlaybackState.STATE_ERROR:
case PlaybackState.STATE_NONE:
case PlaybackState.STATE_STOPPED:
return false;
default:
return true;
}
}
示例5: isQueueItemPlaying
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
/**
* Determine if queue item matches the currently playing queue item
*
* @param context for retrieving the {@link MediaControllerCompat}
* @param queueItem to compare to currently playing {@link MediaSessionCompat.QueueItem}
* @return boolean indicating whether queue item matches currently playing queue item
*/
public static boolean isQueueItemPlaying(Activity context,
MediaSessionCompat.QueueItem queueItem) {
// Queue item is considered to be playing or paused based on both the controller's
// current media id and the controller's active queue item id
MediaControllerCompat controller = MediaControllerCompat.getMediaController(context);
if (controller != null && controller.getPlaybackState() != null) {
long currentPlayingQueueId = controller.getPlaybackState().getActiveQueueItemId();
String currentPlayingMediaId = controller.getMetadata().getDescription()
.getMediaId();
String itemMusicId = MediaIDHelper.extractMusicIDFromMediaID(
queueItem.getDescription().getMediaId());
if (queueItem.getQueueId() == currentPlayingQueueId
&& currentPlayingMediaId != null
&& TextUtils.equals(currentPlayingMediaId, itemMusicId)) {
return true;
}
}
return false;
}
示例6: onClick
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
MediaControllerCompat controller = MediaControllerCompat.getMediaController(getActivity());
PlaybackStateCompat stateObj = controller.getPlaybackState();
final int state = stateObj == null ?
PlaybackStateCompat.STATE_NONE : stateObj.getState();
LogHelper.d(TAG, "Button pressed, in state " + state);
switch (v.getId()) {
case R.id.play_pause:
LogHelper.d(TAG, "Play button pressed, in state " + state);
if (state == PlaybackStateCompat.STATE_PAUSED ||
state == PlaybackStateCompat.STATE_STOPPED ||
state == PlaybackStateCompat.STATE_NONE) {
playMedia();
} else if (state == PlaybackStateCompat.STATE_PLAYING ||
state == PlaybackStateCompat.STATE_BUFFERING ||
state == PlaybackStateCompat.STATE_CONNECTING) {
pauseMedia();
}
break;
}
}
示例7: shouldShowControls
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
/**
* Check if the MediaSession is active and in a "playback-able" state
* (not NONE and not STOPPED).
*
* @return true if the MediaSession's state requires playback controls to be visible.
*/
protected boolean shouldShowControls() {
MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(this);
if (mediaController == null ||
mediaController.getMetadata() == null ||
mediaController.getPlaybackState() == null) {
return false;
}
switch (mediaController.getPlaybackState().getState()) {
case PlaybackStateCompat.STATE_ERROR:
case PlaybackStateCompat.STATE_NONE:
case PlaybackStateCompat.STATE_STOPPED:
return false;
default:
return true;
}
}
示例8: connectToSession
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private void connectToSession(MediaSessionCompat.Token token) throws RemoteException {
MediaControllerCompat mediaController = new MediaControllerCompat(
FullScreenPlayerActivity.this, token);
if (mediaController.getMetadata() == null) {
finish();
return;
}
MediaControllerCompat.setMediaController(FullScreenPlayerActivity.this, mediaController);
mediaController.registerCallback(mCallback);
PlaybackStateCompat state = mediaController.getPlaybackState();
updatePlaybackState(state);
MediaMetadataCompat metadata = mediaController.getMetadata();
if (metadata != null) {
updateMediaDescription(metadata.getDescription());
updateDuration(metadata);
}
updateProgress();
if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING ||
state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
scheduleSeekbarUpdate();
}
}
示例9: getView
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
MediaBrowserCompat.MediaItem item = getItem(position);
int itemState = MediaItemViewHolder.STATE_NONE;
if (item.isPlayable()) {
itemState = MediaItemViewHolder.STATE_PLAYABLE;
MediaControllerCompat controller = mMediaControllerProvider.getSupportMediaController();
if (controller != null && controller.getMetadata() != null) {
String currentPlaying = controller.getMetadata().getDescription().getMediaId();
String musicId = MediaIDHelper.extractMusicIDFromMediaID(
item.getDescription().getMediaId());
if (currentPlaying != null && currentPlaying.equals(musicId)) {
PlaybackStateCompat pbState = controller.getPlaybackState();
if (pbState == null || pbState.getState() == PlaybackStateCompat.STATE_ERROR) {
itemState = MediaItemViewHolder.STATE_NONE;
} else if (pbState.getState() == PlaybackStateCompat.STATE_PLAYING) {
itemState = MediaItemViewHolder.STATE_PLAYING;
} else {
itemState = MediaItemViewHolder.STATE_PAUSED;
}
}
}
}
return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent,
item.getDescription(), itemState);
}
示例10: shouldShowControls
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
/**
* Check if the MediaSession is active and in a "playback-able" state
* (not NONE and not STOPPED).
*
* @return true if the MediaSession's state requires playback controls to be visible.
*/
protected boolean shouldShowControls() {
MediaControllerCompat mediaController = mMediaController;
if (mediaController == null ||
mediaController.getMetadata() == null ||
mediaController.getPlaybackState() == null) {
return false;
}
switch (mediaController.getPlaybackState().getState()) {
case PlaybackState.STATE_ERROR:
case PlaybackState.STATE_NONE:
case PlaybackState.STATE_STOPPED:
return false;
default:
return true;
}
}
示例11: connectToSession
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private void connectToSession(MediaSessionCompat.Token token) {
try {
mMediaController = new MediaControllerCompat(FullScreenPlayerActivity.this, token);
if (mMediaController.getMetadata() == null) {
finish();
return;
}
mMediaController.registerCallback(mCallback);
PlaybackStateCompat state = mMediaController.getPlaybackState();
updatePlaybackState(state);
MediaMetadataCompat metadata = mMediaController.getMetadata();
if (metadata != null) {
updateMediaDescription(metadata.getDescription());
updateDuration(metadata);
}
updateProgress();
if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING ||
state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
scheduleSeekbarUpdate();
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
示例12: shouldShowControls
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
protected boolean shouldShowControls() {
MediaControllerCompat mediaController = getMediaControllerCompat();
if (mediaController == null ||
mediaController.getMetadata() == null ||
mediaController.getPlaybackState() == null) {
return false;
}
switch (mediaController.getPlaybackState().getState()) {
case PlaybackState.STATE_ERROR:
case PlaybackState.STATE_NONE:
case PlaybackState.STATE_STOPPED:
return false;
default:
return true;
}
}
示例13: isPlaying
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
public static boolean isPlaying(MediaControllerCompat mediaControllerCompat, PlaybackStateCompat playbackStateCompat, MediaId mediaId) {
if (isEquals(mediaControllerCompat, mediaId)) {
if (playbackStateCompat == null)
playbackStateCompat = mediaControllerCompat.getPlaybackState();
int state = -1;
if (playbackStateCompat != null)
state = playbackStateCompat.getState();
return state == PlaybackStateCompat.STATE_BUFFERING || state == PlaybackStateCompat.STATE_PLAYING;
}
return false;
}
示例14: connectToSession
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private void connectToSession(MediaSessionCompat.Token token) {
try {
mMediaController = new MediaControllerCompat(FullScreenPlayerActivity.this, token);
if (mMediaController.getMetadata() == null) {
finish();
return;
}
mMediaController.registerCallback(mCallback);
PlaybackStateCompat state = mMediaController.getPlaybackState();
updatePlaybackState(state);
MediaMetadataCompat metadata = mMediaController.getMetadata();
if (metadata != null) {
updateMediaDescription(metadata.getDescription());
updateDuration(metadata);
}
updateProgress();
if (state != null && (state.getState() == PlaybackStateCompat.STATE_PLAYING ||
state.getState() == PlaybackStateCompat.STATE_BUFFERING)) {
scheduleSeekbarUpdate();
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
示例15: onMetadataChanged
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onMetadataChanged(MediaMetadataCompat metadata) {
if (metadata != null) {
MediaControllerCompat mediaController = MediaControllerCompat.getMediaController(getActivity());
long activeQueueId;
if (mediaController.getPlaybackState() == null) {
activeQueueId = MediaSessionCompat.QueueItem.UNKNOWN_ID;
} else {
activeQueueId = mediaController.getPlaybackState().getActiveQueueItemId();
}
updateNowPlayingList(mediaController.getQueue(), activeQueueId);
mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
}
}