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


C++ TimeRanges::length方法代码示例

本文整理汇总了C++中TimeRanges::length方法的典型用法代码示例。如果您正苦于以下问题:C++ TimeRanges::length方法的具体用法?C++ TimeRanges::length怎么用?C++ TimeRanges::length使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在TimeRanges的用法示例。


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

示例1: seekable

TimeRanges* MediaSource::seekable() const
{
    // Implements MediaSource algorithm for HTMLMediaElement.seekable.
    // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#htmlmediaelement-extensions

    double sourceDuration = duration();
    // If duration equals NaN: Return an empty TimeRanges object.
    if (std::isnan(sourceDuration))
        return TimeRanges::create();

    // If duration equals positive Infinity:
    if (sourceDuration == std::numeric_limits<double>::infinity()) {
        TimeRanges* buffered = m_attachedElement->buffered();

        // 1. If the HTMLMediaElement.buffered attribute returns an empty TimeRanges object, then
        // return an empty TimeRanges object and abort these steps.
        if (buffered->length() == 0)
            return TimeRanges::create();

        // 2. Return a single range with a start time of 0 and an end time equal to the highest end
        // time reported by the HTMLMediaElement.buffered attribute.
        return TimeRanges::create(0, buffered->end(buffered->length() - 1, ASSERT_NO_EXCEPTION));
    }

    // 3. Otherwise: Return a single range with a start time of 0 and an end time equal to duration.
    return TimeRanges::create(0, sourceDuration);
}
开发者ID:astojilj,项目名称:chromium-crosswalk,代码行数:27,代码来源:MediaSource.cpp

示例2: buffered

TimeRanges* MediaSource::buffered() const {
  // Implements MediaSource algorithm for HTMLMediaElement.buffered.
  // https://dvcs.w3.org/hg/html-media/raw-file/default/media-source/media-source.html#htmlmediaelement-extensions
  HeapVector<Member<TimeRanges>> ranges(m_activeSourceBuffers->length());
  for (size_t i = 0; i < m_activeSourceBuffers->length(); ++i)
    ranges[i] = m_activeSourceBuffers->item(i)->buffered(ASSERT_NO_EXCEPTION);

  // 1. If activeSourceBuffers.length equals 0 then return an empty TimeRanges
  //    object and abort these steps.
  if (ranges.isEmpty())
    return TimeRanges::create();

  // 2. Let active ranges be the ranges returned by buffered for each
  //    SourceBuffer object in activeSourceBuffers.
  // 3. Let highest end time be the largest range end time in the active ranges.
  double highestEndTime = -1;
  for (size_t i = 0; i < ranges.size(); ++i) {
    unsigned length = ranges[i]->length();
    if (length)
      highestEndTime = std::max(
          highestEndTime, ranges[i]->end(length - 1, ASSERT_NO_EXCEPTION));
  }

  // Return an empty range if all ranges are empty.
  if (highestEndTime < 0)
    return TimeRanges::create();

  // 4. Let intersection ranges equal a TimeRange object containing a single
  //    range from 0 to highest end time.
  TimeRanges* intersectionRanges = TimeRanges::create(0, highestEndTime);

  // 5. For each SourceBuffer object in activeSourceBuffers run the following
  //    steps:
  bool ended = readyState() == endedKeyword();
  for (size_t i = 0; i < ranges.size(); ++i) {
    // 5.1 Let source ranges equal the ranges returned by the buffered attribute
    //     on the current SourceBuffer.
    TimeRanges* sourceRanges = ranges[i].get();

    // 5.2 If readyState is "ended", then set the end time on the last range in
    //     source ranges to highest end time.
    if (ended && sourceRanges->length())
      sourceRanges->add(
          sourceRanges->start(sourceRanges->length() - 1, ASSERT_NO_EXCEPTION),
          highestEndTime);

    // 5.3 Let new intersection ranges equal the the intersection between the
    //     intersection ranges and the source ranges.
    // 5.4 Replace the ranges in intersection ranges with the new intersection
    //     ranges.
    intersectionRanges->intersectWith(sourceRanges);
  }

  return intersectionRanges;
}
开发者ID:ollie314,项目名称:chromium,代码行数:55,代码来源:MediaSource.cpp

示例3: seekable

TimeRanges* MediaSource::seekable() const {
  // Implements MediaSource algorithm for HTMLMediaElement.seekable.
  // http://w3c.github.io/media-source/#htmlmediaelement-extensions

  double sourceDuration = duration();
  // If duration equals NaN: Return an empty TimeRanges object.
  if (std::isnan(sourceDuration))
    return TimeRanges::create();

  // If duration equals positive Infinity:
  if (sourceDuration == std::numeric_limits<double>::infinity()) {
    TimeRanges* buffered = m_attachedElement->buffered();

    // 1. If live seekable range is not empty:
    if (m_liveSeekableRange->length() != 0) {
      // 1.1. Let union ranges be the union of live seekable range and the
      //      HTMLMediaElement.buffered attribute.
      // 1.2. Return a single range with a start time equal to the
      //      earliest start time in union ranges and an end time equal to
      //      the highest end time in union ranges and abort these steps.
      if (buffered->length() == 0) {
        return TimeRanges::create(
            m_liveSeekableRange->start(0, ASSERT_NO_EXCEPTION),
            m_liveSeekableRange->end(0, ASSERT_NO_EXCEPTION));
      }

      return TimeRanges::create(
          std::min(m_liveSeekableRange->start(0, ASSERT_NO_EXCEPTION),
                   buffered->start(0, ASSERT_NO_EXCEPTION)),
          std::max(m_liveSeekableRange->end(0, ASSERT_NO_EXCEPTION),
                   buffered->end(buffered->length() - 1, ASSERT_NO_EXCEPTION)));
    }
    // 2. If the HTMLMediaElement.buffered attribute returns an empty TimeRanges
    //    object, then return an empty TimeRanges object and abort these steps.
    if (buffered->length() == 0)
      return TimeRanges::create();

    // 3. Return a single range with a start time of 0 and an end time equal to
    //    the highest end time reported by the HTMLMediaElement.buffered
    //    attribute.
    return TimeRanges::create(
        0, buffered->end(buffered->length() - 1, ASSERT_NO_EXCEPTION));
  }

  // 3. Otherwise: Return a single range with a start time of 0 and an end time
  //    equal to duration.
  return TimeRanges::create(0, sourceDuration);
}
开发者ID:ollie314,项目名称:chromium,代码行数:48,代码来源:MediaSource.cpp

