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


Java PlaybackStateCompat类代码示例

本文整理汇总了Java中android.support.v4.media.session.PlaybackStateCompat的典型用法代码示例。如果您正苦于以下问题:Java PlaybackStateCompat类的具体用法?Java PlaybackStateCompat怎么用?Java PlaybackStateCompat使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: initializeMediaSession

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
private void initializeMediaSession() {
    mMediaSession = new MediaSessionCompat(getContext(), TAG);
    mMediaSession.setFlags(
            MediaSessionCompat.FLAG_HANDLES_MEDIA_BUTTONS |
                    MediaSessionCompat.FLAG_HANDLES_TRANSPORT_CONTROLS);

    mMediaSession.setMediaButtonReceiver(null);
    mStateBuilder = new PlaybackStateCompat.Builder()
            .setActions(
                    PlaybackStateCompat.ACTION_PLAY |
                            PlaybackStateCompat.ACTION_PAUSE |
                            PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
                            PlaybackStateCompat.ACTION_PLAY_PAUSE);

    mMediaSession.setPlaybackState(mStateBuilder.build());
    mMediaSession.setCallback(new MySessionCallback());
    mMediaSession.setActive(true);
}
 
开发者ID:twisstosin,项目名称:UdacityBakingAndroid,代码行数:19,代码来源:StepFragment.java

示例2: initialize

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
private static void initialize(File file) throws IOException {
    File tempFile = new File(file.getPath() + ".tmp");
    RandomAccessFile raf = open(tempFile);
    try {
        raf.setLength(PlaybackStateCompat.ACTION_SKIP_TO_QUEUE_ITEM);
        raf.seek(0);
        byte[] headerBuffer = new byte[16];
        writeInts(headerBuffer, 4096, 0, 0, 0);
        raf.write(headerBuffer);
        if (!tempFile.renameTo(file)) {
            throw new IOException("Rename failed!");
        }
    } finally {
        raf.close();
    }
}
 
开发者ID:JackChan1999,项目名称:letv,代码行数:17,代码来源:QueueFile.java

示例3: getAvailableActions

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
private long getAvailableActions() {
    long actions =
            PlaybackStateCompat.ACTION_PLAY_PAUSE |
                    PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID |
                    PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH |
                    PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS |
                    PlaybackStateCompat.ACTION_SKIP_TO_NEXT;
    if (playback.isPlaying()) {
        actions |= PlaybackStateCompat.ACTION_PAUSE;
    } else {
        actions |= PlaybackStateCompat.ACTION_PLAY;
    }
    //
    if(isRepeat){
        actions|=PlaybackStateCompat.ACTION_SET_REPEAT_MODE;
    }
    //
    if(isShuffle){
        actions|=PlaybackStateCompat.ACTION_SET_SHUFFLE_MODE_ENABLED;
    }
    return actions;
}
 
开发者ID:vpaliyX,项目名称:Melophile,代码行数:23,代码来源:PlaybackManager.java

示例4: onSkipToNext

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
@Override
public void onSkipToNext() {
    super.onSkipToNext();
    movieView.startVideo();
    if (indexInPlaylist < PLAYLIST_SIZE) {
        indexInPlaylist++;
        if (indexInPlaylist >= PLAYLIST_SIZE) {
            updatePlaybackState(
                    PlaybackStateCompat.STATE_PLAYING,
                    MEDIA_ACTIONS_PLAY_PAUSE | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS,
                    movieView.getCurrentPosition(),
                    movieView.getVideoResourceId());
        } else {
            updatePlaybackState(
                    PlaybackStateCompat.STATE_PLAYING,
                    MEDIA_ACTIONS_ALL,
                    movieView.getCurrentPosition(),
                    movieView.getVideoResourceId());
        }
    }
}
 
开发者ID:googlesamples,项目名称:android-PictureInPicture,代码行数:22,代码来源:MediaSessionPlaybackActivity.java

