本文整理汇总了Java中com.google.android.exoplayer.util.Util.binarySearchFloor方法的典型用法代码示例。如果您正苦于以下问题:Java Util.binarySearchFloor方法的具体用法?Java Util.binarySearchFloor怎么用?Java Util.binarySearchFloor使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.google.android.exoplayer.util.Util
的用法示例。
在下文中一共展示了Util.binarySearchFloor方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTimeUs
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
@Override
public long getTimeUs(long position) {
long offsetByte = 256 * (position - firstFramePosition) / sizeBytes;
int previousIndex = Util.binarySearchFloor(tableOfContents, offsetByte, true, false);
long previousTime = getTimeUsForTocIndex(previousIndex);
if (previousIndex == 98) {
return previousTime;
}
// Linearly interpolate the time taking into account the next entry.
long previousByte = previousIndex == -1 ? 0 : tableOfContents[previousIndex];
long nextByte = tableOfContents[previousIndex + 1];
long nextTime = getTimeUsForTocIndex(previousIndex + 1);
long timeOffset =
(nextTime - previousTime) * (offsetByte - previousByte) / (nextByte - previousByte);
return previousTime + timeOffset;
}
示例2: getTimeUs
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
@Override
public long getTimeUs(long position) {
if (!isSeekable() || position < firstFramePosition) {
return 0L;
}
double offsetByte = 256.0 * (position - firstFramePosition) / sizeBytes;
int previousTocPosition =
Util.binarySearchFloor(tableOfContents, (long) offsetByte, true, false) + 1;
long previousTime = getTimeUsForTocPosition(previousTocPosition);
// Linearly interpolate the time taking into account the next entry.
long previousByte = previousTocPosition == 0 ? 0 : tableOfContents[previousTocPosition - 1];
long nextByte = previousTocPosition == 99 ? 256 : tableOfContents[previousTocPosition];
long nextTime = getTimeUsForTocPosition(previousTocPosition + 1);
long timeOffset = nextByte == previousByte ? 0 : (long) ((nextTime - previousTime)
* (offsetByte - previousByte) / (nextByte - previousByte));
return previousTime + timeOffset;
}
示例3: getIndexOfEarlierOrEqualSynchronizationSample
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
/**
* Returns the sample index of the closest synchronization sample at or before the given
* timestamp, if one is available.
*
* @param timeUs Timestamp adjacent to which to find a synchronization sample.
* @return Index of the synchronization sample, or {@link #NO_SAMPLE} if none.
*/
public int getIndexOfEarlierOrEqualSynchronizationSample(long timeUs) {
int startIndex = Util.binarySearchFloor(timestampsUs, timeUs, true, false);
for (int i = startIndex; i >= 0; i--) {
if (timestampsUs[i] <= timeUs && (flags[i] & C.SAMPLE_FLAG_SYNC) != 0) {
return i;
}
}
return NO_SAMPLE;
}
示例4: getCues
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
@Override
public List<Cue> getCues(long timeUs) {
int index = Util.binarySearchFloor(cueTimesUs, timeUs, true, false);
if (index == -1 || index % 2 == 1) {
// timeUs is earlier than the start of the first cue, or corresponds to a gap between cues.
return Collections.<Cue>emptyList();
} else {
return Collections.singletonList(cues[index / 2]);
}
}
示例5: getIndexOfEarlierOrEqualSynchronizationSample
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
/**
* Returns the sample index of the closest synchronization sample at or before the given
* timestamp, if one is available.
*
* @param timeUs Timestamp adjacent to which to find a synchronization sample.
* @return Index of the synchronization sample, or {@link #NO_SAMPLE} if none.
*/
public int getIndexOfEarlierOrEqualSynchronizationSample(long timeUs) {
// Video frame timestamps may not be sorted, so the behavior of this call can be undefined.
// Frames are not reordered past synchronization samples so this works in practice.
int startIndex = Util.binarySearchFloor(timestampsUs, timeUs, true, false);
for (int i = startIndex; i >= 0; i--) {
if ((flags[i] & C.SAMPLE_FLAG_SYNC) != 0) {
return i;
}
}
return NO_SAMPLE;
}
示例6: getCues
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
@Override
public List<Cue> getCues(long timeUs) {
int index = Util.binarySearchFloor(cueTimesUs, timeUs, true, false);
if (index == -1 || cues[index] == null) {
// timeUs is earlier than the start of the first cue, or we have an empty cue.
return Collections.<Cue>emptyList();
} else {
return Collections.singletonList(cues[index]);
}
}
示例7: getPosition
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
@Override
public long getPosition(long timeUs) {
int index = Util.binarySearchFloor(timesUs, timeUs, false, false);
return basePosition + (index == -1 ? 0L : positions[index]);
}
示例8: getTimeUs
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
@Override
public long getTimeUs(long position) {
return timesUs[Util.binarySearchFloor(positions, position, true, true)];
}
示例9: getPosition
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
@Override
public long getPosition(long timeUs) {
return positions[Util.binarySearchFloor(timesUs, timeUs, true, true)];
}
示例10: getChunkIndex
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
/**
* Obtains the index of the chunk corresponding to a given time.
*
* @param timeUs The time, in microseconds.
* @return The index of the corresponding chunk.
*/
public int getChunkIndex(long timeUs) {
return Util.binarySearchFloor(timesUs, timeUs, true, true);
}
示例11: getChunkIndex
import com.google.android.exoplayer.util.Util; //导入方法依赖的package包/类
/**
* Gets the index of the chunk that contains the specified time.
*
* @param timeUs The time in microseconds.
* @return The index of the corresponding chunk.
*/
public int getChunkIndex(long timeUs) {
return Util.binarySearchFloor(chunkStartTimesUs, timeUs, true, true);
}