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


Java MediaController.getPlaybackState方法代码示例

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


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

示例5: pickController

import android.media.session.MediaController; //导入方法依赖的package包/类
private MediaController pickController(List<MediaController> controllers){
    for(int i=0;i<controllers.size();i++){
        MediaController mc = controllers.get(i);
        if(mc!=null&&mc.getPlaybackState()!=null&&
                mc.getPlaybackState().getState()==PlaybackState.STATE_PLAYING){
            return mc;
        }
    }
    if(controllers.size()>0) return controllers.get(0);
    return null;
}
 
开发者ID:jathak,项目名称:sflauncher,代码行数:12,代码来源:MediaListener.java

示例6: onMetadataChanged

import android.media.session.MediaController; //导入方法依赖的package包/类
@Override
public void onMetadataChanged(MediaMetadata metadata) {
    if (metadata != null) {
        MediaController mediaController = getActivity().getMediaController();
        long activeQueueId;
        if (mediaController.getPlaybackState() == null) {
            activeQueueId = QueueItem.UNKNOWN_ID;
        } else {
            activeQueueId = mediaController.getPlaybackState().getActiveQueueItemId();
        }
        updateNowPlayingList(mediaController.getQueue(), activeQueueId);
        mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
    }
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:15,代码来源:TvBrowseFragment.java

示例7: onQueueChanged

import android.media.session.MediaController; //导入方法依赖的package包/类
@Override
public void onQueueChanged(List<QueueItem> queue) {
    // queue has changed somehow
    MediaController mediaController = getActivity().getMediaController();

    long activeQueueId;
    if (mediaController.getPlaybackState() == null) {
        activeQueueId = QueueItem.UNKNOWN_ID;
    } else {
        activeQueueId = mediaController.getPlaybackState().getActiveQueueItemId();
    }
    updateNowPlayingList(queue, activeQueueId);
    mRowsAdapter.notifyArrayItemRangeChanged(0, mRowsAdapter.size());
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:15,代码来源:TvBrowseFragment.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

示例9: pickBestMediaController

import android.media.session.MediaController; //导入方法依赖的package包/类
@Nullable
private MediaController pickBestMediaController(
        @NonNull List<MediaController> list) {
    int mediaControllerScore = -1;
    MediaController mediaController = null;
    for (MediaController mc : list) {
        if (mc == null) continue;
        int mcScore = 0;

        // Check for the current state
        PlaybackState state = mc.getPlaybackState();
        if (state != null) {
            switch (state.getState()) {
                case PlaybackState.STATE_STOPPED:
                case PlaybackState.STATE_ERROR:
                    break;
                default:
                    mcScore++;
                    break;
            }
        }

        if (mcScore > mediaControllerScore) {
            mediaControllerScore = mcScore;
            mediaController = mc;
        }
    }
    return mediaController;
}
 
开发者ID:AChep,项目名称:AcDisplay,代码行数:30,代码来源:MediaController2Lollipop.java


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