示例5: movie_playingOnPip

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
@Test
public void movie_playingOnPip() throws Throwable {
    // The movie should be playing on start
    onView(withId(R.id.movie))
            .check(matches(allOf(isDisplayed(), isPlaying())))
            .perform(showControls());
    // Click on the button to enter Picture-in-Picture mode
    onView(withId(R.id.minimize)).perform(click());
    InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    // The Activity is paused. We cannot use Espresso to test paused activities.
    rule.runOnUiThread(new Runnable() {
        @Override
        public void run() {
            // We are now in Picture-in-Picture mode
            assertTrue(rule.getActivity().isInPictureInPictureMode());
            final MovieView view = rule.getActivity().findViewById(R.id.movie);
            assertNotNull(view);
            // The video should still be playing
            assertTrue(view.isPlaying());

            // The media session state should be playing.
            assertMediaStateIs(PlaybackStateCompat.STATE_PLAYING);
        }
    });
}
 
开发者ID:googlesamples,项目名称:android-PictureInPicture,代码行数:26,代码来源:MediaSessionPlaybackActivityTest.java

示例6: movie_pauseAndResume

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
@Test
public void movie_pauseAndResume() throws Throwable {
    // The movie should be playing on start
    onView(withId(R.id.movie))
            .check(matches(allOf(isDisplayed(), isPlaying())))
            .perform(showControls());
    // Pause
    onView(withId(R.id.toggle)).perform(click());
    onView(withId(R.id.movie)).check(matches((not(isPlaying()))));
    // The media session state should be paused.
    assertMediaStateIs(PlaybackStateCompat.STATE_PAUSED);
    // Resume
    onView(withId(R.id.toggle)).perform(click());
    onView(withId(R.id.movie)).check(matches(isPlaying()));
    // The media session state should be playing.
    assertMediaStateIs(PlaybackStateCompat.STATE_PLAYING);
}
 
开发者ID:googlesamples,项目名称:android-PictureInPicture,代码行数:18,代码来源:MediaSessionPlaybackActivityTest.java

示例7: clearMediaSession

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
public void clearMediaSession() {
    LOGD(TAG, "clearMediaSession()");
    if (isFeatureEnabled(CastConfiguration.FEATURE_LOCKSCREEN)) {
        if (mLockScreenFetchTask != null) {
            mLockScreenFetchTask.cancel(true);
        }
        if (mMediaSessionIconFetchTask != null) {
            mMediaSessionIconFetchTask.cancel(true);
        }
        mAudioManager.abandonAudioFocus(null);
        if (mMediaSessionCompat != null) {
            mMediaSessionCompat.setMetadata(null);
            PlaybackStateCompat playbackState = new PlaybackStateCompat.Builder()
                    .setState(PlaybackStateCompat.STATE_NONE, 0, 1.0f).build();
            mMediaSessionCompat.setPlaybackState(playbackState);
            mMediaSessionCompat.release();
            mMediaSessionCompat.setActive(false);
            mMediaSessionCompat = null;
        }
    }
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:22,代码来源:VideoCastManager.java

示例8: processPauseRequest

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
private void processPauseRequest() {
  if (State.Playing == mState) {
    // Pause media player and cancel the 'foreground service' state.
    mState = State.Paused;
    mHandler.removeCallbacksAndMessages(null);
    mPlayer.pause();
    setState(PlaybackStateCompat.STATE_PAUSED);
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) {
      // while paused, we always retain the MediaPlayer
      relaxResources(false, true);
    } else {
      // on jellybean and above, stay in the foreground and
      // update the notification.
      relaxResources(false, false);
      pauseNotification();
      notifyAudioStatus(AudioUpdateIntent.PAUSED);
    }
  } else if (State.Stopped == mState) {
    // if we get a pause while we're already stopped, it means we likely woke up because
    // of AudioIntentReceiver, so just stop in this case.
    setState(PlaybackStateCompat.STATE_STOPPED);
    stopSelf();
  }
}
 
开发者ID:Elias33,项目名称:Quran,代码行数:25,代码来源:AudioService.java

