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


Java PlaybackState類代碼示例

本文整理匯總了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);
}
 
開發者ID:googlecodelabs,項目名稱:musicplayer-devices,代碼行數:24,代碼來源:MusicPlayerActivity.java

示例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;
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:17,代碼來源:PlaybackOverlayFragment.java

示例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.
    }
}
 
開發者ID:nejtv,項目名稱:androidtv-sample,代碼行數:21,代碼來源:PlaybackOverlayFragment.java

示例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);
                }
            }
        }
    }
 
開發者ID:bertrandmartel,項目名稱:webradio-tv-app,代碼行數:17,代碼來源:RadioSingleton.java

示例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());
    }
 
開發者ID:bertrandmartel,項目名稱:webradio-tv-app,代碼行數:26,代碼來源:RadioSingleton.java

示例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);
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:20,代碼來源:DvrPlayer.java

示例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);
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:23,代碼來源:DvrPlayer.java

示例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);
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:22,代碼來源:DvrPlayer.java

示例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);
    }
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:22,代碼來源:DvrPlayer.java

示例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);
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:17,代碼來源:DvrPlayer.java

示例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));
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:18,代碼來源:DvrPlaybackMediaSessionHelper.java

示例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));
}
 
開發者ID:trevd,項目名稱:android_packages_apps_tv,代碼行數:17,代碼來源:DvrPlaybackMediaSessionHelper.java

示例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());
    }
}
 
開發者ID:PTCE,項目名稱:popcorn-android,代碼行數:18,代碼來源:PTVVideoPlayerFragment.java

示例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();
        }
    }
}
 
開發者ID:PTCE,項目名稱:popcorn-android,代碼行數:23,代碼來源:PTVVideoPlayerFragment.java

示例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);
  }
}
 
開發者ID:peterjosling,項目名稱:scroball,代碼行數:25,代碼來源:PlayerState.java


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