當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。