Search in sources :

Example 1 with TrackSelectionParameters

use of androidx.media3.common.TrackSelectionParameters in project media by androidx.

the class PlayerInfo method fromBundle.

private static PlayerInfo fromBundle(Bundle bundle) {
    @Nullable PlaybackException playerError = BundleableUtil.fromNullableBundle(PlaybackException.CREATOR, bundle.getBundle(keyForField(FIELD_PLAYBACK_ERROR)));
    int mediaItemTransitionReason = bundle.getInt(keyForField(FIELD_MEDIA_ITEM_TRANSITION_REASON), MEDIA_ITEM_TRANSITION_REASON_REPEAT);
    SessionPositionInfo sessionPositionInfo = BundleableUtil.fromNullableBundle(SessionPositionInfo.CREATOR, bundle.getBundle(keyForField(FIELD_SESSION_POSITION_INFO)), SessionPositionInfo.DEFAULT);
    PositionInfo oldPositionInfo = BundleableUtil.fromNullableBundle(PositionInfo.CREATOR, bundle.getBundle(keyForField(FIELD_OLD_POSITION_INFO)), SessionPositionInfo.DEFAULT_POSITION_INFO);
    PositionInfo newPositionInfo = BundleableUtil.fromNullableBundle(PositionInfo.CREATOR, bundle.getBundle(keyForField(FIELD_NEW_POSITION_INFO)), SessionPositionInfo.DEFAULT_POSITION_INFO);
    int discontinuityReason = bundle.getInt(keyForField(FIELD_DISCONTINUITY_REASON), DISCONTINUITY_REASON_AUTO_TRANSITION);
    @Nullable Bundle playbackParametersBundle = bundle.getBundle(keyForField(FIELD_PLAYBACK_PARAMETERS));
    PlaybackParameters playbackParameters = BundleableUtil.fromNullableBundle(PlaybackParameters.CREATOR, playbackParametersBundle, /* defaultValue= */
    PlaybackParameters.DEFAULT);
    @Player.RepeatMode int repeatMode = bundle.getInt(keyForField(FIELD_REPEAT_MODE), /* defaultValue= */
    Player.REPEAT_MODE_OFF);
    boolean shuffleModeEnabled = bundle.getBoolean(keyForField(FIELD_SHUFFLE_MODE_ENABLED), /* defaultValue= */
    false);
    Timeline timeline = BundleableUtil.fromNullableBundle(Timeline.CREATOR, bundle.getBundle(keyForField(FIELD_TIMELINE)), Timeline.EMPTY);
    VideoSize videoSize = BundleableUtil.fromNullableBundle(VideoSize.CREATOR, bundle.getBundle(keyForField(FIELD_VIDEO_SIZE)), VideoSize.UNKNOWN);
    MediaMetadata playlistMetadata = BundleableUtil.fromNullableBundle(MediaMetadata.CREATOR, bundle.getBundle(keyForField(FIELD_PLAYLIST_METADATA)), MediaMetadata.EMPTY);
    float volume = bundle.getFloat(keyForField(FIELD_VOLUME), /* defaultValue= */
    1);
    AudioAttributes audioAttributes = BundleableUtil.fromNullableBundle(AudioAttributes.CREATOR, bundle.getBundle(keyForField(FIELD_AUDIO_ATTRIBUTES)), /* defaultValue= */
    AudioAttributes.DEFAULT);
    List<Cue> cues = BundleableUtil.fromBundleNullableList(Cue.CREATOR, bundle.getParcelableArrayList(keyForField(FIELD_CUES)), /* defaultValue= */
    ImmutableList.of());
    @Nullable Bundle deviceInfoBundle = bundle.getBundle(keyForField(FIELD_DEVICE_INFO));
    DeviceInfo deviceInfo = BundleableUtil.fromNullableBundle(DeviceInfo.CREATOR, deviceInfoBundle, /* defaultValue= */
    DeviceInfo.UNKNOWN);
    int deviceVolume = bundle.getInt(keyForField(FIELD_DEVICE_VOLUME), /* defaultValue= */
    0);
    boolean deviceMuted = bundle.getBoolean(keyForField(FIELD_DEVICE_MUTED), /* defaultValue= */
    false);
    boolean playWhenReady = bundle.getBoolean(keyForField(FIELD_PLAY_WHEN_READY), /* defaultValue= */
    false);
    int playWhenReadyChangedReason = bundle.getInt(keyForField(FIELD_PLAY_WHEN_READY_CHANGED_REASON), /* defaultValue= */
    PLAY_WHEN_READY_CHANGE_REASON_USER_REQUEST);
    @Player.PlaybackSuppressionReason int playbackSuppressionReason = bundle.getInt(keyForField(FIELD_PLAYBACK_SUPPRESSION_REASON), /* defaultValue= */
    PLAYBACK_SUPPRESSION_REASON_NONE);
    @Player.State int playbackState = bundle.getInt(keyForField(FIELD_PLAYBACK_STATE), /* defaultValue= */
    STATE_IDLE);
    boolean isPlaying = bundle.getBoolean(keyForField(FIELD_IS_PLAYING), /* defaultValue= */
    false);
    boolean isLoading = bundle.getBoolean(keyForField(FIELD_IS_LOADING), /* defaultValue= */
    false);
    MediaMetadata mediaMetadata = BundleableUtil.fromNullableBundle(MediaMetadata.CREATOR, bundle.getBundle(keyForField(FIELD_MEDIA_METADATA)), MediaMetadata.EMPTY);
    long seekBackIncrementMs = bundle.getLong(keyForField(FIELD_SEEK_BACK_INCREMENT_MS), /* defaultValue= */
    0);
    long seekForwardIncrementMs = bundle.getLong(keyForField(FIELD_SEEK_FORWARD_INCREMENT_MS), /* defaultValue= */
    0);
    long maxSeekToPreviousPosition = bundle.getLong(keyForField(FIELD_MAX_SEEK_TO_PREVIOUS_POSITION_MS), /* defaultValue= */
    0);
    TrackSelectionParameters trackSelectionParameters = BundleableUtil.fromNullableBundle(TrackSelectionParameters.CREATOR, bundle.getBundle(keyForField(FIELD_TRACK_SELECTION_PARAMETERS)), TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT);
    return new PlayerInfo(playerError, mediaItemTransitionReason, sessionPositionInfo, oldPositionInfo, newPositionInfo, discontinuityReason, playbackParameters, repeatMode, shuffleModeEnabled, videoSize, timeline, playlistMetadata, volume, audioAttributes, cues, deviceInfo, deviceVolume, deviceMuted, playWhenReady, playWhenReadyChangedReason, playbackSuppressionReason, playbackState, isPlaying, isLoading, mediaMetadata, seekBackIncrementMs, seekForwardIncrementMs, maxSeekToPreviousPosition, trackSelectionParameters);
}
Also used : PlaybackException(androidx.media3.common.PlaybackException) PlaybackSuppressionReason(androidx.media3.common.Player.PlaybackSuppressionReason) Bundle(android.os.Bundle) AudioAttributes(androidx.media3.common.AudioAttributes) State(androidx.media3.common.Player.State) Timeline(androidx.media3.common.Timeline) Cue(androidx.media3.common.text.Cue) TrackSelectionParameters(androidx.media3.common.TrackSelectionParameters) VideoSize(androidx.media3.common.VideoSize) DeviceInfo(androidx.media3.common.DeviceInfo) PositionInfo(androidx.media3.common.Player.PositionInfo) MediaMetadata(androidx.media3.common.MediaMetadata) Nullable(androidx.annotation.Nullable) PlaybackParameters(androidx.media3.common.PlaybackParameters)

