com.google.android.exoplayer2.util.Util类的使用及代码示例

x33g5p2x  于2022-02-01 转载在 其他  
字(8.3k)|赞(0)|评价(0)|浏览(304)

本文整理了Java中com.google.android.exoplayer2.util.Util类的一些代码示例,展示了Util类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Util类的具体详情如下:
包路径:com.google.android.exoplayer2.util.Util
类名称:Util

Util介绍

[英]Miscellaneous utility methods.
[中]各种实用方法。

代码示例

代码示例来源:origin: google/ExoPlayer

  1. public PlayerManager(Context context) {
  2. String adTag = context.getString(R.string.ad_tag_url);
  3. adsLoader = new ImaAdsLoader(context, Uri.parse(adTag));
  4. dataSourceFactory =
  5. new DefaultDataSourceFactory(
  6. context, Util.getUserAgent(context, context.getString(R.string.application_name)));
  7. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Makes a best guess to infer the type from a {@link Uri}.
  3. *
  4. * @param uri The {@link Uri}.
  5. * @param overrideExtension If not null, used to infer the type.
  6. * @return The content type.
  7. */
  8. @C.ContentType
  9. public static int inferContentType(Uri uri, String overrideExtension) {
  10. return TextUtils.isEmpty(overrideExtension)
  11. ? inferContentType(uri)
  12. : inferContentType("." + overrideExtension);
  13. }

代码示例来源:origin: google/ExoPlayer

  1. @Override
  2. public boolean equals(@Nullable Object obj) {
  3. if (this == obj) {
  4. return true;
  5. }
  6. if (obj == null || getClass() != obj.getClass()) {
  7. return false;
  8. }
  9. CommentFrame other = (CommentFrame) obj;
  10. return Util.areEqual(description, other.description) && Util.areEqual(language, other.language)
  11. && Util.areEqual(text, other.text);
  12. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Adjusts ClearKey request data obtained from the Android ClearKey CDM to be spec compliant.
  3. *
  4. * @param request The request data.
  5. * @return The adjusted request data.
  6. */
  7. public static byte[] adjustRequestData(byte[] request) {
  8. if (Util.SDK_INT >= 27) {
  9. return request;
  10. }
  11. // Prior to O-MR1 the ClearKey CDM encoded the values in the "kids" array using Base64 encoding
  12. // rather than Base64Url encoding. See [Internal: b/64388098]. We know the exact request format
  13. // from the platform's InitDataParser.cpp. Since there aren't any "+" or "/" symbols elsewhere
  14. // in the request, it's safe to fix the encoding by replacement through the whole request.
  15. String requestString = Util.fromUtf8Bytes(request);
  16. return Util.getUtf8Bytes(base64ToBase64Url(requestString));
  17. }

代码示例来源:origin: google/ExoPlayer

  1. private static void setSampleDuration(byte[] subripSampleData, long durationUs,
  2. String timecodeFormat, int endTimecodeOffset, long lastTimecodeValueScalingFactor,
  3. byte[] emptyTimecode) {
  4. byte[] timeCodeData;
  5. if (durationUs == C.TIME_UNSET) {
  6. timeCodeData = emptyTimecode;
  7. } else {
  8. int hours = (int) (durationUs / (3600 * C.MICROS_PER_SECOND));
  9. durationUs -= (hours * 3600 * C.MICROS_PER_SECOND);
  10. int minutes = (int) (durationUs / (60 * C.MICROS_PER_SECOND));
  11. durationUs -= (minutes * 60 * C.MICROS_PER_SECOND);
  12. int seconds = (int) (durationUs / C.MICROS_PER_SECOND);
  13. durationUs -= (seconds * C.MICROS_PER_SECOND);
  14. int lastValue = (int) (durationUs / lastTimecodeValueScalingFactor);
  15. timeCodeData = Util.getUtf8Bytes(String.format(Locale.US, timecodeFormat, hours, minutes,
  16. seconds, lastValue));
  17. }
  18. System.arraycopy(timeCodeData, 0, subripSampleData, endTimecodeOffset, emptyTimecode.length);
  19. }

代码示例来源:origin: google/ExoPlayer

  1. public WebvttCssStyle setFontFamily(String fontFamily) {
  2. this.fontFamily = Util.toLowerInvariant(fontFamily);
  3. return this;
  4. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Returns the index of the chunk that contains the specified time.
  3. *
  4. * @param timeUs The time in microseconds.
  5. * @return The index of the corresponding chunk.
  6. */
  7. public int getChunkIndex(long timeUs) {
  8. return Util.binarySearchFloor(chunkStartTimesUs, timeUs, true, true);
  9. }

代码示例来源:origin: google/ExoPlayer

  1. return new Point(3840, 2160);
  2. } else if (("NVIDIA".equals(Util.MANUFACTURER) && Util.MODEL.contains("SHIELD"))
  3. || ("philips".equals(Util.toLowerInvariant(Util.MANUFACTURER))
  4. && (Util.MODEL.startsWith("QM1")
  5. || Util.MODEL.equals("QV151E")
  6. String[] sysDisplaySizeParts = split(sysDisplaySize.trim(), "x");
  7. if (sysDisplaySizeParts.length == 2) {
  8. int width = Integer.parseInt(sysDisplaySizeParts[0]);
  9. getDisplaySizeV23(display, displaySize);
  10. } else if (Util.SDK_INT >= 17) {
  11. getDisplaySizeV17(display, displaySize);
  12. } else if (Util.SDK_INT >= 16) {
  13. getDisplaySizeV16(display, displaySize);
  14. } else {
  15. getDisplaySizeV9(display, displaySize);

代码示例来源:origin: google/ExoPlayer

  1. return null;
  2. codec = Util.toLowerInvariant(codec.trim());
  3. if (codec.startsWith("avc1") || codec.startsWith("avc3")) {
  4. return MimeTypes.VIDEO_H264;
  5. if (objectTypeString.length() >= 2) {
  6. try {
  7. String objectTypeHexString = Util.toUpperInvariant(objectTypeString.substring(0, 2));
  8. int objectTypeInt = Integer.parseInt(objectTypeHexString, 16);
  9. mimeType = getMimeTypeFromMp4ObjectType(objectTypeInt);

代码示例来源:origin: google/ExoPlayer

  1. private static void assertParseStringToLong(
  2. long expected, ParsingLoadable.Parser<Long> parser, String data) throws IOException {
  3. long actual = parser.parse(null, new ByteArrayInputStream(Util.getUtf8Bytes(data)));
  4. assertThat(actual).isEqualTo(expected);
  5. }
  6. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Parses the number of channels from the value attribute of an AudioElementConfiguration with
  3. * schemeIdUri "tag:dolby.com,2014:dash:audio_channel_configuration:2011", as defined by table E.5
  4. * in ETSI TS 102 366.
  5. *
  6. * @param xpp The parser from which to read.
  7. * @return The parsed number of channels, or {@link Format#NO_VALUE} if the channel count could
  8. * not be parsed.
  9. */
  10. protected static int parseDolbyChannelConfiguration(XmlPullParser xpp) {
  11. String value = Util.toLowerInvariant(xpp.getAttributeValue(null, "value"));
  12. if (value == null) {
  13. return Format.NO_VALUE;
  14. }
  15. switch (value) {
  16. case "4000":
  17. return 1;
  18. case "a000":
  19. return 2;
  20. case "f801":
  21. return 6;
  22. case "fa01":
  23. return 8;
  24. default:
  25. return Format.NO_VALUE;
  26. }
  27. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Obtains the index of the chunk corresponding to a given time.
  3. *
  4. * @param timeUs The time, in microseconds.
  5. * @return The index of the corresponding chunk.
  6. */
  7. public int getChunkIndex(long timeUs) {
  8. return Util.binarySearchFloor(timesUs, timeUs, true, true);
  9. }

代码示例来源:origin: CarGuo/GSYVideoPlayer

  1. private DataSource.Factory getHttpDataSourceFactory(Context context, boolean preview) {
  2. DefaultHttpDataSourceFactory dataSourceFactory = new DefaultHttpDataSourceFactory(Util.getUserAgent(context,
  3. TAG), preview ? null : new DefaultBandwidthMeter());
  4. if (mMapHeadData != null && mMapHeadData.size() > 0) {
  5. for (Map.Entry<String, String> header : mMapHeadData.entrySet()) {
  6. dataSourceFactory.getDefaultRequestProperties().set(header.getKey(), header.getValue());
  7. }
  8. }
  9. return dataSourceFactory;
  10. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Makes a best guess to infer the type from a {@link Uri}.
  3. *
  4. * @param uri The {@link Uri}.
  5. * @return The content type.
  6. */
  7. @C.ContentType
  8. public static int inferContentType(Uri uri) {
  9. String path = uri.getPath();
  10. return path == null ? C.TYPE_OTHER : inferContentType(path);
  11. }

代码示例来源:origin: google/ExoPlayer

  1. @Override
  2. public boolean equals(@Nullable Object obj) {
  3. if (!(obj instanceof SchemeData)) {
  4. return false;
  5. }
  6. if (obj == this) {
  7. return true;
  8. }
  9. SchemeData other = (SchemeData) obj;
  10. return Util.areEqual(licenseServerUrl, other.licenseServerUrl)
  11. && Util.areEqual(mimeType, other.mimeType)
  12. && Util.areEqual(uuid, other.uuid)
  13. && Arrays.equals(data, other.data);
  14. }

代码示例来源:origin: google/ExoPlayer

  1. @Config(sdk = 26)
  2. @Test
  3. public void testAdjustRequestDataV26() {
  4. // We expect "+" and "/" to be replaced with "-" and "_" respectively, for "kids".
  5. byte[] expected =
  6. Util.getUtf8Bytes(
  7. "{"
  8. + "\"kids\":["
  9. + "\"abc-def_\","
  10. + "\"ab-cde_f\""
  11. + "],"
  12. + "\"type\":\"temporary\""
  13. + "}");
  14. assertThat(ClearKeyUtil.adjustRequestData(KEY_REQUEST)).isEqualTo(expected);
  15. }

代码示例来源:origin: google/ExoPlayer

  1. /**
  2. * Derives a DRM {@link UUID} from {@code drmScheme}.
  3. *
  4. * @param drmScheme A UUID string, or {@code "widevine"}, {@code "playready"} or {@code
  5. * "clearkey"}.
  6. * @return The derived {@link UUID}, or {@code null} if one could not be derived.
  7. */
  8. public static @Nullable UUID getDrmUuid(String drmScheme) {
  9. switch (Util.toLowerInvariant(drmScheme)) {
  10. case "widevine":
  11. return C.WIDEVINE_UUID;
  12. case "playready":
  13. return C.PLAYREADY_UUID;
  14. case "clearkey":
  15. return C.CLEARKEY_UUID;
  16. default:
  17. try {
  18. return UUID.fromString(drmScheme);
  19. } catch (RuntimeException e) {
  20. return null;
  21. }
  22. }
  23. }

代码示例来源:origin: google/ExoPlayer

  1. @Override
  2. protected int getChildIndexByPeriodIndex(int periodIndex) {
  3. return Util.binarySearchFloor(firstPeriodInChildIndices, periodIndex + 1, false, false);
  4. }

代码示例来源:origin: lipangit/JiaoZiVideoPlayer

  1. Util.getUserAgent(context, context.getResources().getString(R.string.app_name)));

代码示例来源:origin: CarGuo/GSYVideoPlayer

  1. @C.ContentType
  2. public static int inferContentType(Uri uri, @Nullable String overrideExtension) {
  3. return Util.inferContentType(uri, overrideExtension);
  4. }

相关文章