本文整理汇总了Java中com.google.android.exoplayer.util.Util类的典型用法代码示例。如果您正苦于以下问题:Java Util类的具体用法?Java Util怎么用?Java Util使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Util类属于com.google.android.exoplayer.util包,在下文中一共展示了Util类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getRendererBuilder
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
private VideoPlayer.RendererBuilder getRendererBuilder() {
String userAgent = Util.getUserAgent(getActivity(), "ExoVideoPlayer");
Uri contentUri = Uri.parse(mSelectedVideo.videoUrl);
int contentType = Util.inferContentType(contentUri.getLastPathSegment());
switch (contentType) {
case Util.TYPE_OTHER: {
return new ExtractorRendererBuilder(getActivity(), userAgent, contentUri);
}
case Util.TYPE_DASH: {
// Implement your own DRM callback here.
MediaDrmCallback drmCallback = new WidevineTestMediaDrmCallback(null, null);
return new DashRendererBuilder(getActivity(), userAgent, contentUri.toString(),
drmCallback);
}
case Util.TYPE_HLS: {
return new HlsRendererBuilder(getActivity(), userAgent, contentUri.toString());
}
default: {
throw new IllegalStateException("Unsupported type: " + contentType);
}
}
}
示例2: getRendererBuilder
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
private RendererBuilder getRendererBuilder() {
Uri contentUri = Uri.parse(mDataSource);
String userAgent = Util.getUserAgent(mAppContext, "IjkExoMediaPlayer");
int contentType = inferContentType(contentUri);
switch (contentType) {
case Util.TYPE_SS:
return new SmoothStreamingRendererBuilder(mAppContext, userAgent, contentUri.toString(),
new SmoothStreamingTestMediaDrmCallback());
/* case Util.TYPE_DASH:
return new DashRendererBuilder(mAppContext , userAgent, contentUri.toString(),
new WidevineTestMediaDrmCallback(contentId, provider));*/
case Util.TYPE_HLS:
return new HlsRendererBuilder(mAppContext, userAgent, contentUri.toString());
case Util.TYPE_OTHER:
default:
return new ExtractorRendererBuilder(mAppContext, userAgent, contentUri);
}
}
示例3: StreamElement
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
public StreamElement(String baseUri, String chunkTemplate, int type, String subType,
long timescale, String name, int qualityLevels, int maxWidth, int maxHeight,
int displayWidth, int displayHeight, String language, TrackElement[] tracks,
List<Long> chunkStartTimes, long lastChunkDuration) {
this.baseUri = baseUri;
this.chunkTemplate = chunkTemplate;
this.type = type;
this.subType = subType;
this.timescale = timescale;
this.name = name;
this.qualityLevels = qualityLevels;
this.maxWidth = maxWidth;
this.maxHeight = maxHeight;
this.displayWidth = displayWidth;
this.displayHeight = displayHeight;
this.language = language;
this.tracks = tracks;
this.chunkCount = chunkStartTimes.size();
this.chunkStartTimes = chunkStartTimes;
lastChunkDurationUs =
Util.scaleLargeTimestamp(lastChunkDuration, C.MICROS_PER_SECOND, timescale);
chunkStartTimesUs =
Util.scaleLargeTimestamps(chunkStartTimes, C.MICROS_PER_SECOND, timescale);
}
示例4: MediaCodecTrackRenderer
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
/**
* @param sources The upstream sources from which the renderer obtains samples.
* @param mediaCodecSelector A decoder selector.
* @param drmSessionManager For use with encrypted media. May be null if support for encrypted
* media is not required.
* @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
* For example a media file may start with a short clear region so as to allow playback to
* begin in parallel with key acquisition. This parameter specifies whether the renderer is
* permitted to play clear regions of encrypted media files before {@code drmSessionManager}
* has obtained the keys necessary to decrypt encrypted regions of the media.
* @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
* null if delivery of events is not required.
* @param eventListener A listener of events. May be null if delivery of events is not required.
*/
public MediaCodecTrackRenderer(SampleSource[] sources, MediaCodecSelector mediaCodecSelector,
DrmSessionManager drmSessionManager, boolean playClearSamplesWithoutKeys,
Handler eventHandler, EventListener eventListener) {
super(sources);
Assertions.checkState(Util.SDK_INT >= 16);
this.mediaCodecSelector = Assertions.checkNotNull(mediaCodecSelector);
this.drmSessionManager = drmSessionManager;
this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
this.eventHandler = eventHandler;
this.eventListener = eventListener;
deviceNeedsAutoFrcWorkaround = deviceNeedsAutoFrcWorkaround();
codecCounters = new CodecCounters();
sampleHolder = new SampleHolder(SampleHolder.BUFFER_REPLACEMENT_MODE_DISABLED);
formatHolder = new MediaFormatHolder();
decodeOnlyPresentationTimestamps = new ArrayList<>();
outputBufferInfo = new MediaCodec.BufferInfo();
codecReconfigurationState = RECONFIGURATION_STATE_NONE;
codecReinitializationState = REINITIALIZATION_STATE_NONE;
}
示例5: load
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
@SuppressWarnings("NonAtomicVolatileUpdate")
@Override
public void load() throws IOException, InterruptedException {
DataSpec loadDataSpec = Util.getRemainderDataSpec(dataSpec, bytesLoaded);
try {
// Create and open the input.
ExtractorInput input = new DefaultExtractorInput(dataSource,
loadDataSpec.absoluteStreamPosition, dataSource.open(loadDataSpec));
if (bytesLoaded == 0) {
// Set the target to ourselves.
extractorWrapper.init(this);
}
// Load and parse the initialization data.
try {
int result = Extractor.RESULT_CONTINUE;
while (result == Extractor.RESULT_CONTINUE && !loadCanceled) {
result = extractorWrapper.read(input);
}
} finally {
bytesLoaded = (int) (input.getPosition() - dataSpec.absoluteStreamPosition);
}
} finally {
dataSource.close();
}
}
示例6: getRendererBuilder
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
private RendererBuilder getRendererBuilder() {
String userAgent = Util.getUserAgent(getActivity(), "ExoPlayerDemo");
Uri uri = Uri.parse(mStreamUrl);
int contentType = inferContentType(uri, null);
switch (contentType) {
// case TYPE_SS:
// return new SmoothStreamingRendererBuilder(this, null, contentUri.toString(),
// new SmoothStreamingTestMediaDrmCallback());
// case TYPE_DASH:
// return new DashRendererBuilder(this, userAgent, contentUri.toString(),
// new WidevineTestMediaDrmCallback(contentId, provider));
case TYPE_HLS:
return new HlsRendererBuilder(getContext(), userAgent, mStreamUrl);
case TYPE_OTHER:
return new ExtractorRendererBuilder(getContext(), userAgent, uri);
default:
throw new IllegalStateException("Unsupported type: " + contentType);
}
}
示例7: getMaxVideoSizeInViewport
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
/**
* Given viewport dimensions and video dimensions, computes the maximum size of the video as it
* will be rendered to fit inside of the viewport.
*/
private static Point getMaxVideoSizeInViewport(boolean orientationMayChange, int viewportWidth,
int viewportHeight, int videoWidth, int videoHeight) {
if (orientationMayChange && (videoWidth > videoHeight) != (viewportWidth > viewportHeight)) {
// Rotation is allowed, and the video will be larger in the rotated viewport.
int tempViewportWidth = viewportWidth;
viewportWidth = viewportHeight;
viewportHeight = tempViewportWidth;
}
if (videoWidth * viewportHeight >= videoHeight * viewportWidth) {
// Horizontal letter-boxing along top and bottom.
return new Point(viewportWidth, Util.ceilDivide(viewportWidth * videoHeight, videoWidth));
} else {
// Vertical letter-boxing along edges.
return new Point(Util.ceilDivide(viewportHeight * videoWidth, videoHeight), viewportHeight);
}
}
示例8: MediaCodecTrackRenderer
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
/**
* @param source The upstream source from which the renderer obtains samples.
* @param drmSessionManager For use with encrypted media. May be null if support for encrypted
* media is not required.
* @param playClearSamplesWithoutKeys Encrypted media may contain clear (un-encrypted) regions.
* For example a media file may start with a short clear region so as to allow playback
* to
* begin in parallel with key acquisision. This parameter specifies whether the renderer
* is
* permitted to play clear regions of encrypted media files before
* {@code drmSessionManager}
* has obtained the keys necessary to decrypt encrypted regions of the media.
* @param eventHandler A handler to use when delivering events to {@code eventListener}. May be
* null if delivery of events is not required.
* @param eventListener A listener of events. May be null if delivery of events is not required.
*/
public MediaCodecTrackRenderer(SampleSource source, DrmSessionManager drmSessionManager,
boolean playClearSamplesWithoutKeys, Handler eventHandler, EventListener eventListener) {
Assertions.checkState(Util.SDK_INT >= 16);
this.source = source.register();
this.drmSessionManager = drmSessionManager;
this.playClearSamplesWithoutKeys = playClearSamplesWithoutKeys;
this.eventHandler = eventHandler;
this.eventListener = eventListener;
codecCounters = new CodecCounters();
sampleHolder = new SampleHolder(SampleHolder.BUFFER_REPLACEMENT_MODE_DISABLED);
formatHolder = new MediaFormatHolder();
decodeOnlyPresentationTimestamps = new ArrayList<>();
outputBufferInfo = new MediaCodec.BufferInfo();
codecReconfigurationState = RECONFIGURATION_STATE_NONE;
codecReinitializationState = REINITIALIZATION_STATE_NONE;
}
示例9: flushCodec
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
private void flushCodec() throws ExoPlaybackException {
codecHotswapTimeMs = -1;
inputIndex = -1;
outputIndex = -1;
waitingForFirstSyncFrame = true;
waitingForKeys = false;
decodeOnlyPresentationTimestamps.clear();
// Workaround for framework bugs.
// See [Internal: b/8347958], [Internal: b/8578467], [Internal: b/8543366].
if (Util.SDK_INT >= 18 && codecReinitializationState == REINITIALIZATION_STATE_NONE) {
codec.flush();
codecHasQueuedBuffers = false;
} else {
releaseCodec();
maybeInitCodec();
}
if (codecReconfigured && format != null) {
// Any reconfiguration data that we send shortly before the flush may be discarded. We
// avoid this issue by sending reconfiguration data following every flush.
codecReconfigurationState = RECONFIGURATION_STATE_WRITE_PENDING;
}
}
示例10: AudioTrack
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
public AudioTrack() {
releasingConditionVariable = new ConditionVariable(true);
if (Util.SDK_INT >= 18) {
try {
getLatencyMethod =
android.media.AudioTrack.class.getMethod("getLatency", (Class<?>[]) null);
} catch (NoSuchMethodException e) {
// There's no guarantee this method exists. Do nothing.
}
}
if (Util.SDK_INT >= 19) {
audioTrackUtil = new AudioTrackUtilV19();
} else {
audioTrackUtil = new AudioTrackUtil();
}
playheadOffsets = new long[MAX_PLAYHEAD_OFFSET_COUNT];
volume = 1.0f;
startMediaTimeState = START_NOT_SET;
}
示例11: getPlaybackHeadPosition
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
/**
* {@link android.media.AudioTrack#getPlaybackHeadPosition()} returns a value intended to be
* interpreted as an unsigned 32 bit integer, which also wraps around periodically. This method
* returns the playback head position as a long that will only wrap around if the value exceeds
* {@link Long#MAX_VALUE} (which in practice will never happen).
*
* @return {@link android.media.AudioTrack#getPlaybackHeadPosition()} of {@link #audioTrack}
* expressed as a long.
*/
public long getPlaybackHeadPosition() {
long rawPlaybackHeadPosition = 0xFFFFFFFFL & audioTrack.getPlaybackHeadPosition();
if (Util.SDK_INT <= 22 && isPassthrough) {
// Work around issues with passthrough/direct AudioTracks on platform API versions 21/22:
// - After resetting, the new AudioTrack's playback position continues to increase for a
// short time from the old AudioTrack's position, while in the PLAYSTATE_STOPPED state.
// - The playback head position jumps back to zero on paused passthrough/direct audio
// tracks. See [Internal: b/19187573].
if (audioTrack.getPlayState() == android.media.AudioTrack.PLAYSTATE_STOPPED) {
// Prevent detecting a wrapped position.
lastRawPlaybackHeadPosition = rawPlaybackHeadPosition;
} else if (audioTrack.getPlayState() == android.media.AudioTrack.PLAYSTATE_PAUSED
&& rawPlaybackHeadPosition == 0) {
passthroughWorkaroundPauseOffset = lastRawPlaybackHeadPosition;
}
rawPlaybackHeadPosition += passthroughWorkaroundPauseOffset;
}
if (lastRawPlaybackHeadPosition > rawPlaybackHeadPosition) {
// The value must have wrapped around.
rawPlaybackHeadWrapCount++;
}
lastRawPlaybackHeadPosition = rawPlaybackHeadPosition;
return rawPlaybackHeadPosition + (rawPlaybackHeadWrapCount << 32);
}
示例12: isCodecUsableDecoder
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
/**
* Returns whether the specified codec is usable for decoding on the current device.
*/
private static boolean isCodecUsableDecoder(MediaCodecInfo info, String name,
boolean secureDecodersExplicit) {
if (info.isEncoder() || !name.startsWith("OMX.")
|| (!secureDecodersExplicit && name.endsWith(".secure"))) {
return false;
}
// Work around an issue where creating a particular MP3 decoder on some devices on platform API
// version 16 crashes mediaserver.
if (Util.SDK_INT == 16
&& ("dlxu".equals(Util.DEVICE) // HTC Butterfly
|| "protou".equals(Util.DEVICE) // HTC Desire X
|| "C6602".equals(Util.DEVICE) || "C6603".equals(Util.DEVICE)) // Sony Xperia Z
&& name.equals("OMX.qcom.audio.decoder.mp3")) {
return false;
}
// Work around an issue where the VP8 decoder on Samsung Galaxy S4 Mini does not render video.
if (Util.SDK_INT <= 19 && Util.DEVICE != null && Util.DEVICE.startsWith("serrano")
&& "samsung".equals(Util.MANUFACTURER) && name.equals("OMX.SEC.vp8.dec")) {
return false;
}
return true;
}
示例13: close
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
@Override
public void close() throws HttpDataSourceException {
try {
if (inputStream != null) {
Util.maybeTerminateInputStream(connection, bytesRemaining());
try {
inputStream.close();
} catch (IOException e) {
throw new HttpDataSourceException(e, dataSpec);
}
}
} finally {
inputStream = null;
closeConnection();
if (opened) {
opened = false;
if (listener != null) {
listener.onTransferEnd();
}
}
}
}
示例14: closeCurrentOutputStream
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
private void closeCurrentOutputStream() throws IOException {
if (outputStream == null) {
return;
}
boolean success = false;
try {
outputStream.flush();
outputStream.getFD().sync();
success = true;
} finally {
Util.closeQuietly(outputStream);
if (success) {
cache.commitFile(file);
} else {
file.delete();
}
outputStream = null;
file = null;
}
}
示例15: executeKeyRequest
import com.google.android.exoplayer.util.Util; //导入依赖的package包/类
@Override
public byte[] executeKeyRequest(UUID uuid, KeyRequest request) throws Exception {
String url = request.getDefaultUrl();
if (TextUtils.isEmpty(url)) {
url = PLAYREADY_TEST_DEFAULT_URI;
}
return Util.executePost(url, request.getData(), KEY_REQUEST_PROPERTIES);
}