本文整理汇总了Java中android.support.v4.media.session.MediaControllerCompat.getMetadata方法的典型用法代码示例。如果您正苦于以下问题:Java MediaControllerCompat.getMetadata方法的具体用法?Java MediaControllerCompat.getMetadata怎么用?Java MediaControllerCompat.getMetadata使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v4.media.session.MediaControllerCompat
的用法示例。
在下文中一共展示了MediaControllerCompat.getMetadata方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: from
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
/**
* Build a notification using the information from the given media session. Makes heavy use
* of {@link MediaMetadataCompat#getDescription()} to extract the appropriate information.
*
* @param context Context used to construct the notification.
* @param mediaSession Media session to get information.
* @return A pre-built notification with information from the given media session.
*/
static NotificationCompat.Builder from(
Context context, MediaSessionCompat mediaSession) {
MediaControllerCompat controller = mediaSession.getController();
MediaMetadataCompat mediaMetadata = controller.getMetadata();
MediaDescriptionCompat description = mediaMetadata.getDescription();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder
.setContentTitle(description.getTitle())
.setContentText(description.getSubtitle())
.setSubText(description.getDescription())
.setLargeIcon(description.getIconBitmap())
.setContentIntent(controller.getSessionActivity())
.setDeleteIntent(
MediaButtonReceiver.buildMediaButtonPendingIntent(context, PlaybackStateCompat.ACTION_STOP))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
return builder;
}
示例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: checkForUserVisibleErrors
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private void checkForUserVisibleErrors(boolean forceError) {
boolean showError = forceError;
// If offline, message is about the lack of connectivity:
if (!NetworkHelper.isOnline(getActivity())) {
mErrorMessage.setText(R.string.error_no_connection);
showError = true;
} else {
// otherwise, if state is ERROR and metadata!=null, use playback state error message:
MediaControllerCompat controller = mMediaControllerProvider.getSupportMediaController();
if (controller != null
&& controller.getMetadata() != null
&& controller.getPlaybackState().getState() == PlaybackState.STATE_ERROR
&& controller.getPlaybackState().getErrorMessage() != null) {
mErrorMessage.setText(controller.getPlaybackState().getErrorMessage());
showError = true;
} else if (forceError) {
// Finally, if the caller requested to show error, show a generic message:
mErrorMessage.setText(R.string.error_loading_media);
showError = true;
}
}
mErrorView.setVisibility(showError ? View.VISIBLE : View.GONE);
LogHelper.d(TAG, "checkForUserVisibleErrors. forceError=", forceError,
" showError=", showError,
" isOnline=", NetworkHelper.isOnline(getActivity()));
}
示例5: 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 state = MediaItemViewHolder.STATE_NONE;
if (item.isPlayable()) {
state = 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)) {
if (controller.getPlaybackState().getState() == PlaybackStateCompat.STATE_PLAYING) {
state = MediaItemViewHolder.STATE_PLAYING;
} else if (controller.getPlaybackState().getState() != PlaybackStateCompat.STATE_ERROR) {
state = MediaItemViewHolder.STATE_PAUSED;
}
}
}
}
return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent, item.getDescription(), state);
}
示例6: 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;
}
}
示例7: isMediaItemPlaying
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
/**
* Determine if media item is playing (matches the currently playing media item).
*
* @param context for retrieving the {@link MediaControllerCompat}
* @param mediaItem to compare to currently playing {@link MediaBrowserCompat.MediaItem}
* @return boolean indicating whether media item matches currently playing media item
*/
public static boolean isMediaItemPlaying(Activity context, MediaBrowserCompat.MediaItem mediaItem) {
// Media item is considered to be playing or paused based on the controller's current
// media id
MediaControllerCompat controller = MediaControllerCompat.getMediaController(context);
if (controller != null && controller.getMetadata() != null) {
String currentPlayingMediaId = controller.getMetadata().getDescription()
.getMediaId();
String itemMusicId = MediaIDHelper.extractMusicIDFromMediaID(
mediaItem.getDescription().getMediaId());
if (currentPlayingMediaId != null
&& TextUtils.equals(currentPlayingMediaId, itemMusicId)) {
return true;
}
}
return false;
}
示例8: onConnected
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
@Override
public void onConnected() {
LogHelper.d(TAG, "onConnected");
try {
MediaControllerCompat mediaController = new MediaControllerCompat(
TvPlaybackActivity.this, mMediaBrowser.getSessionToken());
MediaControllerCompat.setMediaController(TvPlaybackActivity.this, mediaController);
mediaController.registerCallback(mMediaControllerCallback);
MediaMetadataCompat metadata = mediaController.getMetadata();
if (metadata != null) {
mPlaybackFragment.updateMetadata(metadata);
mPlaybackFragment.updatePlaybackState(mediaController.getPlaybackState());
}
} catch (RemoteException e) {
LogHelper.e(TAG, e, "could not connect media controller");
}
}
示例9: 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;
}
}
示例10: 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();
}
}
示例11: 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);
}
示例12: 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;
}
}
示例13: 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();
}
}
示例14: notificationBuilder
import android.support.v4.media.session.MediaControllerCompat; //导入方法依赖的package包/类
private NotificationCompat.Builder notificationBuilder(PlayerService context, MediaSessionCompat session) {
MediaControllerCompat controller = session.getController();
MediaMetadataCompat mediaMetadata = controller.getMetadata();
MediaDescriptionCompat description = mediaMetadata.getDescription();
NotificationCompat.Builder builder = new NotificationCompat.Builder(context);
builder
.setContentTitle(description.getTitle())
.setContentText(description.getSubtitle())
.setSubText(description.getDescription())
.setLargeIcon(mediaMetadata.getBitmap(MediaMetadataCompat.METADATA_KEY_ART))
.setContentIntent(clickIntent)
.setDeleteIntent(
MediaButtonReceiver.buildMediaButtonPendingIntent(context, receiverName, PlaybackStateCompat.ACTION_STOP))
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC);
return builder;
}
示例15: 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;
}
}