use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.
the class ImaServerSideAdInsertionMediaSourceTest method adsLoaderStateToBundle_marshallAndUnmarshalling_resultIsEqual.
@Test
public void adsLoaderStateToBundle_marshallAndUnmarshalling_resultIsEqual() {
AdPlaybackState firstAdPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(new AdPlaybackState("adsId1"), /* fromPositionUs= */
0, /* contentResumeOffsetUs= */
10, /* adDurationsUs...= */
5_000_000, 10_000_000, 20_000_000);
AdPlaybackState secondAdPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(new AdPlaybackState("adsId2"), /* fromPositionUs= */
0, /* contentResumeOffsetUs= */
10, /* adDurationsUs...= */
10_000_000).withPlayedAd(/* adGroupIndex= */
0, /* adIndexInAdGroup= */
0);
AdPlaybackState thirdAdPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(new AdPlaybackState("adsId3"), /* fromPositionUs= */
C.TIME_END_OF_SOURCE, /* contentResumeOffsetUs= */
10, /* adDurationsUs...= */
10_000_000);
thirdAdPlaybackState = ServerSideAdInsertionUtil.addAdGroupToAdPlaybackState(thirdAdPlaybackState, /* fromPositionUs= */
0, /* contentResumeOffsetUs= */
10, /* adDurationsUs...= */
10_000_000).withRemovedAdGroupCount(1);
State state = new State(ImmutableMap.<String, AdPlaybackState>builder().put("adsId1", firstAdPlaybackState).put("adsId2", secondAdPlaybackState).put("adsId3", thirdAdPlaybackState).buildOrThrow());
assertThat(State.CREATOR.fromBundle(state.toBundle())).isEqualTo(state);
}
use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.
the class MediaSessionConnector method invalidateMediaSessionPlaybackState.
/**
* Updates the playback state of the media session.
*
* <p>Apps normally only need to call this method when the custom actions provided by a {@link
* CustomActionProvider} changed and the playback state needs to be updated immediately.
*/
public final void invalidateMediaSessionPlaybackState() {
PlaybackStateCompat.Builder builder = new PlaybackStateCompat.Builder();
@Nullable Player player = this.player;
if (player == null) {
builder.setActions(buildPrepareActions()).setState(PlaybackStateCompat.STATE_NONE, /* position= */
0, /* playbackSpeed= */
0, /* updateTime= */
SystemClock.elapsedRealtime());
mediaSession.setRepeatMode(PlaybackStateCompat.REPEAT_MODE_NONE);
mediaSession.setShuffleMode(PlaybackStateCompat.SHUFFLE_MODE_NONE);
mediaSession.setPlaybackState(builder.build());
return;
}
Map<String, CustomActionProvider> currentActions = new HashMap<>();
for (CustomActionProvider customActionProvider : customActionProviders) {
@Nullable PlaybackStateCompat.CustomAction customAction = customActionProvider.getCustomAction(player);
if (customAction != null) {
currentActions.put(customAction.getAction(), customActionProvider);
builder.addCustomAction(customAction);
}
}
customActionMap = Collections.unmodifiableMap(currentActions);
Bundle extras = new Bundle();
@Nullable PlaybackException playbackError = player.getPlayerError();
boolean reportError = playbackError != null || customError != null;
int sessionPlaybackState = reportError ? PlaybackStateCompat.STATE_ERROR : getMediaSessionPlaybackState(player.getPlaybackState(), player.getPlayWhenReady());
if (customError != null) {
builder.setErrorMessage(customError.first, customError.second);
if (customErrorExtras != null) {
extras.putAll(customErrorExtras);
}
} else if (playbackError != null && errorMessageProvider != null) {
Pair<Integer, String> message = errorMessageProvider.getErrorMessage(playbackError);
builder.setErrorMessage(message.first, message.second);
}
long activeQueueItemId = queueNavigator != null ? queueNavigator.getActiveQueueItemId(player) : MediaSessionCompat.QueueItem.UNKNOWN_ID;
float playbackSpeed = player.getPlaybackParameters().speed;
extras.putFloat(EXTRAS_SPEED, playbackSpeed);
float sessionPlaybackSpeed = player.isPlaying() ? playbackSpeed : 0f;
@Nullable MediaItem currentMediaItem = player.getCurrentMediaItem();
if (currentMediaItem != null && !MediaItem.DEFAULT_MEDIA_ID.equals(currentMediaItem.mediaId)) {
extras.putString(PLAYBACK_STATE_EXTRAS_KEY_MEDIA_ID, currentMediaItem.mediaId);
}
builder.setActions(buildPrepareActions() | buildPlaybackActions(player)).setActiveQueueItemId(activeQueueItemId).setBufferedPosition(player.getBufferedPosition()).setState(sessionPlaybackState, player.getCurrentPosition(), sessionPlaybackSpeed, /* updateTime= */
SystemClock.elapsedRealtime()).setExtras(extras);
@Player.RepeatMode int repeatMode = player.getRepeatMode();
mediaSession.setRepeatMode(repeatMode == Player.REPEAT_MODE_ONE ? PlaybackStateCompat.REPEAT_MODE_ONE : repeatMode == Player.REPEAT_MODE_ALL ? PlaybackStateCompat.REPEAT_MODE_ALL : PlaybackStateCompat.REPEAT_MODE_NONE);
mediaSession.setShuffleMode(player.getShuffleModeEnabled() ? PlaybackStateCompat.SHUFFLE_MODE_ALL : PlaybackStateCompat.SHUFFLE_MODE_NONE);
mediaSession.setPlaybackState(builder.build());
}
use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.
the class MappingTrackSelector method buildTracksInfo.
@VisibleForTesting
static /* package */
TracksInfo buildTracksInfo(@NullableType TrackSelection[] selections, MappedTrackInfo mappedTrackInfo) {
ImmutableList.Builder<TracksInfo.TrackGroupInfo> builder = new ImmutableList.Builder<>();
for (int rendererIndex = 0; rendererIndex < mappedTrackInfo.getRendererCount(); rendererIndex++) {
TrackGroupArray trackGroupArray = mappedTrackInfo.getTrackGroups(rendererIndex);
@Nullable TrackSelection trackSelection = selections[rendererIndex];
for (int groupIndex = 0; groupIndex < trackGroupArray.length; groupIndex++) {
TrackGroup trackGroup = trackGroupArray.get(groupIndex);
@C.FormatSupport int[] trackSupport = new int[trackGroup.length];
boolean[] selected = new boolean[trackGroup.length];
for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
trackSupport[trackIndex] = mappedTrackInfo.getTrackSupport(rendererIndex, groupIndex, trackIndex);
boolean isTrackSelected = trackSelection != null && trackSelection.getTrackGroup().equals(trackGroup) && trackSelection.indexOf(trackIndex) != C.INDEX_UNSET;
selected[trackIndex] = isTrackSelected;
}
@C.TrackType int trackGroupType = mappedTrackInfo.getRendererType(rendererIndex);
builder.add(new TracksInfo.TrackGroupInfo(trackGroup, trackSupport, trackGroupType, selected));
}
}
TrackGroupArray unmappedTrackGroups = mappedTrackInfo.getUnmappedTrackGroups();
for (int groupIndex = 0; groupIndex < unmappedTrackGroups.length; groupIndex++) {
TrackGroup trackGroup = unmappedTrackGroups.get(groupIndex);
@C.FormatSupport int[] trackSupport = new int[trackGroup.length];
Arrays.fill(trackSupport, C.FORMAT_UNSUPPORTED_TYPE);
// A track group only contains tracks of the same type, thus only consider the first track.
@C.TrackType int trackGroupType = MimeTypes.getTrackType(trackGroup.getFormat(0).sampleMimeType);
// Initialized to false.
boolean[] selected = new boolean[trackGroup.length];
builder.add(new TracksInfo.TrackGroupInfo(trackGroup, trackSupport, trackGroupType, selected));
}
return new TracksInfo(builder.build());
}
use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.
the class DefaultTrackSelectorTest method setParameterWithSameParametersDoesNotNotifyInvalidationListenerAgain.
/**
* Tests that track selector will not call {@link
* InvalidationListener#onTrackSelectionsInvalidated()} again when it's set with the same values
* of {@link Parameters}.
*/
@Test
public void setParameterWithSameParametersDoesNotNotifyInvalidationListenerAgain() {
ParametersBuilder builder = defaultParameters.buildUpon().setPreferredAudioLanguage("eng");
trackSelector.setParameters(builder);
trackSelector.setParameters(builder);
verify(invalidationListener, times(1)).onTrackSelectionsInvalidated();
}
use of com.google.android.exoplayer2.DefaultLoadControl.Builder in project ExoPlayer by google.
the class DefaultTrackSelectorTest method setParameterWithNonDefaultParameterNotifyInvalidationListener.
/**
* Tests that track selector will call {@link InvalidationListener#onTrackSelectionsInvalidated()}
* when it's set with non-default values of {@link Parameters}.
*/
@Test
public void setParameterWithNonDefaultParameterNotifyInvalidationListener() {
ParametersBuilder builder = defaultParameters.buildUpon().setPreferredAudioLanguage("eng");
trackSelector.setParameters(builder);
verify(invalidationListener).onTrackSelectionsInvalidated();
}
Aggregations