當前位置: 首頁>>代碼示例>>Java>>正文


Java PlaybackState.STATE_ERROR屬性代碼示例

本文整理匯總了Java中android.media.session.PlaybackState.STATE_ERROR屬性的典型用法代碼示例。如果您正苦於以下問題:Java PlaybackState.STATE_ERROR屬性的具體用法?Java PlaybackState.STATE_ERROR怎麽用?Java PlaybackState.STATE_ERROR使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在android.media.session.PlaybackState的用法示例。


在下文中一共展示了PlaybackState.STATE_ERROR屬性的10個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: getView

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MediaBrowserCompat.MediaItem item = getItem(position);
    int itemState = MediaItemViewHolder.STATE_NONE;
    if (item.isPlayable()) {
        String itemMediaId = item.getDescription().getMediaId();
        int playbackState = PlaybackStateCompat.STATE_NONE;
        if (mCurrentState != null) {
            playbackState = mCurrentState.getState();
        }
        if (mCurrentMetadata != null
                && itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) {
            if (playbackState == PlaybackState.STATE_PLAYING
                    || playbackState == PlaybackState.STATE_BUFFERING) {
                itemState = MediaItemViewHolder.STATE_PLAYING;
            } else if (playbackState != PlaybackState.STATE_ERROR) {
                itemState = MediaItemViewHolder.STATE_PAUSED;
            }
        }
    }
    return MediaItemViewHolder.setupView(
            (Activity) getContext(), convertView, parent, item.getDescription(), itemState);
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:23,代碼來源:MusicPlayerActivity.java

示例2: getView

@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,代碼行數:26,代碼來源:MediaBrowserFragment.java

示例3: shouldShowControls

/**
 * 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,代碼行數:22,代碼來源:BaseActivity.java

示例4: getView

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    MediaBrowser.MediaItem item = getItem(position);
    int itemState = MediaItemViewHolder.STATE_NONE;
    if (item.isPlayable()) {
        String itemMediaId = item.getDescription().getMediaId();
        int playbackState = PlaybackState.STATE_NONE;
        if (mCurrentState != null) {
            playbackState = mCurrentState.getState();
        }
        if (mCurrentMetadata != null &&
                itemMediaId.equals(mCurrentMetadata.getDescription().getMediaId())) {
            if (playbackState == PlaybackState.STATE_PLAYING ||
                playbackState == PlaybackState.STATE_BUFFERING) {
                itemState = MediaItemViewHolder.STATE_PLAYING;
            } else if (playbackState != PlaybackState.STATE_ERROR) {
                itemState = MediaItemViewHolder.STATE_PAUSED;
            }
        }
    }
    return MediaItemViewHolder.setupView((Activity) getContext(), convertView, parent,
        item.getDescription(), itemState);
}
 
開發者ID:googlecodelabs,項目名稱:android-music-player,代碼行數:23,代碼來源:MusicPlayerActivity.java

示例5: updatePlaybackState

private void updatePlaybackState(String error) {
    long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN;
    MessageObject playingMessageObject = MediaController.getInstance().getPlayingMessageObject();
    if (playingMessageObject != null) {
        position = playingMessageObject.audioProgressSec * 1000;
    }

    PlaybackState.Builder stateBuilder = new PlaybackState.Builder().setActions(getAvailableActions());
    int state;
    if (playingMessageObject == null) {
        state = PlaybackState.STATE_STOPPED;
    } else {
        if (MediaController.getInstance().isDownloadingCurrentMessage()) {
            state = PlaybackState.STATE_BUFFERING;
        } else {
            state = MediaController.getInstance().isAudioPaused() ? PlaybackState.STATE_PAUSED : PlaybackState.STATE_PLAYING;
        }
    }

    if (error != null) {
        stateBuilder.setErrorMessage(error);
        state = PlaybackState.STATE_ERROR;
    }
    stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());
    if (playingMessageObject != null) {
        stateBuilder.setActiveQueueItemId(MediaController.getInstance().getPlayingMessageObjectNum());
    } else {
        stateBuilder.setActiveQueueItemId(0);
    }

    mediaSession.setPlaybackState(stateBuilder.build());
}
 
開發者ID:MLNO,項目名稱:airgram,代碼行數:32,代碼來源:MusicBrowserService.java

示例6: updatePlaybackState

/**
 * Update the current media player state, optionally showing an error message.
 *
 * @param error if not null, error message to present to the user.
 */