Example 2 with TrackSelectionParameters

use of androidx.media3.common.TrackSelectionParameters in project media by androidx.

the class MediaControllerListenerTest method onTrackSelectionParametersChanged.

/**
 * This also tests {@link MediaController#getTrackSelectionParameters()}.
 */
@Test
public void onTrackSelectionParametersChanged() throws Exception {
    RemoteMediaSession.RemoteMockPlayer player = remoteSession.getMockPlayer();
    player.setTrackSelectionParameters(TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT);
    MediaController controller = controllerTestRule.createController(remoteSession.getToken());
    AtomicReference<TrackSelectionParameters> parametersFromParamRef = new AtomicReference<>();
    AtomicReference<TrackSelectionParameters> parametersFromGetterRef = new AtomicReference<>();
    CountDownLatch latch = new CountDownLatch(1);
    Player.Listener listener = new Player.Listener() {

        @Override
        public void onTrackSelectionParametersChanged(TrackSelectionParameters parameters) {
            parametersFromParamRef.set(parameters);
            parametersFromGetterRef.set(controller.getTrackSelectionParameters());
            latch.countDown();
        }
    };
    threadTestRule.getHandler().postAndSync(() -> controller.addListener(listener));
    TrackSelectionParameters parameters = TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT.buildUpon().setMaxAudioBitrate(100).build();
    player.notifyTrackSelectionParametersChanged(parameters);
    assertThat(latch.await(TIMEOUT_MS, MILLISECONDS)).isTrue();
    assertThat(parametersFromParamRef.get()).isEqualTo(parameters);
    assertThat(parametersFromGetterRef.get()).isEqualTo(parameters);
}
Also used : RemoteMockPlayer(androidx.media3.session.RemoteMediaSession.RemoteMockPlayer) Player(androidx.media3.common.Player) TrackSelectionParameters(androidx.media3.common.TrackSelectionParameters) AtomicReference(java.util.concurrent.atomic.AtomicReference) RemoteMockPlayer(androidx.media3.session.RemoteMediaSession.RemoteMockPlayer) CountDownLatch(java.util.concurrent.CountDownLatch) LargeTest(androidx.test.filters.LargeTest) Test(org.junit.Test)

