Home > Web Front-end > H5 Tutorial > Return the property buffered of TimeRanges object in html5

Return the property buffered of TimeRanges object in html5

黄舟
Release: 2017-11-08 09:38:12
Original
4185 people have browsed it

Example

Get the first buffer range (part) of video, in seconds:

myVid=document.getElementById("video1");
alert("Start: " + myVid.buffered.start(0)
+ " End: " + myVid.buffered.end(0));
Copy after login

Definition and usage

buffered PropertiesReturn TimeRanges Object.

The TimeRanges object represents the user's audio and video buffering range.

The buffering range refers to the time range of buffered audio and video. If the user skips playback in audio and video, he will get multiple buffer ranges.

Browser support

All major browsers support the buffered attribute.

Note: This attribute is not supported in Internet Explorer 8 or earlier browsers.

Syntax

audio|video.buffered
Copy after login
ValueDescription
TimeRanges Object

represents the buffered part of audio and video.

TimeRanges Object properties:

  • length - Get the number of buffered ranges in audio and video

  • start(index) - Get the start position of a buffered range

  • end(index) - Get the end position of a buffered range

Comments: First The lower table of buffer ranges is 0.

Example 1: buffered in audio

Audio’s cache has only one segment, the starting position is 0, and the ending position is timeRange.end (0)

<audio id="myAudio"></audio>
<script>
    var myAudio = document.getElementById(&#39;myAudio&#39;);
    myAudio.preload = true;
    myAudio.autoplay = true;
    myAudio.src = &#39;../content/audio/海阔天空.mp3&#39;;
    myAudio.onplay = function () {
        console.info("开始播放");
    }
    myAudio.oncanplay = function () {
        console.info(&#39;进入可以播放状态&#39;);
        console.info(&#39;总长度:&#39; + myAudio.duration);
    }
    //加载状态监听
    myAudio.ontimeupdate = function (e) {
        /*
        * Audio的缓存只有一个分段,开始位置为0,结束位置为timeRange.end(0)
        */
        //console.info(myAudio.buffered);
        //console.info(myAudio.buffered.length);
        // console.info(&#39;start:&#39;+myAudio.buffered.start(0)+&#39;,end:&#39;+myAudio.buffered.end(0));
        var timeRange = myAudio.buffered;
        console.info(timeRange);
        console.info(&#39;start:&#39; + timeRange.start(0) + &#39;,end:&#39; + timeRange.end(0));
    }
</script>
Copy after login


The above is the detailed content of Return the property buffered of TimeRanges object in html5. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template