private void updatePlaybackState(String error) {
    LogHelper.d(TAG, "updatePlaybackState, playback state=" + mPlayback.getState());
    long position = PlaybackState.PLAYBACK_POSITION_UNKNOWN;
    if (mPlayback != null && mPlayback.isConnected()) {
        position = mPlayback.getCurrentStreamPosition();
    }

    PlaybackState.Builder stateBuilder = new PlaybackState.Builder()
            .setActions(getAvailableActions());

    setCustomAction(stateBuilder);
    int state = mPlayback.getState();

    // If there is an error message, send it to the playback state:
    if (error != null) {
        // Error states are really only supposed to be used for errors that cause playback to
        // stop unexpectedly and persist until the user takes action to fix it.
        stateBuilder.setErrorMessage(error);
        state = PlaybackState.STATE_ERROR;
    }
    stateBuilder.setState(state, position, 1.0f, SystemClock.elapsedRealtime());

    // Set the activeQueueItemId if the current index is valid.
    if (QueueHelper.isIndexPlayable(mCurrentIndexOnQueue, mPlayingQueue)) {
        MediaSession.QueueItem item = mPlayingQueue.get(mCurrentIndexOnQueue);
        stateBuilder.setActiveQueueItemId(item.getQueueId());
    }

    mSession.setPlaybackState(stateBuilder.build());

    if (state == PlaybackState.STATE_PLAYING || state == PlaybackState.STATE_PAUSED) {
        mMediaNotificationManager.startNotification();
    }
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:39,代碼來源:MusicService.java

示例7: checkForUserVisibleErrors

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,代碼行數:27,代碼來源:MediaBrowserFragment.java

示例8: onPlaybackStateChanged

private void onPlaybackStateChanged(PlaybackState state) {
    LogHelper.d(TAG, "onPlaybackStateChanged ", state);
    if (getActivity() == null) {
        LogHelper.w(TAG, "onPlaybackStateChanged called when getActivity null," +
                "this should not happen if the callback was properly unregistered. Ignoring.");
        return;
    }
    if (state == null) {
        return;
    }
    boolean enablePlay = false;
    switch (state.getState()) {
        case PlaybackState.STATE_PAUSED:
        case PlaybackState.STATE_STOPPED:
            enablePlay = true;
            break;
        case PlaybackState.STATE_ERROR:
            LogHelper.e(TAG, "error playbackstate: ", state.getErrorMessage());
            Toast.makeText(getActivity(), state.getErrorMessage(), Toast.LENGTH_LONG).show();
            break;
    }

    if (enablePlay) {
        mPlayPause.setImageDrawable(
                getActivity().getDrawable(R.drawable.ic_play_arrow_black_36dp));
    } else {
        mPlayPause.setImageDrawable(getActivity().getDrawable(R.drawable.ic_pause_black_36dp));
    }

    MediaController controller = getActivity().getMediaController();
    String extraInfo = null;
    if (controller != null && controller.getExtras() != null) {
        String castName = controller.getExtras().getString(MusicService.EXTRA_CONNECTED_CAST);
        if (castName != null) {
            extraInfo = getResources().getString(R.string.casting_to_device, castName);
        }
    }
    setExtraInfo(extraInfo);
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:39,代碼來源:PlaybackControlsFragment.java

示例9: onPlayerStateChanged

@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
    switch (playbackState){
        case PlaybackState.STATE_PLAYING:
            mProgressWheel.setVisibility(GONE);
            mDanmakuView.resume();
            startUitimer();
            hideSystemUI();
            mPlayBtn.setOnCheckedChangeListener(null);
            mPlayBtn.setChecked(false);
            mPlayBtn.setOnCheckedChangeListener(this);
            break;
        case PlaybackState.STATE_PAUSED:
            mPlayBtn.setOnCheckedChangeListener(null);
            mPlayBtn.setChecked(true);
            mPlayBtn.setOnCheckedChangeListener(this);
            break;
        case PlaybackState.STATE_BUFFERING:
            mProgressWheel.setVisibility(VISIBLE);
            break;
        case PlaybackState.STATE_STOPPED:
            break;
        case PlaybackState.STATE_ERROR:

            break;
        default:
            break;
    }
}
 
開發者ID:ayaseruri,項目名稱:luxunPro,代碼行數:29,代碼來源:VideoView.java

示例10: onPlayerStateChanged

@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
    Timber.e("onPlayerStateChanged: playWhenReady = " + String.valueOf(playWhenReady)
            + " playbackState = " + playbackState);
    switch (playbackState) {
        case PlaybackState.STATE_PLAYING:
            //初始化播放點擊事件並設置總時長
            initPlayVideo();
            Timber.e("播放狀態: 準備 playing");
            break;

        case PlaybackState.STATE_BUFFERING:
            Timber.e("播放狀態: 緩存完成 playing");
            break;

        case PlaybackState.STATE_CONNECTING:
            Timber.e("播放狀態: 連接 CONNECTING");
            break;

        case PlaybackState.STATE_ERROR://錯誤
            Timber.e("播放狀態: 錯誤 STATE_ERROR");
            startPlay.setBackgroundColor(Color.WHITE);
            ToastUtil.showShort("播放錯誤");
            break;

        case PlaybackState.STATE_FAST_FORWARDING:
            Timber.e("播放狀態: 快速傳遞,播放完畢");

            pausePlay();//暫停播放
            break;

        case PlaybackState.STATE_NONE:
            Timber.e("播放狀態: 無 STATE_NONE");
            break;

        case PlaybackState.STATE_PAUSED:
            Timber.e("播放狀態: 暫停 PAUSED");
            break;

        case PlaybackState.STATE_REWINDING:
            Timber.e("播放狀態: 倒回 REWINDING");
            break;

        case PlaybackState.STATE_SKIPPING_TO_NEXT:
            Timber.e("播放狀態: 跳到下一個");
            break;

        case PlaybackState.STATE_SKIPPING_TO_PREVIOUS:
            Timber.e("播放狀態: 跳到上一個");
            break;

        case PlaybackState.STATE_SKIPPING_TO_QUEUE_ITEM:
            Timber.e("播放狀態: 跳到指定的Item");
            break;

        case PlaybackState.STATE_STOPPED:
            Timber.e("播放狀態: 停止的 STATE_STOPPED");
            break;


    }
}
 
開發者ID:ChangWeiBa,項目名稱:AesExoPlayer,代碼行數:62,代碼來源:TestPlayerActivity.java


注:本文中的android.media.session.PlaybackState.STATE_ERROR屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。