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


Java MediaController.getMetadata方法代码示例

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


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

示例1: getView

import android.media.session.MediaController; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MediaBrowser.MediaItem item = getItem(position);
    int itemState = MediaItemViewHolder.STATE_NONE;
    if (item.isPlayable()) {
        itemState = MediaItemViewHolder.STATE_PLAYABLE;
        MediaController controller = ((Activity) getContext()).getMediaController();
        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)) {
                PlaybackState pbState = controller.getPlaybackState();
                if (pbState == null || pbState.getState() == PlaybackState.STATE_ERROR) {
                    itemState = MediaItemViewHolder.STATE_NONE;
                } else if (pbState.getState() == PlaybackState.STATE_PLAYING) {
                    itemState = MediaItemViewHolder.STATE_PLAYING;
                } else {
                    itemState = MediaItemViewHolder.STATE_PAUSED;
                }
            }
        }
    }
    return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent,
        item.getDescription(), itemState);
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:27,代码来源:MediaBrowserFragment.java

示例2: shouldShowControls

import android.media.session.MediaController; //导入方法依赖的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() {
    MediaController mediaController = getMediaController();
    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:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:23,代码来源:BaseActivity.java

示例3: connectToSession

import android.media.session.MediaController; //导入方法依赖的package包/类
private void connectToSession(MediaSession.Token token) {
    MediaController mediaController = new MediaController(FullScreenPlayerActivity.this, token);
    if (mediaController.getMetadata() == null) {
        finish();
        return;
    }
    setMediaController(mediaController);
    mediaController.registerCallback(mCallback);
    PlaybackState state = mediaController.getPlaybackState();
    updatePlaybackState(state);
    MediaMetadata metadata = mediaController.getMetadata();
    if (metadata != null) {
        updateMediaDescription(metadata.getDescription());
        updateDuration(metadata);
    }
    updateProgress();
    if (state != null && (state.getState() == PlaybackState.STATE_PLAYING ||
            state.getState() == PlaybackState.STATE_BUFFERING)) {
        scheduleSeekbarUpdate();
    }
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:22,代码来源:FullScreenPlayerActivity.java

示例4: checkForUserVisibleErrors

import android.media.session.MediaController; //导入方法依赖的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:
        MediaController controller = getActivity().getMediaController();
        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:ErNaveen,项目名称:UniversalMusicPlayer,代码行数:27,代码来源:MediaBrowserFragment.java

示例5: getView

import android.media.session.MediaController; //导入方法依赖的package包/类
@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MediaBrowser.MediaItem item = getItem(position);
    int state = MediaItemViewHolder.STATE_NONE;
    if (item.isPlayable()) {
        state = MediaItemViewHolder.STATE_PLAYABLE;
        MediaController controller = ((Activity) getContext()).getMediaController();
        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() ==
                        PlaybackState.STATE_PLAYING) {
                    state = MediaItemViewHolder.STATE_PLAYING;
                } else if (controller.getPlaybackState().getState() !=
                        PlaybackState.STATE_ERROR) {
                    state = MediaItemViewHolder.STATE_PAUSED;
                }
            }
        }
    }
    return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent,
        item.getDescription(), state);
}
 
开发者ID:ErNaveen,项目名称:UniversalMusicPlayer,代码行数:26,代码来源:MediaBrowserFragment.java

示例6: run

import android.media.session.MediaController; //导入方法依赖的package包/类
@Override
public void run(@NonNull MediaController2 mc) {
    final MediaController2Lollipop mcl = (MediaController2Lollipop) mc;
    final MediaController source = mcl.mMediaController;

    if (source != null && mToken.equals(source.getSessionToken())) {
        long now = SystemClock.elapsedRealtime();

        final MediaMetadata metadata = source.getMetadata();
        final PlaybackState playbackState = source.getPlaybackState();

        long delta = SystemClock.elapsedRealtime() - now;
        Log.i(TAG, "Got the new metadata & playback state in " + delta + " millis. "
                + "The media controller is " + source.getPackageName());

        mHandler.post(new Runnable() {
            @Override
            public void run() {
                mcl.updateMetadata(metadata);
                mcl.updatePlaybackState(playbackState);
            }
        });
    }
}
 
开发者ID:AChep,项目名称:AcDisplay,代码行数:25,代码来源:MediaController2Lollipop.java

示例7: onConnected

import android.media.session.MediaController; //导入方法依赖的package包/类
@Override
public void onConnected() {
    LogHelper.d(TAG, "onConnected");
    MediaController mediaController = new MediaController(
            TvPlaybackActivity.this, mMediaBrowser.getSessionToken());
    setMediaController(mediaController);
    mediaController.registerCallback(mMediaControllerCallback);

    MediaMetadata metadata = mediaController.getMetadata();
    if (metadata != null) {
        mPlaybackFragment.updateMetadata(metadata);
        mPlaybackFragment.updatePlaybackState(mediaController.getPlaybackState());
    }
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:15,代码来源:TvPlaybackActivity.java

示例8: checkForUserVisibleErrors

import android.media.session.MediaController; //导入方法依赖的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:
        MediaController controller = getActivity().getMediaController();
        if (controller != null
            && controller.getMetadata() != null
            && controller.getPlaybackState() != 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:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:28,代码来源:MediaBrowserFragment.java


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