示例4: ToString

static std::string ToString(const TimeRanges& ranges)
{
    std::stringstream ss;
    ss << "{";
    for (unsigned i = 0; i < ranges.length(); ++i)
        ss << " [" << ranges.start(i, IGNORE_EXCEPTION) << "," << ranges.end(i, IGNORE_EXCEPTION) << ")";
    ss << " }";

    return ss.str();
}
开发者ID:Happy-Ferret,项目名称:webkit.js,代码行数:10,代码来源:TimeRanges.cpp

示例5: ToString

static std::string ToString(const TimeRanges& ranges)
{
    std::stringstream ss;
    ss << "{";
    for (unsigned i = 0; i < ranges.length(); ++i)
        ss << " [" << ranges.start(i).releaseReturnValue() << "," << ranges.end(i).releaseReturnValue() << ")";
    ss << " }";

    return ss.str();
}
开发者ID:eocanha,项目名称:webkit,代码行数:10,代码来源:TimeRanges.cpp

示例6: paintMediaSliderInternal

void MediaControlsPainter::paintMediaSliderInternal(const LayoutObject& object, const PaintInfo& paintInfo, const IntRect& rect)
{
    const bool useNewUi = RuntimeEnabledFeatures::newMediaPlaybackUiEnabled();
    const HTMLMediaElement* mediaElement = toParentMediaElement(object);
    if (!mediaElement)
        return;

    const ComputedStyle& style = object.styleRef();
    GraphicsContext* context = paintInfo.context;

    // Paint the slider bar in the "no data buffered" state.
    Color sliderBackgroundColor;
    if (!useNewUi)
        sliderBackgroundColor = Color(11, 11, 11);
    else
        sliderBackgroundColor = Color(0xda, 0xda, 0xda);

    paintRoundedSliderBackground(rect, style, context, sliderBackgroundColor);

    // Draw the buffered range. Since the element may have multiple buffered ranges and it'd be
    // distracting/'busy' to show all of them, show only the buffered range containing the current play head.
    TimeRanges* bufferedTimeRanges = mediaElement->buffered();
    float duration = mediaElement->duration();
    float currentTime = mediaElement->currentTime();
    if (std::isnan(duration) || std::isinf(duration) || !duration || std::isnan(currentTime))
        return;

    for (unsigned i = 0; i < bufferedTimeRanges->length(); ++i) {
        float start = bufferedTimeRanges->start(i, ASSERT_NO_EXCEPTION);
        float end = bufferedTimeRanges->end(i, ASSERT_NO_EXCEPTION);
        // The delta is there to avoid corner cases when buffered
        // ranges is out of sync with current time because of
        // asynchronous media pipeline and current time caching in
        // HTMLMediaElement.
        // This is related to https://www.w3.org/Bugs/Public/show_bug.cgi?id=28125
        // FIXME: Remove this workaround when WebMediaPlayer
        // has an asynchronous pause interface.
        if (std::isnan(start) || std::isnan(end)
            || start > currentTime + kCurrentTimeBufferedDelta || end < currentTime)
            continue;
        int startPosition = int(start * rect.width() / duration);
        int currentPosition = int(currentTime * rect.width() / duration);
        int endPosition = int(end * rect.width() / duration);

        if (!useNewUi) {
            // Add half the thumb width proportionally adjusted to the current painting position.
            int thumbCenter = mediaSliderThumbWidth / 2;
            int addWidth = thumbCenter * (1.0 - 2.0 * currentPosition / rect.width());
            currentPosition += addWidth;
        }

        // Draw highlight before current time.
        Color startColor;
        Color endColor;
        if (!useNewUi) {
            startColor = Color(195, 195, 195); // white-ish.
            endColor = Color(217, 217, 217);
        } else {
            startColor = endColor = Color(0x42, 0x85, 0xf4); // blue.
        }

        if (currentPosition > startPosition)
            paintSliderRangeHighlight(rect, style, context, startPosition, currentPosition, startColor, endColor);

        // Draw grey-ish highlight after current time.
        if (!useNewUi) {
            startColor = Color(60, 60, 60);
            endColor = Color(76, 76, 76);
        } else {
            startColor = endColor = Color(0x9f, 0x9f, 0x9f); // light grey.
        }

        if (endPosition > currentPosition)
            paintSliderRangeHighlight(rect, style, context, currentPosition, endPosition, startColor, endColor);

        return;
    }
}
开发者ID:azureplus,项目名称:chromium,代码行数:78,代码来源:MediaControlsPainter.cpp


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