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


Java MediaControllerCompat.getMetadata方法代码示例

本文整理汇总了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;
}
 
开发者ID:SergeyVinyar,项目名称:AndroidAudioExample,代码行数:27,代码来源:MediaStyleHelper.java

示例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();
        }
    }
}
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:24,代码来源:PlaybackControlsFragment.java

示例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;
    }
}
 
开发者ID:teocci,项目名称:YouTube-In-Background,代码行数:25,代码来源:MainActivity.java

示例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()));
}
 
开发者ID:SoumyaParida,项目名称:MyGaana-Universal,代码行数:27,代码来源:MediaBrowserFragment.java

示例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);
}
 
开发者ID:SoumyaParida,项目名称:MyGaana-Universal,代码行数:23,代码来源:MediaBrowserFragment.java

示例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;
    }
}
 
开发者ID:SoumyaParida,项目名称:MyGaana-Universal,代码行数:23,代码来源:BaseActivity.java

示例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;
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:24,代码来源:MediaIDHelper.java

示例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");
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:19,代码来源:TvPlaybackActivity.java

示例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;
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:23,代码来源:BaseActivity.java

示例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();
    }
}
 
开发者ID:googlesamples,项目名称:android-UniversalMusicPlayer,代码行数:23,代码来源:FullScreenPlayerActivity.java

示例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);
}
 
开发者ID:markzhai,项目名称:LyricHere,代码行数:27,代码来源:MediaBrowserFragment.java

示例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;
    }
}
 
开发者ID:markzhai,项目名称:LyricHere,代码行数:23,代码来源:PlaybackControlBaseActivity.java

示例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();
    }
}
 
开发者ID:markzhai,项目名称:LyricHere,代码行数:27,代码来源:FullScreenPlayerActivity.java

示例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;
}
 
开发者ID:SpongeBobSun,项目名称:Prodigal,代码行数:18,代码来源:NotificationUtil.java

示例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;
    }
}
 
开发者ID:berwyn,项目名称:ponyville-live-android,代码行数:18,代码来源:BaseActivity.java


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