當前位置: 首頁>>代碼示例>>Java>>正文


Java Util類代碼示例

本文整理匯總了Java中com.google.android.exoplayer2.util.Util的典型用法代碼示例。如果您正苦於以下問題:Java Util類的具體用法?Java Util怎麽用?Java Util使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


Util類屬於com.google.android.exoplayer2.util包,在下文中一共展示了Util類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: buildMediaSource

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
    int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension
            : uri.getLastPathSegment());
    switch (type) {
        case C.TYPE_SS:
            return new SsMediaSource(uri, buildDataSourceFactory(false),
                    new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
        case C.TYPE_DASH:
            return new DashMediaSource(uri, buildDataSourceFactory(false),
                    new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
        case C.TYPE_HLS:
            return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null);
        case C.TYPE_OTHER:
            return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
                    mainHandler, null);
        default: {
            throw new IllegalStateException("Unsupported type: " + type);
        }
    }
}
 
開發者ID:12d,項目名稱:react-native-videoplayer,代碼行數:21,代碼來源:ReactExoplayerView.java

示例2: open

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
@Override
public long open(DataSpec dataSpec) throws IOException {
    Assertions.checkState(dataSource == null);
    String scheme = dataSpec.uri.getScheme();
    if (Util.isLocalFileUri(dataSpec.uri)) {
        if (dataSpec.uri.getPath().startsWith("/android_asset/")) {
            dataSource = getAssetDataSource();
        } else {
            dataSource = getFileDataSource();
        }
    } else if (SCHEME_ASSET.equals(scheme)) {
        dataSource = getAssetDataSource();
    } else if (SCHEME_CONTENT.equals(scheme)) {
        dataSource = getContentDataSource();
    } else if (SCHEME_RTMP.equals(scheme)) {
        dataSource = getRtmpDataSource();
    } else {
        dataSource = baseDataSource;
    }
    // Open the source and return.
    return dataSource.open(dataSpec);
}
 
開發者ID:yangchaojiang,項目名稱:yjPlay,代碼行數:23,代碼來源:MyDefaultDataSource.java

示例3: buildMediaSource

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
	DataSource.Factory mediaDataSourceFactory = buildDataSourceFactory(true);
	int type = TextUtils.isEmpty(overrideExtension) ? Util.inferContentType(uri)
			: Util.inferContentType("." + overrideExtension);
	switch (type) {
		case C.TYPE_SS:
			return new SsMediaSource(uri, buildDataSourceFactory(false),
					new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
		case C.TYPE_DASH:
			return new DashMediaSource(uri, buildDataSourceFactory(false),
					new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, null);
		case C.TYPE_HLS:
			return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, null);
		case C.TYPE_OTHER:
			return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
					mainHandler, null);
		default: {
			throw new IllegalStateException("Unsupported type: " + type);
		}
	}
}
 
開發者ID:NiciDieNase,項目名稱:chaosflix,代碼行數:22,代碼來源:PlayerActivity.java

示例4: onInitializeAccessibilityNodeInfo

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
@TargetApi(21)
@Override
public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
    super.onInitializeAccessibilityNodeInfo(info);
    info.setClassName(com.google.android.exoplayer2.ui.DefaultTimeBar.class.getCanonicalName());
    info.setContentDescription(getProgressText());
    if (duration <= 0) {
        return;
    }
    if (Util.SDK_INT >= 21) {
        info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_FORWARD);
        info.addAction(AccessibilityNodeInfo.AccessibilityAction.ACTION_SCROLL_BACKWARD);
    } else if (Util.SDK_INT >= 16) {
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_FORWARD);
        info.addAction(AccessibilityNodeInfo.ACTION_SCROLL_BACKWARD);
    }
}
 
開發者ID:rubensousa,項目名稱:PreviewSeekBar,代碼行數:18,代碼來源:CustomTimeBar.java

示例5: drawPlayhead

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
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);
    }
}
 
開發者ID:rubensousa,項目名稱:PreviewSeekBar,代碼行數:23,代碼來源:CustomTimeBar.java

示例6: scrubIncrementally

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:rubensousa,項目名稱:PreviewSeekBar,代碼行數:25,代碼來源:CustomTimeBar.java

示例7: doInBackground

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
@Override
protected List<SampleGroup> doInBackground(String... uris) {
  List<SampleGroup> result = new ArrayList<>();
  Context context = getApplicationContext();
  String userAgent = Util.getUserAgent(context, "ExoPlayerDemo");
  DataSource dataSource = new DefaultDataSource(context, null, userAgent, false);
  for (String uri : uris) {
    DataSpec dataSpec = new DataSpec(Uri.parse(uri));
    InputStream inputStream = new DataSourceInputStream(dataSource, dataSpec);
    try {
      readSampleGroups(new JsonReader(new InputStreamReader(inputStream, "UTF-8")), result);
    } catch (Exception e) {
      Log.e(TAG, "Error loading sample list: " + uri, e);
      sawError = true;
    } finally {
      Util.closeQuietly(dataSource);
    }
  }
  return result;
}
 
開發者ID:ashwanijanghu,項目名稱:ExoPlayer-Offline,代碼行數:21,代碼來源:SampleChooserActivity.java

