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


Java PlaybackState.getState方法代码示例

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


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

示例1: setPlaybackState

import android.media.session.PlaybackState; //导入方法依赖的package包/类
public void setPlaybackState(PlaybackState playbackState) {
  if (playbackItem == null) {
    return;
  }

  playbackItem.updateAmountPlayed();

  int state = playbackState.getState();
  boolean isPlaying = state == PlaybackState.STATE_PLAYING;

  if (isPlaying) {
    Log.d(TAG, "Track playing");
    postEvent(playbackItem.getTrack());
    playbackItem.startPlaying();
    notificationManager.updateNowPlaying(playbackItem.getTrack());
    scheduleSubmission();
  } else {
    Log.d(TAG, String.format("Track paused (state %d)", state));
    postEvent(Track.empty());
    playbackItem.stopPlaying();
    notificationManager.removeNowPlaying();
    scrobbler.submit(playbackItem);
  }
}
 
开发者ID:peterjosling,项目名称:scroball,代码行数:25,代码来源:PlayerState.java

示例2: updatePlaybackState

import android.media.session.PlaybackState; //导入方法依赖的package包/类
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,代码行数:23,代码来源:TvPlaybackFragment.java

示例3: getView

import android.media.session.PlaybackState; //导入方法依赖的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

示例4: onClick

import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onClick(View v) {
    PlaybackState stateObj = getActivity().getMediaController().getPlaybackState();
    final int state = stateObj == null ?
            PlaybackState.STATE_NONE : stateObj.getState();
    LogHelper.d(TAG, "Button pressed, in state " + state);
    switch (v.getId()) {
        case R.id.play_pause:
            LogHelper.d(TAG, "Play button pressed, in state " + state);
            if (state == PlaybackState.STATE_PAUSED ||
                    state == PlaybackState.STATE_STOPPED ||
                    state == PlaybackState.STATE_NONE) {
                playMedia();
            } else if (state == PlaybackState.STATE_PLAYING ||
                    state == PlaybackState.STATE_BUFFERING ||
                    state == PlaybackState.STATE_CONNECTING) {
                pauseMedia();
            }
            break;
    }
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:22,代码来源:PlaybackControlsFragment.java

示例5: connectToSession

import android.media.session.PlaybackState; //导入方法依赖的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

示例6: getPlaybackState

import android.media.session.PlaybackState; //导入方法依赖的package包/类
private int getPlaybackState() {
	Activity activity = getActivity();

	if (activity != null) {
		PlaybackState state = activity.getMediaController().getPlaybackState();
		if (state != null) {
			return state.getState();
		} else {
			return PlaybackState.STATE_NONE;
		}
	}
	return PlaybackState.STATE_NONE;
}
 
开发者ID:NiciDieNase,项目名称:chaosflix-leanback,代码行数:14,代码来源:OverlayFragment.java

示例7: onPlaybackStateChanged

import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
	if (state.getState() != PlaybackState.STATE_NONE) {
		updateProgress();
	}
	onStateChanged();
}
 
开发者ID:NiciDieNase,项目名称:chaosflix-leanback,代码行数:8,代码来源:PlaybackHelper.java

示例8: onPlaybackStateChanged

import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
    // Update your UI to reflect the new state. Do not change media playback here.
    if (DEBUG) Log.d(TAG, "Playback state changed: " + state.getState());

    int nextState = state.getState();
    if (nextState != PlaybackState.STATE_NONE) {
        updateProgress();
    }
    onStateChanged();
}
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:12,代码来源:PlaybackControlHelper.java

示例9: getPlaybackState

import android.media.session.PlaybackState; //导入方法依赖的package包/类
private int getPlaybackState() {
    Activity activity = getActivity();

    if (activity != null) {
        PlaybackState state = activity.getMediaController().getPlaybackState();
        if (state != null) {
            return state.getState();
        } else {
            return PlaybackState.STATE_NONE;
        }
    }
    return PlaybackState.STATE_NONE;
}
 
开发者ID:nejtv,项目名称:androidtv-sample,代码行数:14,代码来源:PlaybackOverlayFragment.java