示例9: recycle

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
static void recycle(Segment segment) {
    if (segment.next != null || segment.prev != null) {
        throw new IllegalArgumentException();
    } else if (!segment.shared) {
        synchronized (SegmentPool.class) {
            if (byteCount + PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH > MAX_SIZE) {
                return;
            }
            byteCount += PlaybackStateCompat.ACTION_PLAY_FROM_SEARCH;
            segment.next = next;
            segment.limit = 0;
            segment.pos = 0;
            next = segment;
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:17,代码来源:SegmentPool.java

示例10: setNotificationPlaybackState

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
private void setNotificationPlaybackState(NotificationCompat.Builder builder) {
    if (mPlaybackState == null || !mStarted) {
        mService.stopForeground(true);
        return;
    }

    if (mPlaybackState.getState() == PlaybackStateCompat.STATE_PLAYING && mPlaybackState.getPosition() >= 0) {
        builder
            .setWhen(System.currentTimeMillis() - mPlaybackState.getPosition())
            .setShowWhen(true)
            .setUsesChronometer(true);
    } else {
        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() == PlaybackStateCompat.STATE_PLAYING);
}
 
开发者ID:AllThatSeries,项目名称:react-native-streaming-audio-player,代码行数:22,代码来源:MediaNotificationManager.java

示例11: onPlaybackStatusChanged

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
@Override
public void onPlaybackStatusChanged(int state) {
    try {
        if (state == PlaybackStateCompat.STATE_PLAYING) {
            instance.scheduleSeekBarUpdate();
        } else {
            instance.stopSeekBarUpdate();
        }
        if (instance.currentSessionCallback != null) {
            instance.currentSessionCallback.updatePlaybackState(state);
        }

        instance.mLastPlaybackState = state;
        if(instance.currentAudio!=null){
            instance.currentAudio.setPlayState(state);
        }
        if (instance.showPlayerNotification) {
            NotificationManager.getInstance().postNotificationName(NotificationManager.audioPlayStateChanged, instance.getCurrentAudio().getMediaId());
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}
 
开发者ID:dibakarece,项目名称:DMAudioStreamer,代码行数:24,代码来源:AudioStreamingManager.java

示例12: pause

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
@Override
public void pause() {
    try {
        if (mState == PlaybackStateCompat.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);
        }
        mState = PlaybackStateCompat.STATE_PAUSED;
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
        unregisterAudioNoisyReceiver();
    } catch (IllegalStateException ex) {
        Logger.e(TAG, ex, "Exception pause IllegalStateException");
        ex.printStackTrace();
    }
}
 
开发者ID:dibakarece,项目名称:DMAudioStreamer,代码行数:23,代码来源:AudioPlaybackListener.java

示例13: seekTo

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
@Override
public void seekTo(int position) {
    Logger.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 = PlaybackStateCompat.STATE_BUFFERING;
        }
        registerAudioNoisyReceiver();
        mMediaPlayer.seekTo(position);
        if (mCallback != null) {
            mCallback.onPlaybackStatusChanged(mState);
        }
    }
}
 
开发者ID:dibakarece,项目名称:DMAudioStreamer,代码行数:19,代码来源:AudioPlaybackListener.java

示例14: onSeekComplete

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
@Override
public void onSeekComplete(MediaPlayer mp) {
    Logger.d(TAG, "onSeekComplete from MediaPlayer:", mp.getCurrentPosition());
    mCurrentPosition = mp.getCurrentPosition();
    if (mState == PlaybackStateCompat.STATE_BUFFERING) {
        registerAudioNoisyReceiver();
        mMediaPlayer.start();
        mState = PlaybackStateCompat.STATE_PLAYING;
    }
    if (mCallback != null) {
        mCallback.onPlaybackStatusChanged(mState);
    }
}
 
开发者ID:dibakarece,项目名称:DMAudioStreamer,代码行数:14,代码来源:AudioPlaybackListener.java

示例15: getFolderSize

import android.support.v4.media.session.PlaybackStateCompat; //导入依赖的package包/类
public static long getFolderSize(File file) {
    long size = 0;
    try {
        if (!file.exists()) {
            return 0;
        }
        if (!file.isDirectory()) {
            return file.length() / PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID;
        }
        File[] fileList = file.listFiles();
        for (int i = 0; i < fileList.length; i++) {
            if (fileList[i].isDirectory()) {
                size += getFolderSize(fileList[i]) * PlaybackStateCompat
                        .ACTION_PLAY_FROM_MEDIA_ID;
            } else {
                size += fileList[i].length();
            }
        }
        return size / PlaybackStateCompat.ACTION_PLAY_FROM_MEDIA_ID;
    } catch (Exception e) {
        e.printStackTrace();
        return 0;
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:25,代码来源:FileUtil.java


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