本文整理了Java中com.google.android.exoplayer2.util.Util.constrainValue()
方法的一些代码示例,展示了Util.constrainValue()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util.constrainValue()
方法的具体详情如下:
包路径:com.google.android.exoplayer2.util.Util
类名称:Util
方法名:constrainValue
[英]Constrains a value to the specified bounds.
[中]将值约束到指定的边界。
代码示例来源:origin: google/ExoPlayer
/** Returns whether it's possible to apply the specified edit using gapless playback info. */
private static boolean canApplyEditWithGaplessInfo(
long[] timestamps, long duration, long editStartTime, long editEndTime) {
int lastIndex = timestamps.length - 1;
int latestDelayIndex = Util.constrainValue(MAX_GAPLESS_TRIM_SIZE_SAMPLES, 0, lastIndex);
int earliestPaddingIndex =
Util.constrainValue(timestamps.length - MAX_GAPLESS_TRIM_SIZE_SAMPLES, 0, lastIndex);
return timestamps[0] <= editStartTime
&& editStartTime < timestamps[latestDelayIndex]
&& timestamps[earliestPaddingIndex] < editEndTime
&& editEndTime <= duration;
}
代码示例来源:origin: google/ExoPlayer
/**
* Returns the sample index for the sample at given position.
*
* @param timeUs Time position in microseconds in the FLAC stream.
* @return The sample index for the sample at given position.
*/
public long getSampleIndex(long timeUs) {
long sampleIndex = (timeUs * sampleRate) / C.MICROS_PER_SECOND;
return Util.constrainValue(sampleIndex, 0, totalSamples - 1);
}
代码示例来源:origin: google/ExoPlayer
private long getFramePositionForTimeUs(long timeUs) {
long positionOffset = (timeUs * bitrate) / (C.MICROS_PER_SECOND * C.BITS_PER_BYTE);
// Constrain to nearest preceding frame offset.
positionOffset = (positionOffset / frameSize) * frameSize;
positionOffset =
Util.constrainValue(positionOffset, /* min= */ 0, /* max= */ dataSize - frameSize);
return firstFrameBytePosition + positionOffset;
}
}
代码示例来源:origin: google/ExoPlayer
private void positionScrubber(float xPosition) {
scrubberBar.right = Util.constrainValue((int) xPosition, progressBar.left, progressBar.right);
}
代码示例来源:origin: google/ExoPlayer
/**
* Ensures {@code peekBuffer} is large enough to store at least {@code length} bytes from the
* current peek position.
*/
private void ensureSpaceForPeek(int length) {
int requiredLength = peekBufferPosition + length;
if (requiredLength > peekBuffer.length) {
int newPeekCapacity = Util.constrainValue(peekBuffer.length * 2,
requiredLength + PEEK_MIN_FREE_SPACE_AFTER_RESIZE, requiredLength + PEEK_MAX_FREE_SPACE);
peekBuffer = Arrays.copyOf(peekBuffer, newPeekCapacity);
}
}
代码示例来源:origin: google/ExoPlayer
private SeekParameters clipSeekParameters(long positionUs, SeekParameters seekParameters) {
long toleranceBeforeUs =
Util.constrainValue(
seekParameters.toleranceBeforeUs, /* min= */ 0, /* max= */ positionUs - startUs);
long toleranceAfterUs =
Util.constrainValue(
seekParameters.toleranceAfterUs,
/* min= */ 0,
/* max= */ endUs == C.TIME_END_OF_SOURCE ? Long.MAX_VALUE : endUs - positionUs);
if (toleranceBeforeUs == seekParameters.toleranceBeforeUs
&& toleranceAfterUs == seekParameters.toleranceAfterUs) {
return seekParameters;
} else {
return new SeekParameters(toleranceBeforeUs, toleranceAfterUs);
}
}
代码示例来源:origin: google/ExoPlayer
/**
* Sets the playback speed. Calling this method will discard any data buffered within the
* processor, and may update the value returned by {@link #isActive()}.
*
* @param speed The requested new playback speed.
* @return The actual new playback speed.
*/
public float setSpeed(float speed) {
speed = Util.constrainValue(speed, MINIMUM_SPEED, MAXIMUM_SPEED);
if (this.speed != speed) {
this.speed = speed;
sonic = null;
}
flush();
return speed;
}
代码示例来源:origin: google/ExoPlayer
/**
* Sets the playback pitch. Calling this method will discard any data buffered within the
* processor, and may update the value returned by {@link #isActive()}.
*
* @param pitch The requested new pitch.
* @return The actual new pitch.
*/
public float setPitch(float pitch) {
pitch = Util.constrainValue(pitch, MINIMUM_PITCH, MAXIMUM_PITCH);
if (this.pitch != pitch) {
this.pitch = pitch;
sonic = null;
}
flush();
return pitch;
}
代码示例来源:origin: google/ExoPlayer
| (initializationBytes[11] & 0xFF);
defaultVerticalPlacement = (float) requestedVerticalPlacement / calculatedVideoTrackHeight;
defaultVerticalPlacement = Util.constrainValue(defaultVerticalPlacement, 0.0f, 0.95f);
} else {
defaultVerticalPlacement = DEFAULT_VERTICAL_PLACEMENT;
代码示例来源:origin: google/ExoPlayer
private long getSegmentNum(
RepresentationHolder representationHolder,
@Nullable MediaChunk previousChunk,
long loadPositionUs,
long firstAvailableSegmentNum,
long lastAvailableSegmentNum) {
return previousChunk != null
? previousChunk.getNextChunkIndex()
: Util.constrainValue(
representationHolder.getSegmentNum(loadPositionUs),
firstAvailableSegmentNum,
lastAvailableSegmentNum);
}
代码示例来源:origin: google/ExoPlayer
@Override
public final int getBufferedPercentage() {
long position = getBufferedPosition();
long duration = getDuration();
return position == C.TIME_UNSET || duration == C.TIME_UNSET
? 0
: duration == 0 ? 100 : Util.constrainValue((int) ((position * 100) / duration), 0, 100);
}
代码示例来源:origin: google/ExoPlayer
private void drawPlayhead(Canvas canvas) {
if (duration <= 0) {
return;
}
int playheadX = Util.constrainValue(scrubberBar.right, scrubberBar.left, progressBar.right);
int playheadY = scrubberBar.centerY();
if (scrubberDrawable == null) {
int scrubberSize = (scrubbing || isFocused()) ? scrubberDraggedSize
: (isEnabled() ? scrubberEnabledSize : scrubberDisabledSize);
int playheadRadius = scrubberSize / 2;
canvas.drawCircle(playheadX, playheadY, playheadRadius, scrubberPaint);
} else {
int scrubberDrawableWidth = scrubberDrawable.getIntrinsicWidth();
int scrubberDrawableHeight = scrubberDrawable.getIntrinsicHeight();
scrubberDrawable.setBounds(
playheadX - scrubberDrawableWidth / 2,
playheadY - scrubberDrawableHeight / 2,
playheadX + scrubberDrawableWidth / 2,
playheadY + scrubberDrawableHeight / 2);
scrubberDrawable.draw(canvas);
}
}
代码示例来源:origin: google/ExoPlayer
private void parsePaletteSection(ParsableByteArray buffer, int sectionLength) {
if ((sectionLength % 5) != 2) {
// Section must be two bytes followed by a whole number of (index, y, cb, cr, a) entries.
return;
}
buffer.skipBytes(2);
Arrays.fill(colors, 0);
int entryCount = sectionLength / 5;
for (int i = 0; i < entryCount; i++) {
int index = buffer.readUnsignedByte();
int y = buffer.readUnsignedByte();
int cr = buffer.readUnsignedByte();
int cb = buffer.readUnsignedByte();
int a = buffer.readUnsignedByte();
int r = (int) (y + (1.40200 * (cr - 128)));
int g = (int) (y - (0.34414 * (cb - 128)) - (0.71414 * (cr - 128)));
int b = (int) (y + (1.77200 * (cb - 128)));
colors[index] =
(a << 24)
| (Util.constrainValue(r, 0, 255) << 16)
| (Util.constrainValue(g, 0, 255) << 8)
| Util.constrainValue(b, 0, 255);
}
colorsSet = true;
}
代码示例来源:origin: google/ExoPlayer
@Override
public void setVolume(float audioVolume) {
verifyApplicationThread();
audioVolume = Util.constrainValue(audioVolume, /* min= */ 0, /* max= */ 1);
if (this.audioVolume == audioVolume) {
return;
}
this.audioVolume = audioVolume;
sendVolumeToRenderers();
for (AudioListener audioListener : audioListeners) {
audioListener.onVolumeChanged(audioVolume);
}
}
代码示例来源:origin: google/ExoPlayer
private int getDefaultBufferSize() {
if (isInputPcm) {
int minBufferSize =
AudioTrack.getMinBufferSize(outputSampleRate, outputChannelConfig, outputEncoding);
Assertions.checkState(minBufferSize != ERROR_BAD_VALUE);
int multipliedBufferSize = minBufferSize * BUFFER_MULTIPLICATION_FACTOR;
int minAppBufferSize = (int) durationUsToFrames(MIN_BUFFER_DURATION_US) * outputPcmFrameSize;
int maxAppBufferSize = (int) Math.max(minBufferSize,
durationUsToFrames(MAX_BUFFER_DURATION_US) * outputPcmFrameSize);
return Util.constrainValue(multipliedBufferSize, minAppBufferSize, maxAppBufferSize);
} else {
int rate = getMaximumEncodedRateBytesPerSecond(outputEncoding);
if (outputEncoding == C.ENCODING_AC3) {
rate *= AC3_BUFFER_MULTIPLICATION_FACTOR;
}
return (int) (PASSTHROUGH_BUFFER_DURATION_US * rate / C.MICROS_PER_SECOND);
}
}
代码示例来源:origin: TeamNewPipe/NewPipe
private void publishFloatingQueueWindow() {
if (callback.getQueueSize() == 0) {
mediaSession.setQueue(Collections.emptyList());
activeQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID;
return;
}
// Yes this is almost a copypasta, got a problem with that? =\
int windowCount = callback.getQueueSize();
int currentWindowIndex = callback.getCurrentPlayingIndex();
int queueSize = Math.min(maxQueueSize, windowCount);
int startIndex = Util.constrainValue(currentWindowIndex - ((queueSize - 1) / 2), 0,
windowCount - queueSize);
List<MediaSessionCompat.QueueItem> queue = new ArrayList<>();
for (int i = startIndex; i < startIndex + queueSize; i++) {
queue.add(new MediaSessionCompat.QueueItem(callback.getQueueMetadata(i), i));
}
mediaSession.setQueue(queue);
activeQueueItemId = currentWindowIndex;
}
代码示例来源:origin: google/ExoPlayer
private void publishFloatingQueueWindow(Player player) {
if (player.getCurrentTimeline().isEmpty()) {
mediaSession.setQueue(Collections.emptyList());
activeQueueItemId = MediaSessionCompat.QueueItem.UNKNOWN_ID;
return;
}
int windowCount = player.getCurrentTimeline().getWindowCount();
int currentWindowIndex = player.getCurrentWindowIndex();
int queueSize = Math.min(maxQueueSize, windowCount);
int startIndex = Util.constrainValue(currentWindowIndex - ((queueSize - 1) / 2), 0,
windowCount - queueSize);
List<MediaSessionCompat.QueueItem> queue = new ArrayList<>();
for (int i = startIndex; i < startIndex + queueSize; i++) {
queue.add(new MediaSessionCompat.QueueItem(getMediaDescription(player, i), i));
}
mediaSession.setQueue(queue);
activeQueueItemId = currentWindowIndex;
}
代码示例来源:origin: google/ExoPlayer
/**
* Incrementally scrubs the position by {@code positionChange}.
*
* @param positionChange The change in the scrubber position, in milliseconds. May be negative.
* @return Returns whether the scrubber position changed.
*/
private boolean scrubIncrementally(long positionChange) {
if (duration <= 0) {
return false;
}
long scrubberPosition = getScrubberPosition();
scrubPosition = Util.constrainValue(scrubberPosition + positionChange, 0, duration);
if (scrubPosition == scrubberPosition) {
return false;
}
if (!scrubbing) {
startScrubbing();
}
for (OnScrubListener listener : listeners) {
listener.onScrubMove(this, scrubPosition);
}
update();
return true;
}
代码示例来源:origin: google/ExoPlayer
@Override
public SeekPoints getSeekPoints(long timeUs) {
timeUs = Util.constrainValue(timeUs, 0, durationUs);
Pair<Long, Long> timeMsAndPosition =
linearlyInterpolate(C.usToMs(timeUs), referenceTimesMs, referencePositions);
timeUs = C.msToUs(timeMsAndPosition.first);
long position = timeMsAndPosition.second;
return new SeekPoints(new SeekPoint(timeUs, position));
}
代码示例来源:origin: google/ExoPlayer
@Override
public SeekPoints getSeekPoints(long timeUs) {
long positionOffset = (timeUs * averageBytesPerSecond) / C.MICROS_PER_SECOND;
// Constrain to nearest preceding frame offset.
positionOffset = (positionOffset / blockAlignment) * blockAlignment;
positionOffset = Util.constrainValue(positionOffset, 0, dataSize - blockAlignment);
long seekPosition = dataStartPosition + positionOffset;
long seekTimeUs = getTimeUs(seekPosition);
SeekPoint seekPoint = new SeekPoint(seekTimeUs, seekPosition);
if (seekTimeUs >= timeUs || positionOffset == dataSize - blockAlignment) {
return new SeekPoints(seekPoint);
} else {
long secondSeekPosition = seekPosition + blockAlignment;
long secondSeekTimeUs = getTimeUs(secondSeekPosition);
SeekPoint secondSeekPoint = new SeekPoint(secondSeekTimeUs, secondSeekPosition);
return new SeekPoints(seekPoint, secondSeekPoint);
}
}
内容来源于网络,如有侵权,请联系作者删除!