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


Java PlaybackState.STATE_PLAYING屬性代碼示例

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


在下文中一共展示了PlaybackState.STATE_PLAYING屬性的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的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: getAvailableActions

private long getAvailableActions(int nextState) {
    long actions = PlaybackState.ACTION_PLAY |
            PlaybackState.ACTION_PLAY_FROM_MEDIA_ID |
            PlaybackState.ACTION_PLAY_FROM_SEARCH |
            PlaybackState.ACTION_SKIP_TO_NEXT |
            PlaybackState.ACTION_SKIP_TO_PREVIOUS |
            PlaybackState.ACTION_FAST_FORWARD |
            PlaybackState.ACTION_REWIND |
            PlaybackState.ACTION_PAUSE;

    if (nextState == PlaybackState.STATE_PLAYING) {
        actions |= PlaybackState.ACTION_PAUSE;
    }

    return actions;
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:16,代碼來源:PlaybackOverlayFragment.java

示例3: updatePlaybackState

protected void updatePlaybackState(PlaybackState state) {
    if (mPlaybackControlsRow == null) {
        // We only update playback state after we get a valid metadata.
        return;
    }
    mLastPosition = state.getPosition();
    mLastPositionUpdateTime = state.getLastPositionUpdateTime();
    switch (state.getState()) {
        case PlaybackState.STATE_PLAYING:
            startProgressAutomation();
            mPlayPauseAction.setIndex(PlayPauseAction.PAUSE);
            break;
        case PlaybackState.STATE_PAUSED:
            stopProgressAutomation();
            mPlayPauseAction.setIndex(PlayPauseAction.PLAY);
            break;
    }

    updatePlayListRow(getActivity().getMediaController().getQueue());
    mRowsAdapter.notifyArrayItemRangeChanged(
            mRowsAdapter.indexOf(mPlaybackControlsRow), 1);
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:22,代碼來源:TvPlaybackFragment.java

示例4: pause

/**
 * Pauses playback.
 */
public void pause() throws IllegalStateException {
    if (DEBUG) Log.d(TAG, "pause()");
    if (!isPlaybackPrepared()) {
        throw new IllegalStateException("Recorded program not set or playback not started yet");
    }
    switch (mPlaybackState) {
        case PlaybackState.STATE_FAST_FORWARDING:
        case PlaybackState.STATE_REWINDING:
            setPlaybackSpeed(1);
            // falls through
        case PlaybackState.STATE_PLAYING:
            mTvView.timeShiftPause();
            mPlaybackState = PlaybackState.STATE_PAUSED;
            break;
        default:
            break;
    }
    mCallback.onPlaybackStateChanged(mPlaybackState, 1);
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:22,代碼來源:DvrPlayer.java

示例5: seekTo

/**
 * Seeks playback to the specified position.
 */
public void seekTo(long positionMs) throws IllegalStateException {
    if (DEBUG) Log.d(TAG, "seekTo()");
    if (!isPlaybackPrepared()) {
        throw new IllegalStateException("Recorded program not set or playback not started yet");
    }
    if (mProgram == null || mPlaybackState == PlaybackState.STATE_NONE) {
        return;
    }
    positionMs = getRealSeekPosition(positionMs, SEEK_POSITION_MARGIN_MS);
    if (DEBUG) Log.d(TAG, "Now: " + getPlaybackPosition() + ", shift to: " + positionMs);
    mTvView.timeShiftSeekTo(positionMs + mStartPositionMs);
    if (mPlaybackState == PlaybackState.STATE_FAST_FORWARDING ||
            mPlaybackState == PlaybackState.STATE_REWINDING) {
        mPlaybackState = PlaybackState.STATE_PLAYING;
        mTvView.timeShiftResume();
        mCallback.onPlaybackStateChanged(mPlaybackState, 1);
    }
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:21,代碼來源:DvrPlayer.java

示例6: resumeToWatchedPositionIfNeeded

private void resumeToWatchedPositionIfNeeded() {
    if (mInitialSeekPositionMs != TvInputManager.TIME_SHIFT_INVALID_TIME) {
        mTvView.timeShiftSeekTo(getRealSeekPosition(mInitialSeekPositionMs,
                SEEK_POSITION_MARGIN_MS) + mStartPositionMs);
        mInitialSeekPositionMs = TvInputManager.TIME_SHIFT_INVALID_TIME;
    }
    if (mPauseOnPrepared) {
        mTvView.timeShiftPause();
        mPlaybackState = PlaybackState.STATE_PAUSED;
        mPauseOnPrepared = false;
    } else {
        mTvView.timeShiftResume();
        mPlaybackState = PlaybackState.STATE_PLAYING;
    }
    mCallback.onPlaybackStateChanged(mPlaybackState, 1);
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:16,代碼來源:DvrPlayer.java

示例7: 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

示例8: pause

@Override
public void pause() {
    if (mState == PlaybackState.STATE_PLAYING) {
        // Pause media player and cancel the 'foreground service' state.
        if (mMediaPlayer != null && mMediaPlayer.isPlaying()) {
            mMediaPlayer.pause();
            mCurrentPosition = mMediaPlayer.getCurrentPosition();
        }
        // while paused, retain the MediaPlayer but give up audio focus
        relaxResources(false);
        giveUpAudioFocus();
    }
    mState = PlaybackState.STATE_PAUSED;
    if (mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }
    unregisterAudioNoisyReceiver();
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:18,代碼來源:LocalPlayback.java

示例9: setNotificationPlaybackState

private void setNotificationPlaybackState(Notification.Builder builder) {
    LogHelper.d(TAG, "updateNotificationPlaybackState. mPlaybackState=" + mPlaybackState);
    if (mPlaybackState == null || !mStarted) {
        LogHelper.d(TAG, "updateNotificationPlaybackState. cancelling notification!");
        mService.stopForeground(true);
        return;
    }
    if (mPlaybackState.getState() == PlaybackState.STATE_PLAYING
            && mPlaybackState.getPosition() >= 0) {
        LogHelper.d(TAG, "updateNotificationPlaybackState. updating playback position to ",
                (System.currentTimeMillis() - mPlaybackState.getPosition()) / 1000, " seconds");
        builder
            .setWhen(System.currentTimeMillis() - mPlaybackState.getPosition())
            .setShowWhen(true)
            .setUsesChronometer(true);
    } else {
        LogHelper.d(TAG, "updateNotificationPlaybackState. hiding playback position");
        builder
            .setWhen(0)
            .setShowWhen(false)
            .setUsesChronometer(false);
    }

    // Make sure that the notification can be dismissed by the user when we are not playing:
    builder.setOngoing(mPlaybackState.getState() == PlaybackState.STATE_PLAYING);
}
 
開發者ID:mrinalgit-dev,項目名稱:MrinalMusicPlayer,代碼行數:26,代碼來源:MediaNotificationManager.java

示例10: updateMetadata

public void updateMetadata(){
    if(mediaController!=null&&mediaController.getPlaybackState()!=null){
        currentlyPlaying = mediaController.getPlaybackState().getState() == PlaybackState.STATE_PLAYING;
    }
    if(meta==null)return;
    currentArt=meta.getBitmap(MediaMetadata.METADATA_KEY_ART);
    if(currentArt==null){
        currentArt = meta.getBitmap(MediaMetadata.METADATA_KEY_ALBUM_ART);
    }
    if(currentArt==null){
        currentArt = meta.getBitmap(MediaMetadata.METADATA_KEY_DISPLAY_ICON);
    }
    currentArtist=meta.getString(MediaMetadata.METADATA_KEY_ARTIST);
    currentSong=meta.getString(MediaMetadata.METADATA_KEY_TITLE);
    if(currentSong==null){
        currentSong=meta.getString(MediaMetadata.METADATA_KEY_DISPLAY_TITLE);
    }
    currentAlbum=meta.getString(MediaMetadata.METADATA_KEY_ALBUM);
    if(currentArtist==null){
        currentArtist = meta.getString(MediaMetadata.METADATA_KEY_ALBUM_ARTIST);
    }
    if(currentArtist==null) {
        currentArtist = meta.getString(MediaMetadata.METADATA_KEY_AUTHOR);
    }
    if(currentArtist==null) {
        currentArtist = meta.getString(MediaMetadata.METADATA_KEY_DISPLAY_SUBTITLE);
    }
    if(currentArtist==null) {
        currentArtist = meta.getString(MediaMetadata.METADATA_KEY_WRITER);
    }
    if(currentArtist==null) {
        currentArtist = meta.getString(MediaMetadata.METADATA_KEY_COMPOSER);
    }
    if(currentArtist==null) currentArtist = "";
    if(currentSong==null) currentSong = "";
    if(currentAlbum==null) currentAlbum = "";
    sendBroadcast(new Intent(MEDIA_UPDATE));
}
 
開發者ID:jathak,項目名稱:sflauncher,代碼行數:38,代碼來源:MediaListener.java

示例11: pickController

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

示例12: updatePlaybackState

private void updatePlaybackState(int position) {
    PlaybackState.Builder stateBuilder = new PlaybackState.Builder()
            .setActions(getAvailableActions());
    int state = PlaybackState.STATE_PLAYING;
    if (mPlaybackState == LeanbackPlaybackState.PAUSED) {
        state = PlaybackState.STATE_PAUSED;
    }
    stateBuilder.setState(state, position, 1.0f);
    mSession.setPlaybackState(stateBuilder.build());
}
 
開發者ID:bassaer,項目名稱:HelloTV,代碼行數:10,代碼來源:PlaybackOverlayActivity.java

示例13: 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

示例14: getAvailableActions

private long getAvailableActions(int nextState) {
	long actions = PlaybackState.ACTION_PLAY |
			PlaybackState.ACTION_SKIP_TO_NEXT |
			PlaybackState.ACTION_SKIP_TO_PREVIOUS |
			PlaybackState.ACTION_FAST_FORWARD |
			PlaybackState.ACTION_REWIND |
			PlaybackState.ACTION_PAUSE;

	if (nextState == PlaybackState.STATE_PLAYING) {
		actions |= PlaybackState.ACTION_PAUSE;
	}

	return actions;
}
 
開發者ID:NiciDieNase,項目名稱:chaosflix-leanback,代碼行數:14,代碼來源:OverlayFragment.java

示例15: isMediaPlaying

@Override
public boolean isMediaPlaying() {
    if (mMediaController.getPlaybackState() == null) {
        return false;
    }
    int state = mMediaController.getPlaybackState().getState();
    return (state == PlaybackState.STATE_BUFFERING
            || state == PlaybackState.STATE_CONNECTING
            || state == PlaybackState.STATE_PLAYING
            || state == PlaybackState.STATE_FAST_FORWARDING
            || state == PlaybackState.STATE_REWINDING
            || state == PlaybackState.STATE_SKIPPING_TO_PREVIOUS
            || state == PlaybackState.STATE_SKIPPING_TO_NEXT);
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:14,代碼來源:PlaybackControlHelper.java


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