Example 3 with TrackSelectionParameters

use of androidx.media3.common.TrackSelectionParameters in project media by androidx.

the class MediaSessionPlayerTest method setTrackSelectionParameters.

@Test
public void setTrackSelectionParameters() throws Exception {
    TrackSelectionParameters trackSelectionParameters = TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT.buildUpon().setMaxAudioBitrate(10).build();
    controller.setTrackSelectionParameters(trackSelectionParameters);
    player.awaitMethodCalled(MockPlayer.METHOD_SET_TRACK_SELECTION_PARAMETERS, TIMEOUT_MS);
    assertThat(player.trackSelectionParameters).isEqualTo(trackSelectionParameters);
}
Also used : TrackSelectionParameters(androidx.media3.common.TrackSelectionParameters) Test(org.junit.Test) LargeTest(androidx.test.filters.LargeTest)

Example 4 with TrackSelectionParameters

use of androidx.media3.common.TrackSelectionParameters in project media by androidx.

the class DefaultAnalyticsCollector method onTrackSelectionParametersChanged.

@Override
public void onTrackSelectionParametersChanged(TrackSelectionParameters parameters) {
    EventTime eventTime = generateCurrentPlayerMediaPeriodEventTime();
    sendEvent(eventTime, AnalyticsListener.EVENT_TRACK_SELECTION_PARAMETERS_CHANGED, listener -> listener.onTrackSelectionParametersChanged(eventTime, parameters));
}
Also used : EventTime(androidx.media3.exoplayer.analytics.AnalyticsListener.EventTime)

Example 5 with TrackSelectionParameters

use of androidx.media3.common.TrackSelectionParameters in project media by androidx.

the class MockPlayerTest method setTrackSelectionParameters.

@Test
public void setTrackSelectionParameters() {
    TrackSelectionParameters trackSelectionParameters = TrackSelectionParameters.DEFAULT_WITHOUT_CONTEXT.buildUpon().setMaxAudioBitrate(10).build();
    player.setTrackSelectionParameters(trackSelectionParameters);
    assertThat(player.hasMethodBeenCalled(MockPlayer.METHOD_SET_TRACK_SELECTION_PARAMETERS)).isTrue();
    assertThat(player.trackSelectionParameters).isSameInstanceAs(trackSelectionParameters);
}
Also used : TrackSelectionParameters(androidx.media3.common.TrackSelectionParameters) SmallTest(androidx.test.filters.SmallTest) Test(org.junit.Test)

Aggregations

TrackSelectionParameters (androidx.media3.common.TrackSelectionParameters)8 Test (org.junit.Test)6 LargeTest (androidx.test.filters.LargeTest)4 Bundle (android.os.Bundle)3 PlaybackParameters (androidx.media3.common.PlaybackParameters)2 Timeline (androidx.media3.common.Timeline)2 TrackSelectionOverride (androidx.media3.common.TrackSelectionOverrides.TrackSelectionOverride)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 Intent (android.content.Intent)1 Nullable (androidx.annotation.Nullable)1 AudioAttributes (androidx.media3.common.AudioAttributes)1 DeviceInfo (androidx.media3.common.DeviceInfo)1 MediaItem (androidx.media3.common.MediaItem)1 MediaMetadata (androidx.media3.common.MediaMetadata)1 PlaybackException (androidx.media3.common.PlaybackException)1 Player (androidx.media3.common.Player)1 PlaybackSuppressionReason (androidx.media3.common.Player.PlaybackSuppressionReason)1 PositionInfo (androidx.media3.common.Player.PositionInfo)1 RepeatMode (androidx.media3.common.Player.RepeatMode)1 State (androidx.media3.common.Player.State)1