本文整理匯總了Java中android.media.session.PlaybackState類的典型用法代碼示例。如果您正苦於以下問題:Java PlaybackState類的具體用法?Java PlaybackState怎麽用?Java PlaybackState使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
PlaybackState類屬於android.media.session包,在下文中一共展示了PlaybackState類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: getView
import android.media.session.PlaybackState; //導入依賴的package包/類
@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);
}
示例2: getAvailableActions
import android.media.session.PlaybackState; //導入依賴的package包/類
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;
}
示例3: onSkipToPrevious
import android.media.session.PlaybackState; //導入依賴的package包/類
@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.
}
}
示例4: playPause
import android.media.session.PlaybackState; //導入依賴的package包/類
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);
}
}
}
}
示例5: updateMediaSession
import android.media.session.PlaybackState; //導入依賴的package包/類
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());
}
示例6: play
import android.media.session.PlaybackState; //導入依賴的package包/類
/**
* 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);
}
示例7: pause
import android.media.session.PlaybackState; //導入依賴的package包/類
/**
* 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);
}
示例8: rewind
import android.media.session.PlaybackState; //導入依賴的package包/類
/**
* 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);
}
示例9: seekTo
import android.media.session.PlaybackState; //導入依賴的package包/類
/**
* 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);
}
}
示例10: resumeToWatchedPositionIfNeeded
import android.media.session.PlaybackState; //導入依賴的package包/類
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);
}
示例11: onFastForward
import android.media.session.PlaybackState; //導入依賴的package包/類
@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));
}
示例12: onRewind
import android.media.session.PlaybackState; //導入依賴的package包/類
@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));
}
示例13: updatePlayPauseState
import android.media.session.PlaybackState; //導入依賴的package包/類
@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());
}
}
示例14: onProgressChanged
import android.media.session.PlaybackState; //導入依賴的package包/類
@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();
}
}
}
示例15: 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);
}
}