当前位置: 首页>>代码示例>>Java>>正文


Java TrackGroup.getFormat方法代码示例

本文整理汇总了Java中com.google.android.exoplayer2.source.TrackGroup.getFormat方法的典型用法代码示例。如果您正苦于以下问题:Java TrackGroup.getFormat方法的具体用法?Java TrackGroup.getFormat怎么用?Java TrackGroup.getFormat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.google.android.exoplayer2.source.TrackGroup的用法示例。


在下文中一共展示了TrackGroup.getFormat方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: BaseTrackSelection

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
/**
 * @param group The {@link TrackGroup}. Must not be null.
 * @param tracks The indices of the selected tracks within the {@link TrackGroup}. Must not be
 *     null or empty. May be in any order.
 */
public BaseTrackSelection(TrackGroup group, int... tracks) {
  Assertions.checkState(tracks.length > 0);
  this.group = Assertions.checkNotNull(group);
  this.length = tracks.length;
  // Set the formats, sorted in order of decreasing bandwidth.
  formats = new Format[length];
  for (int i = 0; i < tracks.length; i++) {
    formats[i] = group.getFormat(tracks[i]);
  }
  Arrays.sort(formats, new DecreasingBandwidthComparator());
  // Set the format indices in the same order.
  this.tracks = new int[length];
  for (int i = 0; i < length; i++) {
    this.tracks[i] = group.indexOf(formats[i]);
  }
  blacklistUntilTimes = new long[length];
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:23,代码来源:BaseTrackSelection.java

示例2: getSubtitleTracks

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
public List<PlayerSubtitleTrack> getSubtitleTracks(RendererTypeRequester rendererTypeRequester) {
    TrackGroupArray trackGroups = trackSelector.trackGroups(TEXT, rendererTypeRequester);

    List<PlayerSubtitleTrack> subtitleTracks = new ArrayList<>();

    for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
        TrackGroup trackGroup = trackGroups.get(groupIndex);

        for (int formatIndex = 0; formatIndex < trackGroup.length; formatIndex++) {
            Format format = trackGroup.getFormat(formatIndex);
            PlayerSubtitleTrack playerSubtitleTrack = new PlayerSubtitleTrack(
                    groupIndex,
                    formatIndex,
                    format.id,
                    format.language,
                    format.sampleMimeType,
                    format.channelCount,
                    format.bitrate
            );
            subtitleTracks.add(playerSubtitleTrack);
        }
    }

    return subtitleTracks;
}
 
开发者ID:novoda,项目名称:no-player,代码行数:26,代码来源:ExoPlayerSubtitleTrackSelector.java

示例3: selectOtherTrack

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
protected TrackSelection selectOtherTrack(int trackType, TrackGroupArray groups,
    int[][] formatSupport) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex])) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore = isDefault ? 2 : 1;
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:25,代码来源:DefaultTrackSelector.java

