Java 类android.media.session.PlaybackState 实例源码
项目:musicplayer-devices
文件:MusicPlayerActivity.java
@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);
}
项目:androidtv-sample
文件:PlaybackOverlayFragment.java
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;
}
项目:androidtv-sample
文件:PlaybackOverlayFragment.java
@Override
public void onSkipToPrevious() {
// Update the media to skip to the previous video.
setPlaybackState(PlaybackState.STATE_SKIPPING_TO_PREVIOUS);
Bundle bundle = new Bundle();
bundle.putBoolean(AUTO_PLAY, true);
int prevIndex = --mQueueIndex;
if (prevIndex >= 0) {
MediaSessionCompat.QueueItem item = mQueue.get(prevIndex);
String mediaId = item.getDescription().getMediaId();
getActivity().getMediaController()
.getTransportControls()
.playFromMediaId(mediaId, bundle);
} else {
getActivity().onBackPressed(); // Return to details presenter.
}
}
项目:chilly
文件:PlaybackOverlayFragment.java
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;
}
项目:chilly
文件:PlaybackOverlayFragment.java
@Override
public void onSkipToPrevious() {
// Update the media to skip to the previous video.
setPlaybackState(PlaybackState.STATE_SKIPPING_TO_PREVIOUS);
Bundle bundle = new Bundle();
bundle.putBoolean(AUTO_PLAY, true);
int prevIndex = --mQueueIndex;
if (prevIndex >= 0) {
MediaSessionCompat.QueueItem item = mQueue.get(prevIndex);
String mediaId = item.getDescription().getMediaId();
getActivity().getMediaController()
.getTransportControls()
.playFromMediaId(mediaId, bundle);
} else {
getActivity().onBackPressed(); // Return to details presenter.
}
}
项目:webradio-tv-app
文件:RadioSingleton.java
public void playPause(String streamUrl) {
if (mediaPlayer.isPlaying()) {
mediaPlayer.pause();
updateMediaSession(PlaybackState.STATE_PAUSED);
} else {
if (!initPlayer) {
new Player().execute(streamUrl);
} else {
if (!mediaPlayer.isPlaying()) {
mediaPlayer.start();
updateMediaSession(PlaybackState.STATE_PLAYING);
}
}
}
}
项目:webradio-tv-app
文件:RadioSingleton.java
private void updateMediaSession(int state) {
MediaMetadata.Builder mediaBuilder = null;
Bitmap bitmap = null;
try {
URL url = new URL(mRadioIcon);
bitmap = BitmapFactory.decodeStream(url.openConnection().getInputStream());
} catch (IOException e) {
Log.e(TAG, "BitmapFactory.decodeStream", e);
}
mediaBuilder = new MediaMetadata.Builder();
mediaBuilder.putString(MediaMetadata.METADATA_KEY_TITLE, mTitle);
if (bitmap != null) {
mediaBuilder.putBitmap(MediaMetadata.METADATA_KEY_ART, bitmap);
}
mMediaSession.setMetadata(mediaBuilder.build());
PlaybackState.Builder stateBuilder = new PlaybackState.Builder();
stateBuilder.setState(state, 0, 1.0f);
mMediaSession.setPlaybackState(stateBuilder.build());
}
项目:android_packages_apps_tv
文件:DvrPlayer.java
/**
* Resumes playback.
*/
public void play() throws IllegalStateException {
if (DEBUG) Log.d(TAG, "play()");
if (!isPlaybackPrepared()) {
throw new IllegalStateException("Recorded program not set or video not ready yet");
}
switch (mPlaybackState) {
case PlaybackState.STATE_FAST_FORWARDING:
case PlaybackState.STATE_REWINDING:
setPlaybackSpeed(1);
break;
default:
mTvView.timeShiftResume();
}
mPlaybackState = PlaybackState.STATE_PLAYING;
mCallback.onPlaybackStateChanged(mPlaybackState, 1);
}
项目:android_packages_apps_tv
文件:DvrPlayer.java
/**
* 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);
}
项目:android_packages_apps_tv
文件:DvrPlayer.java
/**
* Rewinds playback with the given speed. If the given speed is larger than
* {@value #MAX_REWIND_SPEED}, uses {@value #MAX_REWIND_SPEED}.
*/
public void rewind(int speed) throws IllegalStateException {
if (DEBUG) Log.d(TAG, "rewind()");
if (!isPlaybackPrepared()) {
throw new IllegalStateException("Recorded program not set or playback not started yet");
}
if (speed <= 0) {
throw new IllegalArgumentException("Speed cannot be negative or 0");
}
if (mTimeShiftCurrentPositionMs <= REWIND_POSITION_MARGIN_MS) {
return;
}
speed = Math.min(speed, MAX_REWIND_SPEED);
if (DEBUG) Log.d(TAG, "Let's play with speed: " + speed);
setPlaybackSpeed(-speed);
mPlaybackState = PlaybackState.STATE_REWINDING;
mCallback.onPlaybackStateChanged(mPlaybackState, speed);
}
项目:android_packages_apps_tv
文件:DvrPlayer.java
/**
* 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);
}
}
项目:android_packages_apps_tv
文件:DvrPlayer.java
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);
}
项目:android_packages_apps_tv
文件:DvrPlaybackMediaSessionHelper.java
@Override
public void onFastForward() {
if (!mDvrPlayer.isPlaybackPrepared()) {
return;
}
if (mDvrPlayer.getPlaybackState() == PlaybackState.STATE_FAST_FORWARDING) {
if (mSpeedLevel < TimeShiftUtils.MAX_SPEED_LEVEL) {
mSpeedLevel++;
} else {
return;
}
} else {
mSpeedLevel = 0;
}
mDvrPlayer.fastForward(
TimeShiftUtils.getPlaybackSpeed(mSpeedLevel, mProgramDurationMs));
}
项目:android_packages_apps_tv
文件:DvrPlaybackMediaSessionHelper.java
@Override
public void onRewind() {
if (!mDvrPlayer.isPlaybackPrepared()) {
return;
}
if (mDvrPlayer.getPlaybackState() == PlaybackState.STATE_REWINDING) {
if (mSpeedLevel < TimeShiftUtils.MAX_SPEED_LEVEL) {
mSpeedLevel++;
} else {
return;
}
} else {
mSpeedLevel = 0;
}
mDvrPlayer.rewind(TimeShiftUtils.getPlaybackSpeed(mSpeedLevel, mProgramDurationMs));
}
项目:popcorn-android
文件:PTVVideoPlayerFragment.java
@Override
protected void updatePlayPauseState() {
EventBus.getDefault().post(new ToggleSubtitleEvent(mIsSubtitleEnabled));
EventBus.getDefault().post(new UpdatePlaybackStateEvent(isPlaying()));
if (mMediaSession != null) {
PlaybackState.Builder builder = new PlaybackState.Builder();
builder.setActions(isPlaying()
? PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PAUSE
: PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PLAY);
builder.setState(
isPlaying() ? PlaybackState.STATE_PLAYING : PlaybackState.STATE_PAUSED,
getCurrentTime(),
1.0f);
mMediaSession.setPlaybackState(builder.build());
}
}
项目:popcorn-android
文件:PTVVideoPlayerFragment.java
@Override
protected void onProgressChanged(long currentTime, long duration) {
EventBus.getDefault().post(new PlaybackProgressChangedEvent(currentTime, duration));
if (mMediaSession != null && duration > 0) {
PlaybackState.Builder builder = new PlaybackState.Builder();
builder.setActions(isPlaying()
? PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PAUSE
: PlaybackState.ACTION_PLAY_PAUSE | PlaybackState.ACTION_PLAY);
builder.setState(
isPlaying()
? PlaybackState.STATE_PLAYING
: PlaybackState.STATE_PAUSED,
getCurrentTime(),
1.0f);
mMediaSession.setPlaybackState(builder.build());
if (!mMediaSessionMetadataApplied) {
setupMediaMetadata();
}
}
}
项目:scroball
文件:PlayerState.java
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);
}
}
项目:AndroidAutoTourGuide
文件:MuziKarMusicService.java
@Override
public void onCreate() {
Log.d (TAG, "onCreate() " + this) ;
super.onCreate();
// Start a new MediaSession
mediaSession = new MediaSession(this, "MuziKarMusicService");
mediaSession.setCallback(mediaSessionCallback);
mediaSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
setSessionToken(mediaSession.getSessionToken());
playbackControlEventBroadcastReceiver = new PlaybackControlEventBroadcastReceiver(this);
audioPlaybackHelper = new AudioPlaybackHelper(getApplicationContext(), new AudioPlaybackHelper.PlayStateChangeCallback() {
@Override
public void onPlaybackStatusChanged(PlaybackState state) {
mediaSession.setPlaybackState(state);
playbackControlEventBroadcastReceiver.update(audioPlaybackHelper.getCurrentMedia(), state, getSessionToken());
}
});
carConnectStatusBroadcastReceiver = new CarConnectStatusBroadcastReceiver( this ) ;
}
项目:android-music-player
文件:MusicPlayerActivity.java
@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);
}
项目:MrinalMusicPlayer
文件:MusicService.java
private void setCustomAction(PlaybackState.Builder stateBuilder) {
MediaMetadata currentMusic = getCurrentPlayingMusic();
if (currentMusic != null) {
// Set appropriate "Favorite" icon on Custom action:
String musicId = currentMusic.getString(MediaMetadata.METADATA_KEY_MEDIA_ID);
int favoriteIcon = R.drawable.ic_star_off;
if (mMusicProvider.isFavorite(musicId)) {
favoriteIcon = R.drawable.ic_star_on;
}
LogHelper.d(TAG, "updatePlaybackState, setting Favorite custom action of music ",
musicId, " current favorite=", mMusicProvider.isFavorite(musicId));
Bundle customActionExtras = new Bundle();
WearHelper.setShowCustomActionOnWear(customActionExtras, true);
stateBuilder.addCustomAction(new PlaybackState.CustomAction.Builder(
CUSTOM_ACTION_THUMBS_UP, getString(R.string.favorite), favoriteIcon)
.setExtras(customActionExtras)
.build());
}
}
项目:android-music-player
文件:MusicService.java
@Override
public void onCreate() {
super.onCreate();
// Start a new MediaSession
mSession = new MediaSession(this, "MusicService");
mSession.setCallback(mCallback);
mSession.setFlags(MediaSession.FLAG_HANDLES_MEDIA_BUTTONS |
MediaSession.FLAG_HANDLES_TRANSPORT_CONTROLS);
setSessionToken(mSession.getSessionToken());
final MediaNotificationManager mediaNotificationManager = new MediaNotificationManager(this);
mPlayback = new PlaybackManager(this, new PlaybackManager.Callback() {
@Override
public void onPlaybackStatusChanged(PlaybackState state) {
mSession.setPlaybackState(state);
mediaNotificationManager.update(mPlayback.getCurrentMedia(), state, getSessionToken());
}
});
}
项目:MrinalMusicPlayer
文件:CastPlayback.java
@Override
public void play(QueueItem item) {
try {
loadMedia(item.getDescription().getMediaId(), true);
mState = PlaybackState.STATE_BUFFERING;
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
} catch (TransientNetworkDisconnectionException | NoConnectionException
| JSONException | IllegalArgumentException e) {
LogHelper.e(TAG, "Exception loading media ", e, null);
if (mCallback != null) {
mCallback.onError(e.getMessage());
}
}
}
项目:MrinalMusicPlayer
文件:LocalPlayback.java
@Override
public void stop(boolean notifyListeners) {
mState = PlaybackState.STATE_STOPPED;
if (notifyListeners && mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
mCurrentPosition = getCurrentStreamPosition();
// Give up Audio focus
giveUpAudioFocus();
unregisterAudioNoisyReceiver();
// Relax all resources
relaxResources(true);
if (mWifiLock.isHeld()) {
mWifiLock.release();
}
}
项目:MrinalMusicPlayer
文件:LocalPlayback.java
@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();
}
项目:MrinalMusicPlayer
文件:LocalPlayback.java
@Override
public void seekTo(int position) {
LogHelper.d(TAG, "seekTo called with ", position);
if (mMediaPlayer == null) {
// If we do not have a current media player, simply update the current position
mCurrentPosition = position;
} else {
if (mMediaPlayer.isPlaying()) {
mState = PlaybackState.STATE_BUFFERING;
}
mMediaPlayer.seekTo(position);
if (mCallback != null) {
mCallback.onPlaybackStatusChanged(mState);
}
}
}
项目:MrinalMusicPlayer
文件:TvPlaybackFragment.java
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);
}
项目:MrinalMusicPlayer
文件:MediaBrowserFragment.java
@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);
}
项目:MrinalMusicPlayer
文件:PlaybackControlsFragment.java
@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;
}
}
项目:MrinalMusicPlayer
文件:BaseActivity.java
/**
* 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;
}
}
项目:MrinalMusicPlayer
文件:FullScreenPlayerActivity.java
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();
}
}
项目:MrinalMusicPlayer
文件:FullScreenPlayerActivity.java
private void updateProgress() {
if (mLastPlaybackState == null) {
return;
}
long currentPosition = mLastPlaybackState.getPosition();
if (mLastPlaybackState.getState() != PlaybackState.STATE_PAUSED) {
// Calculate the elapsed time between the last position update and now and unless
// paused, we can assume (delta * speed) + current position is approximately the
// latest position. This ensure that we do not repeatedly call the getPlaybackState()
// on MediaController.
long timeDelta = SystemClock.elapsedRealtime() -
mLastPlaybackState.getLastPositionUpdateTime();
currentPosition += (int) timeDelta * mLastPlaybackState.getPlaybackSpeed();
}
mSeekbar.setProgress((int) currentPosition);
}
项目:MrinalMusicPlayer
文件:MediaNotificationManager.java
private void addPlayPauseAction(Notification.Builder builder) {
LogHelper.d(TAG, "updatePlayPauseAction");
String label;
int icon;
PendingIntent intent;
if (mPlaybackState.getState() == PlaybackState.STATE_PLAYING) {
label = mService.getString(R.string.label_pause);
icon = R.drawable.uamp_ic_pause_white_24dp;
intent = mPauseIntent;
} else {
label = mService.getString(R.string.label_play);
icon = R.drawable.uamp_ic_play_arrow_white_24dp;
intent = mPlayIntent;
}
builder.addAction(new Notification.Action(icon, label, intent));
}
项目:MrinalMusicPlayer
文件:MediaNotificationManager.java
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);
}
项目:youtubetv
文件:WebviewUtils.java
public static void updateMediaSession(boolean updateMetadata,
MediaMetadata.Builder mediaBuilder,
final MediaSession mediaSession,
final int playbackState,
final long position,
final float speed) {
if (mediaSession.isActive()) {
if (updateMetadata) {
mediaSession.setMetadata(mediaBuilder.build());
}
PlaybackState.Builder stateBuilder = new PlaybackState.Builder();
stateBuilder.setState(playbackState,
position,
speed);
mediaSession.setPlaybackState(stateBuilder.build());
}
}
项目:sbs-android-tv
文件:VideoPlayerActivity.java
private void updatePlaybackState(int playbackState) {
PlaybackState.Builder state = new PlaybackState.Builder();
long position = player.getCurrentPosition();
if (ExoPlayer.STATE_PREPARING == playbackState) {
state.setState(PlaybackState.STATE_CONNECTING, position, 1.0f);
} else if (ExoPlayer.STATE_BUFFERING == playbackState) {
state.setState(PlaybackState.STATE_BUFFERING, position, 1.0f);
} else {
if (player.getPlayerControl().isPlaying()) {
state.setState(PlaybackState.STATE_PLAYING, position, 1.0f);
} else {
state.setState(PlaybackState.STATE_PAUSED, position, 1.0f);
}
}
mediaSession.setPlaybackState(state.build());
}
项目:android-music-player
文件:MusicPlayerActivity.java
@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);
}
项目:android-PictureInPicture
文件:MediaSessionPlaybackActivityTest.java
private void assertMediaStateIs(@PlaybackStateCompat.State int expectedState) {
PlaybackState state = rule.getActivity().getMediaController().getPlaybackState();
assertNotNull(state);
assertThat(
"MediaSession is not in the correct state",
state.getState(),
is(equalTo(expectedState)));
}
项目:sflauncher
文件:MediaListener.java
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));
}
项目:sflauncher
文件:MediaListener.java
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;
}
项目:HelloTV
文件:PlaybackOverlayActivity.java
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());
}