当前位置: 首页>>代码示例>>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;未经允许,请勿转载。