示例8: scrubIncrementally

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
/**
 * 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;
}
 
開發者ID:hongcwamazing,項目名稱:PreviewSeekBar-master,代碼行數:26,代碼來源:CustomTimeBar.java

示例9: buildMediaSource

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
private MediaSource buildMediaSource(Uri uri, String overrideExtension) {
    int type = Util.inferContentType(!TextUtils.isEmpty(overrideExtension) ? "." + overrideExtension
            : uri.getLastPathSegment());
    switch (type) {
        case C.TYPE_SS:
            return new SsMediaSource(uri, buildDataSourceFactory(false),
                    new DefaultSsChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
        case C.TYPE_DASH:
            return new DashMediaSource(uri, buildDataSourceFactory(false),
                    new DefaultDashChunkSource.Factory(mediaDataSourceFactory), mainHandler, eventLogger);
        case C.TYPE_HLS:
            return new HlsMediaSource(uri, mediaDataSourceFactory, mainHandler, eventLogger);
        case C.TYPE_OTHER:
            return new ExtractorMediaSource(uri, mediaDataSourceFactory, new DefaultExtractorsFactory(),
                    mainHandler, eventLogger);
        default: {
            throw new IllegalStateException("Unsupported type: " + type);
        }
    }
}
 
開發者ID:ashwanijanghu,項目名稱:ExoPlayer-Offline,代碼行數:21,代碼來源:PlayerActivity.java

示例10: load

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
@Override
public final void load() throws IOException, InterruptedException {
  try {
    dataSource.open(dataSpec);
    limit = 0;
    int bytesRead = 0;
    while (bytesRead != C.RESULT_END_OF_INPUT && !loadCanceled) {
      maybeExpandData();
      bytesRead = dataSource.read(data, limit, READ_GRANULARITY);
      if (bytesRead != -1) {
        limit += bytesRead;
      }
    }
    if (!loadCanceled) {
      consume(data, limit);
    }
  } finally {
    Util.closeQuietly(dataSource);
  }
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:21,代碼來源:DataChunk.java

示例11: getMaxVideoSizeInViewport

import com.google.android.exoplayer2.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);
  }
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:22,代碼來源:DefaultTrackSelector.java

示例12: initializePlayer

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
private void initializePlayer(Uri videoUri){
    if (mExoPlayer == null){
        TrackSelector trackSelector = new DefaultTrackSelector();
        LoadControl loadControl = new DefaultLoadControl();
        mExoPlayer = ExoPlayerFactory.newSimpleInstance(getContext(), trackSelector, loadControl);
        mExoPlayer.addListener(this);
        mExoPlayer.seekTo(currentPosition);
        mPlayerView.setPlayer(mExoPlayer);
        String userAgent = Util.getUserAgent(getContext(), "Tasty");
        MediaSource mediaSource = new ExtractorMediaSource(videoUri, new DefaultDataSourceFactory(
                getContext(), userAgent), new DefaultExtractorsFactory(), null, null);
        mExoPlayer.prepare(mediaSource);
        if (playWhenReady) mExoPlayer.setPlayWhenReady(true);
        else mExoPlayer.setPlayWhenReady(false);
    }
}
 
開發者ID:harrynp,項目名稱:BakingApp,代碼行數:17,代碼來源:StepDetailFragment.java

示例13: getTimeUs

import com.google.android.exoplayer2.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;
}
 
開發者ID:sanjaysingh1990,項目名稱:Exoplayer2Radio,代碼行數:19,代碼來源:XingSeeker.java

示例14: testWidevineOfflineLicense

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
public void testWidevineOfflineLicense() throws Exception {
  if (Util.SDK_INT < 22) {
    // Pass.
    return;
  }
  String streamName = "test_widevine_h264_fixed_offline";
  DashHostedTestEncParameters parameters = newDashHostedTestEncParameters(
      WIDEVINE_H264_MANIFEST_PREFIX, true, MimeTypes.VIDEO_H264);
  TestOfflineLicenseHelper helper = new TestOfflineLicenseHelper(parameters);
  try {
    byte[] keySetId = helper.downloadLicense();
    testDashPlayback(getActivity(), streamName, null, true, parameters,
        WIDEVINE_AAC_AUDIO_REPRESENTATION_ID, false, keySetId, WIDEVINE_H264_CDD_FIXED);
    helper.renewLicense();
  } finally {
    helper.releaseResources();
  }
}
 
開發者ID:ashwanijanghu,項目名稱:ExoPlayer-Offline,代碼行數:19,代碼來源:DashTest.java

示例15: testWidevineOfflineLicenseExpiresOnPause

import com.google.android.exoplayer2.util.Util; //導入依賴的package包/類
public void testWidevineOfflineLicenseExpiresOnPause() throws Exception {
  if (Util.SDK_INT < 22) {
    // Pass.
    return;
  }
  String streamName = "test_widevine_h264_fixed_offline";
  DashHostedTestEncParameters parameters = newDashHostedTestEncParameters(
      WIDEVINE_H264_MANIFEST_PREFIX, true, MimeTypes.VIDEO_H264);
  TestOfflineLicenseHelper helper = new TestOfflineLicenseHelper(parameters);
  try {
    byte[] keySetId = helper.downloadLicense();
    // During playback pause until the license expires then continue playback
    Pair<Long, Long> licenseDurationRemainingSec = helper.getLicenseDurationRemainingSec();
    long licenseDuration = licenseDurationRemainingSec.first;
    assertTrue("License duration should be less than 30 sec. "
        + "Server settings might have changed.", licenseDuration < 30);
    ActionSchedule schedule = new ActionSchedule.Builder(TAG)
        .delay(3000).pause().delay(licenseDuration * 1000 + 2000).play().build();
    // DefaultDrmSessionManager should renew the license and stream play fine
    testDashPlayback(getActivity(), streamName, schedule, true, parameters,
        WIDEVINE_AAC_AUDIO_REPRESENTATION_ID, false, keySetId, WIDEVINE_H264_CDD_FIXED);
  } finally {
    helper.releaseResources();
  }
}
 
開發者ID:ashwanijanghu,項目名稱:ExoPlayer-Offline,代碼行數:26,代碼來源:DashTest.java


注:本文中的com.google.android.exoplayer2.util.Util類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。