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