use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters in project ExoPlayer by google.
the class SimpleExoPlayer method setPlaybackParams.
/**
* Sets the {@link PlaybackParams} governing audio playback.
*
* @param params The {@link PlaybackParams}, or null to clear any previously set parameters.
*/
@TargetApi(23)
public void setPlaybackParams(PlaybackParams params) {
if (params != null) {
// The audio renderers will call this on the playback thread to ensure they can query
// parameters without failure. We do the same up front, which is redundant except that it
// ensures an immediate call to getPlaybackParams will retrieve the instance with defaults
// allowed, rather than this change becoming visible sometime later once the audio renderers
// receive the parameters.
params.allowDefaults();
playbackParamsHolder = new PlaybackParamsHolder(params);
} else {
playbackParamsHolder = null;
}
ExoPlayerMessage[] messages = new ExoPlayerMessage[audioRendererCount];
int count = 0;
for (Renderer renderer : renderers) {
if (renderer.getTrackType() == C.TRACK_TYPE_AUDIO) {
messages[count++] = new ExoPlayerMessage(renderer, C.MSG_SET_PLAYBACK_PARAMS, params);
}
}
player.sendMessages(messages);
}
use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters in project NewPipe by TeamNewPipe.
the class BasePlayer method getPlaybackParameters.
public PlaybackParameters getPlaybackParameters() {
final PlaybackParameters defaultParameters = new PlaybackParameters(1f, 1f);
if (simpleExoPlayer == null)
return defaultParameters;
final PlaybackParameters parameters = simpleExoPlayer.getPlaybackParameters();
return parameters == null ? defaultParameters : parameters;
}
use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters in project ExoPlayer by google.
the class OkHttpDataSourceTest method open_setsCorrectHeaders.
/**
* This test will set HTTP default request parameters (1) in the OkHttpDataSource, (2) via
* OkHttpDataSource.setRequestProperty() and (3) in the DataSpec instance according to the table
* below. Values wrapped in '*' are the ones that should be set in the connection request.
*
* <pre>{@code
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* | | Header Key |
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* | Location | 0 | 1 | 2 | 3 | 4 | 5 | 6 |
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* | Constructor | *Y* | Y | Y | | Y | | |
* | Setter | | *Y* | Y | Y | | *Y* | |
* | DataSpec | | | *Y* | *Y* | *Y* | | *Y* |
* +---------------+-----+-----+-----+-----+-----+-----+-----+
* }</pre>
*/
@Test
public void open_setsCorrectHeaders() throws Exception {
MockWebServer mockWebServer = new MockWebServer();
mockWebServer.enqueue(new MockResponse());
String propertyFromFactory = "fromFactory";
Map<String, String> defaultRequestProperties = new HashMap<>();
defaultRequestProperties.put("0", propertyFromFactory);
defaultRequestProperties.put("1", propertyFromFactory);
defaultRequestProperties.put("2", propertyFromFactory);
defaultRequestProperties.put("4", propertyFromFactory);
HttpDataSource dataSource = new OkHttpDataSource.Factory(new OkHttpClient()).setDefaultRequestProperties(defaultRequestProperties).createDataSource();
String propertyFromSetter = "fromSetter";
dataSource.setRequestProperty("1", propertyFromSetter);
dataSource.setRequestProperty("2", propertyFromSetter);
dataSource.setRequestProperty("3", propertyFromSetter);
dataSource.setRequestProperty("5", propertyFromSetter);
String propertyFromDataSpec = "fromDataSpec";
Map<String, String> dataSpecRequestProperties = new HashMap<>();
dataSpecRequestProperties.put("2", propertyFromDataSpec);
dataSpecRequestProperties.put("3", propertyFromDataSpec);
dataSpecRequestProperties.put("4", propertyFromDataSpec);
dataSpecRequestProperties.put("6", propertyFromDataSpec);
DataSpec dataSpec = new DataSpec.Builder().setUri(mockWebServer.url("/test-path").toString()).setHttpRequestHeaders(dataSpecRequestProperties).build();
dataSource.open(dataSpec);
Headers headers = mockWebServer.takeRequest(10, SECONDS).getHeaders();
assertThat(headers.get("0")).isEqualTo(propertyFromFactory);
assertThat(headers.get("1")).isEqualTo(propertyFromSetter);
assertThat(headers.get("2")).isEqualTo(propertyFromDataSpec);
assertThat(headers.get("3")).isEqualTo(propertyFromDataSpec);
assertThat(headers.get("4")).isEqualTo(propertyFromDataSpec);
assertThat(headers.get("5")).isEqualTo(propertyFromSetter);
assertThat(headers.get("6")).isEqualTo(propertyFromDataSpec);
}
use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters in project ExoPlayer by google.
the class DownloadHelper method runTrackSelection.
/**
* Runs the track selection for a given period index with the current parameters. The selected
* tracks will be added to {@link #trackSelectionsByPeriodAndRenderer}.
*/
@RequiresNonNull({ "trackGroupArrays", "trackSelectionsByPeriodAndRenderer", "mediaPreparer", "mediaPreparer.timeline" })
private TrackSelectorResult runTrackSelection(int periodIndex) {
try {
TrackSelectorResult trackSelectorResult = trackSelector.selectTracks(rendererCapabilities, trackGroupArrays[periodIndex], new MediaPeriodId(mediaPreparer.timeline.getUidOfPeriod(periodIndex)), mediaPreparer.timeline);
for (int i = 0; i < trackSelectorResult.length; i++) {
@Nullable ExoTrackSelection newSelection = trackSelectorResult.selections[i];
if (newSelection == null) {
continue;
}
List<ExoTrackSelection> existingSelectionList = trackSelectionsByPeriodAndRenderer[periodIndex][i];
boolean mergedWithExistingSelection = false;
for (int j = 0; j < existingSelectionList.size(); j++) {
ExoTrackSelection existingSelection = existingSelectionList.get(j);
if (existingSelection.getTrackGroup().equals(newSelection.getTrackGroup())) {
// Merge with existing selection.
scratchSet.clear();
for (int k = 0; k < existingSelection.length(); k++) {
scratchSet.put(existingSelection.getIndexInTrackGroup(k), 0);
}
for (int k = 0; k < newSelection.length(); k++) {
scratchSet.put(newSelection.getIndexInTrackGroup(k), 0);
}
int[] mergedTracks = new int[scratchSet.size()];
for (int k = 0; k < scratchSet.size(); k++) {
mergedTracks[k] = scratchSet.keyAt(k);
}
existingSelectionList.set(j, new DownloadTrackSelection(existingSelection.getTrackGroup(), mergedTracks));
mergedWithExistingSelection = true;
break;
}
}
if (!mergedWithExistingSelection) {
existingSelectionList.add(newSelection);
}
}
return trackSelectorResult;
} catch (ExoPlaybackException e) {
// DefaultTrackSelector does not throw exceptions during track selection.
throw new UnsupportedOperationException(e);
}
}
use of com.google.android.exoplayer2.trackselection.DefaultTrackSelector.Parameters in project ExoPlayer by google.
the class TrackSelectionDialog method createForTrackSelector.
/**
* Creates a dialog for a given {@link DefaultTrackSelector}, whose parameters will be
* automatically updated when tracks are selected.
*
* @param trackSelector The {@link DefaultTrackSelector}.
* @param onDismissListener A {@link DialogInterface.OnDismissListener} to call when the dialog is
* dismissed.
*/
public static TrackSelectionDialog createForTrackSelector(DefaultTrackSelector trackSelector, DialogInterface.OnDismissListener onDismissListener) {
MappedTrackInfo mappedTrackInfo = Assertions.checkNotNull(trackSelector.getCurrentMappedTrackInfo());
TrackSelectionDialog trackSelectionDialog = new TrackSelectionDialog();
DefaultTrackSelector.Parameters parameters = trackSelector.getParameters();
trackSelectionDialog.init(/* titleId= */
R.string.track_selection_title, mappedTrackInfo, /* initialParameters = */
parameters, /* allowAdaptiveSelections= */
true, /* allowMultipleOverrides= */
false, /* onClickListener= */
(dialog, which) -> {
DefaultTrackSelector.ParametersBuilder builder = parameters.buildUpon();
for (int i = 0; i < mappedTrackInfo.getRendererCount(); i++) {
builder.clearSelectionOverrides(/* rendererIndex= */
i).setRendererDisabled(/* rendererIndex= */
i, trackSelectionDialog.getIsDisabled(/* rendererIndex= */
i));
List<SelectionOverride> overrides = trackSelectionDialog.getOverrides(/* rendererIndex= */
i);
if (!overrides.isEmpty()) {
builder.setSelectionOverride(/* rendererIndex= */
i, mappedTrackInfo.getTrackGroups(/* rendererIndex= */
i), overrides.get(0));
}
}
trackSelector.setParameters(builder);
}, onDismissListener);
return trackSelectionDialog;
}
Aggregations