示例10: onPlaybackStateChanged

import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(PlaybackState state) {
    super.onPlaybackStateChanged(state);
    StandardWidget.currentlyPlaying = state.getState() == PlaybackState.STATE_PLAYING;
    updateMetadata();
    sendBroadcast(new Intent(StandardWidget.WIDGET_UPDATE));
}
 
开发者ID:jathak,项目名称:musicwidget,代码行数:8,代码来源:NotificationListener.java

示例11: onPlaybackStateChanged

import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
    super.onPlaybackStateChanged(state);
    byte[] data = new byte[1];
    data[0] = (byte)(state.getState() == PlaybackState.STATE_PLAYING ?  1 : 0);
    mDevice.write(mediaPlayingCharac, data, MediaService.this);
}
 
开发者ID:AsteroidOS,项目名称:AsteroidOSSync,代码行数:8,代码来源:MediaService.java

示例12: isMediaPlaying

import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public boolean isMediaPlaying() {
    PlaybackState playbackState = mMediaController.getPlaybackState();
    if (playbackState == null) {
        return false;
    }
    int state = playbackState.getState();
    return state != PlaybackState.STATE_NONE && state != PlaybackState.STATE_CONNECTING
            && state != PlaybackState.STATE_PAUSED;
}
 
开发者ID:trevd,项目名称:android_packages_apps_tv,代码行数:11,代码来源:DvrPlaybackControlHelper.java

示例13: onPlaybackStateChanged

import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
    if (state.getState() == PlaybackState.STATE_PLAYING
            && mCurrentPlaybackState == PlaybackState.STATE_PLAYING) {
        startProgressAutomation();
        setFadingEnabled(true);
    } else if (state.getState() == PlaybackState.STATE_PLAYING) {
        mCurrentPlaybackState = PlaybackState.STATE_PLAYING;
        startProgressAutomation();
        setFadingEnabled(true);
        mPlayPauseAction.setIndex(PlayPauseAction.PAUSE);
        mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlayPauseAction.PAUSE));
        notifyChanged(mPlayPauseAction);
    } else if (state.getState() == PlaybackState.STATE_PAUSED
            && mCurrentPlaybackState != PlaybackState.STATE_PAUSED) {
        mCurrentPlaybackState = PlaybackState.STATE_PAUSED;
        stopProgressAutomation();
        setFadingEnabled(false);
        mPlayPauseAction.setIndex(PlayPauseAction.PLAY);
        mPlayPauseAction.setIcon(mPlayPauseAction.getDrawable(PlayPauseAction.PLAY));
        notifyChanged(mPlayPauseAction);
    }

    int currentTime;

    if (state.getState() == PlaybackState.STATE_PAUSED
            || state.getState() == PlaybackState.STATE_PLAYING) {
        currentTime = mPlaybackControlsRow.getCurrentTime();
    } else {
        currentTime = (int) state.getPosition();
    }
    mPlaybackControlsRow.setCurrentTime(currentTime);
    mPlaybackControlsRow.setBufferedProgress(currentTime + SIMULATED_BUFFERED_TIME);
}
 
开发者ID:hitherejoe,项目名称:PictureInPicturePlayground,代码行数:35,代码来源:PlaybackOverlayFragment.java

示例14: onPlaybackStateChanged

import android.media.session.PlaybackState; //导入方法依赖的package包/类
@Override
public void onPlaybackStateChanged(@NonNull PlaybackState state) {
    LogHelper.d(TAG, "onPlaybackStateChanged, state=", state);
    if (mPlaybackFragment == null || state.getState() == PlaybackState.STATE_BUFFERING) {
        return;
    }
    mPlaybackFragment.updatePlaybackState(state);
}
 
开发者ID:mrinalgit-dev,项目名称:MrinalMusicPlayer,代码行数:9,代码来源:TvPlaybackActivity.java

示例15: onPlaybackStateChanged

import android.media.session.PlaybackState; //导入方法依赖的package包/类
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,代码行数:40,代码来源:PlaybackControlsFragment.java


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