示例4: getAdaptiveVideoTracksForGroup

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
private static int[] getAdaptiveVideoTracksForGroup(TrackGroup group, int[] formatSupport,
    boolean allowMixedMimeTypes, int requiredAdaptiveSupport, int maxVideoWidth,
    int maxVideoHeight, int maxVideoBitrate, int viewportWidth, int viewportHeight,
    boolean orientationMayChange) {
  if (group.length < 2) {
    return NO_TRACKS;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, orientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      int trackIndex = selectedTrackIndices.get(i);
      String sampleMimeType = group.getFormat(trackIndex).sampleMimeType;
      if (seenMimeTypes.add(sampleMimeType)) {
        int countForMimeType = getAdaptiveVideoTrackCountForMimeType(group, formatSupport,
            requiredAdaptiveSupport, sampleMimeType, maxVideoWidth, maxVideoHeight,
            maxVideoBitrate, selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

  // Filter by the selected mime type.
  filterAdaptiveVideoTrackCountForMimeType(group, formatSupport, requiredAdaptiveSupport,
      selectedMimeType, maxVideoWidth, maxVideoHeight, maxVideoBitrate, selectedTrackIndices);

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:41,代码来源:DefaultTrackSelector.java

示例5: selectAudioTrack

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport,
    String preferredAudioLanguage, boolean exceedRendererCapabilitiesIfNecessary,
    boolean allowMixedMimeAdaptiveness, TrackSelection.Factory adaptiveTrackSelectionFactory) {
  int selectedGroupIndex = C.INDEX_UNSET;
  int selectedTrackIndex = C.INDEX_UNSET;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        int trackScore = getAudioTrackScore(trackFormatSupport[trackIndex],
            preferredAudioLanguage, format);
        if (trackScore > selectedTrackScore) {
          selectedGroupIndex = groupIndex;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }

  if (selectedGroupIndex == C.INDEX_UNSET) {
    return null;
  }

  TrackGroup selectedGroup = groups.get(selectedGroupIndex);
  if (adaptiveTrackSelectionFactory != null) {
    // If the group of the track with the highest score allows it, try to enable adaptation.
    int[] adaptiveTracks = getAdaptiveAudioTracks(selectedGroup,
        formatSupport[selectedGroupIndex], allowMixedMimeAdaptiveness);
    if (adaptiveTracks.length > 0) {
      return adaptiveTrackSelectionFactory.createTrackSelection(selectedGroup,
          adaptiveTracks);
    }
  }
  return new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:40,代码来源:DefaultTrackSelector.java

示例6: getAdaptiveAudioTracks

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
private static int[] getAdaptiveAudioTracks(TrackGroup group, int[] formatSupport,
    boolean allowMixedMimeTypes) {
  int selectedConfigurationTrackCount = 0;
  AudioConfigurationTuple selectedConfiguration = null;
  HashSet<AudioConfigurationTuple> seenConfigurationTuples = new HashSet<>();
  for (int i = 0; i < group.length; i++) {
    Format format = group.getFormat(i);
    AudioConfigurationTuple configuration = new AudioConfigurationTuple(
        format.channelCount, format.sampleRate,
        allowMixedMimeTypes ? null : format.sampleMimeType);
    if (seenConfigurationTuples.add(configuration)) {
      int configurationCount = getAdaptiveAudioTrackCount(group, formatSupport, configuration);
      if (configurationCount > selectedConfigurationTrackCount) {
        selectedConfiguration = configuration;
        selectedConfigurationTrackCount = configurationCount;
      }
    }
  }

  if (selectedConfigurationTrackCount > 1) {
    int[] adaptiveIndices = new int[selectedConfigurationTrackCount];
    int index = 0;
    for (int i = 0; i < group.length; i++) {
      if (isSupportedAdaptiveAudioTrack(group.getFormat(i), formatSupport[i],
          selectedConfiguration)) {
        adaptiveIndices[index++] = i;
      }
    }
    return adaptiveIndices;
  }
  return NO_TRACKS;
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:33,代码来源:DefaultTrackSelector.java

示例7: selectOtherTrack

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
protected TrackSelection selectOtherTrack(int trackType, TrackGroupArray groups,
    int[][] formatSupport, boolean exceedRendererCapabilitiesIfNecessary) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore = isDefault ? 2 : 1;
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
 
开发者ID:sanjaysingh1990,项目名称:Exoplayer2Radio,代码行数:28,代码来源:DefaultTrackSelector.java

示例8: getAudioTracks

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
public AudioTracks getAudioTracks(RendererTypeRequester rendererTypeRequester) {
    TrackGroupArray trackGroups = trackSelector.trackGroups(AUDIO, rendererTypeRequester);

    List<PlayerAudioTrack> audioTracks = new ArrayList<>();

    for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
        if (trackSelector.supportsTrackSwitching(AUDIO, rendererTypeRequester, trackGroups, groupIndex)) {
            TrackGroup trackGroup = trackGroups.get(groupIndex);

            for (int formatIndex = 0; formatIndex < trackGroup.length; formatIndex++) {
                Format format = trackGroup.getFormat(formatIndex);

                PlayerAudioTrack playerAudioTrack = new PlayerAudioTrack(
                        groupIndex,
                        formatIndex,
                        format.id,
                        format.language,
                        format.sampleMimeType,
                        format.channelCount,
                        format.bitrate,
                        AudioTrackType.from(format.selectionFlags)
                );
                audioTracks.add(playerAudioTrack);
            }
        }
    }

    return AudioTracks.from(audioTracks);
}
 
开发者ID:novoda,项目名称:no-player,代码行数:30,代码来源:ExoPlayerAudioTrackSelector.java

示例9: getVideoTracks

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
public List<PlayerVideoTrack> getVideoTracks(RendererTypeRequester rendererTypeRequester, ContentType contentType) {
    TrackGroupArray trackGroups = trackSelector.trackGroups(VIDEO, rendererTypeRequester);

    List<PlayerVideoTrack> videoTracks = new ArrayList<>();

    for (int groupIndex = 0; groupIndex < trackGroups.length; groupIndex++) {
        TrackGroup trackGroup = trackGroups.get(groupIndex);

        for (int formatIndex = 0; formatIndex < trackGroup.length; formatIndex++) {
            Format format = trackGroup.getFormat(formatIndex);

            PlayerVideoTrack playerVideoTrack = new PlayerVideoTrack(
                    groupIndex,
                    formatIndex,
                    format.id,
                    contentType,
                    format.width,
                    format.height,
                    (int) format.frameRate,
                    format.bitrate
            );

            videoTracks.add(playerVideoTrack);
        }
    }

    return videoTracks;
}
 
开发者ID:novoda,项目名称:no-player,代码行数:29,代码来源:ExoPlayerVideoTrackSelector.java

示例10: getAdaptiveTracksForGroup

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
private static int[] getAdaptiveTracksForGroup(TrackGroup group, int[] formatSupport,
    boolean allowMixedMimeTypes, int requiredAdaptiveSupport, int maxVideoWidth,
    int maxVideoHeight, int maxVideoBitrate, int viewportWidth, int viewportHeight,
    boolean orientationMayChange) {
  if (group.length < 2) {
    return NO_TRACKS;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, orientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      int trackIndex = selectedTrackIndices.get(i);
      String sampleMimeType = group.getFormat(trackIndex).sampleMimeType;
      if (seenMimeTypes.add(sampleMimeType)) {
        int countForMimeType = getAdaptiveTrackCountForMimeType(group, formatSupport,
            requiredAdaptiveSupport, sampleMimeType, maxVideoWidth, maxVideoHeight,
            maxVideoBitrate, selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

  // Filter by the selected mime type.
  filterAdaptiveTrackCountForMimeType(group, formatSupport, requiredAdaptiveSupport,
      selectedMimeType, maxVideoWidth, maxVideoHeight, maxVideoBitrate, selectedTrackIndices);

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}
 
开发者ID:jcodeing,项目名称:K-Sonic,代码行数:41,代码来源:DefaultTrackSelector.java

示例11: selectAudioTrack

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport,
    String preferredAudioLanguage, boolean exceedRendererCapabilitiesIfNecessary) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex], exceedRendererCapabilitiesIfNecessary)) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore;
        if (formatHasLanguage(format, preferredAudioLanguage)) {
          if (isDefault) {
            trackScore = 4;
          } else {
            trackScore = 3;
          }
        } else if (isDefault) {
          trackScore = 2;
        } else {
          trackScore = 1;
        }
        if (isSupported(trackFormatSupport[trackIndex], false)) {
          trackScore += WITHIN_RENDERER_CAPABILITIES_BONUS;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
 
开发者ID:jcodeing,项目名称:K-Sonic,代码行数:39,代码来源:DefaultTrackSelector.java

示例12: getAdaptiveTracksForGroup

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
private static int[] getAdaptiveTracksForGroup(TrackGroup group, int[] formatSupport,
    boolean allowMixedMimeTypes, int requiredAdaptiveSupport, int maxVideoWidth,
    int maxVideoHeight, int viewportWidth, int viewportHeight, boolean orientationMayChange) {
  if (group.length < 2) {
    return NO_TRACKS;
  }

  List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
      viewportHeight, orientationMayChange);
  if (selectedTrackIndices.size() < 2) {
    return NO_TRACKS;
  }

  String selectedMimeType = null;
  if (!allowMixedMimeTypes) {
    // Select the mime type for which we have the most adaptive tracks.
    HashSet<String> seenMimeTypes = new HashSet<>();
    int selectedMimeTypeTrackCount = 0;
    for (int i = 0; i < selectedTrackIndices.size(); i++) {
      int trackIndex = selectedTrackIndices.get(i);
      String sampleMimeType = group.getFormat(trackIndex).sampleMimeType;
      if (!seenMimeTypes.contains(sampleMimeType)) {
        seenMimeTypes.add(sampleMimeType);
        int countForMimeType = getAdaptiveTrackCountForMimeType(group, formatSupport,
            requiredAdaptiveSupport, sampleMimeType, maxVideoWidth, maxVideoHeight,
            selectedTrackIndices);
        if (countForMimeType > selectedMimeTypeTrackCount) {
          selectedMimeType = sampleMimeType;
          selectedMimeTypeTrackCount = countForMimeType;
        }
      }
    }
  }

  // Filter by the selected mime type.
  filterAdaptiveTrackCountForMimeType(group, formatSupport, requiredAdaptiveSupport,
      selectedMimeType, maxVideoWidth, maxVideoHeight, selectedTrackIndices);

  return selectedTrackIndices.size() < 2 ? NO_TRACKS : Util.toArray(selectedTrackIndices);
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:41,代码来源:DefaultTrackSelector.java

示例13: selectFixedVideoTrack

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
private static TrackSelection selectFixedVideoTrack(TrackGroupArray groups,
    int[][] formatSupport, int maxVideoWidth, int maxVideoHeight, int viewportWidth,
    int viewportHeight, boolean orientationMayChange, boolean exceedConstraintsIfNecessary) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedPixelCount = Format.NO_VALUE;
  boolean selectedIsWithinConstraints = false;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup group = groups.get(groupIndex);
    List<Integer> selectedTrackIndices = getViewportFilteredTrackIndices(group, viewportWidth,
        viewportHeight, orientationMayChange);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < group.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex])) {
        Format format = group.getFormat(trackIndex);
        boolean isWithinConstraints = selectedTrackIndices.contains(trackIndex)
            && (format.width == Format.NO_VALUE || format.width <= maxVideoWidth)
            && (format.height == Format.NO_VALUE || format.height <= maxVideoHeight);
        int pixelCount = format.getPixelCount();
        boolean selectTrack;
        if (selectedIsWithinConstraints) {
          selectTrack = isWithinConstraints
              && comparePixelCounts(pixelCount, selectedPixelCount) > 0;
        } else {
          selectTrack = isWithinConstraints || (exceedConstraintsIfNecessary
              && (selectedGroup == null
              || comparePixelCounts(pixelCount, selectedPixelCount) < 0));
        }
        if (selectTrack) {
          selectedGroup = group;
          selectedTrackIndex = trackIndex;
          selectedPixelCount = pixelCount;
          selectedIsWithinConstraints = isWithinConstraints;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:41,代码来源:DefaultTrackSelector.java

示例14: selectAudioTrack

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
protected TrackSelection selectAudioTrack(TrackGroupArray groups, int[][] formatSupport,
    String preferredAudioLanguage) {
  TrackGroup selectedGroup = null;
  int selectedTrackIndex = 0;
  int selectedTrackScore = 0;
  for (int groupIndex = 0; groupIndex < groups.length; groupIndex++) {
    TrackGroup trackGroup = groups.get(groupIndex);
    int[] trackFormatSupport = formatSupport[groupIndex];
    for (int trackIndex = 0; trackIndex < trackGroup.length; trackIndex++) {
      if (isSupported(trackFormatSupport[trackIndex])) {
        Format format = trackGroup.getFormat(trackIndex);
        boolean isDefault = (format.selectionFlags & C.SELECTION_FLAG_DEFAULT) != 0;
        int trackScore;
        if (formatHasLanguage(format, preferredAudioLanguage)) {
          if (isDefault) {
            trackScore = 4;
          } else {
            trackScore = 3;
          }
        } else if (isDefault) {
          trackScore = 2;
        } else {
          trackScore = 1;
        }
        if (trackScore > selectedTrackScore) {
          selectedGroup = trackGroup;
          selectedTrackIndex = trackIndex;
          selectedTrackScore = trackScore;
        }
      }
    }
  }
  return selectedGroup == null ? null
      : new FixedTrackSelection(selectedGroup, selectedTrackIndex);
}
 
开发者ID:zhanglibin123488,项目名称:videoPickPlayer,代码行数:36,代码来源:DefaultTrackSelector.java

示例15: for

import com.google.android.exoplayer2.source.TrackGroup; //导入方法依赖的package包/类
/**
 * Create {@link FakeAdaptiveDataSet} using a {@link TrackGroup} and meta data about the media.
 *
 * @param trackGroup The {@link TrackGroup} for which the data set is to be created.
 * @param mediaDurationUs The total duration of the fake data set in microseconds.
 * @param chunkDurationUs The chunk duration to use in microseconds.
 * @param bitratePercentStdDev  The standard deviation used to generate the chunk sizes centered
 *     around the average bitrate of the {@link Format}s in the {@link TrackGroup}. The standard
 *     deviation is given in percent (of the average size).
 * @param random A {@link Random} instance used to generate random chunk sizes.
 */
/* package */ FakeAdaptiveDataSet(TrackGroup trackGroup, long mediaDurationUs,
    long chunkDurationUs, double bitratePercentStdDev, Random random) {
  this.chunkDurationUs = chunkDurationUs;
  long lastChunkDurationUs = mediaDurationUs % chunkDurationUs;
  int fullChunks = (int) (mediaDurationUs / chunkDurationUs);
  this.lastChunkDurationUs = lastChunkDurationUs == 0 ? chunkDurationUs : lastChunkDurationUs;
  this.chunkCount = lastChunkDurationUs == 0 ? fullChunks : fullChunks + 1;
  double[] bitrateFactors = new double[chunkCount];
  for (int i = 0; i < chunkCount; i++) {
    bitrateFactors[i] = 1.0 + random.nextGaussian() * bitratePercentStdDev / 100.0;
  }
  for (int i = 0; i < trackGroup.length; i++) {
    String uri = getUri(i);
    Format format = trackGroup.getFormat(i);
    double avgChunkLength = format.bitrate * chunkDurationUs / (8 * C.MICROS_PER_SECOND);
    FakeData newData = this.newData(uri);
    for (int j = 0; j < fullChunks; j++) {
      newData.appendReadData((int) (avgChunkLength * bitrateFactors[j]));
    }
    if (lastChunkDurationUs > 0) {
      int lastChunkLength = (int) (format.bitrate * bitrateFactors[bitrateFactors.length - 1]
          * (mediaDurationUs % chunkDurationUs) / (8 * C.MICROS_PER_SECOND));
      newData.appendReadData(lastChunkLength);
    }
  }
}
 
开发者ID:y20k,项目名称:transistor,代码行数:38,代码来源:FakeAdaptiveDataSet.java


注:本文中的com.google.android.exoplayer2.source.TrackGroup.getFormat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。