Home >Web Front-end >H5 Tutorial >Return the property buffered of TimeRanges object in html5
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));
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
Value | Description |
TimeRanges Object |
represents the buffered part of audio and video. TimeRanges Object properties:
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('myAudio'); myAudio.preload = true; myAudio.autoplay = true; myAudio.src = '../content/audio/海阔天空.mp3'; myAudio.onplay = function () { console.info("开始播放"); } myAudio.oncanplay = function () { console.info('进入可以播放状态'); console.info('总长度:' + myAudio.duration); } //加载状态监听 myAudio.ontimeupdate = function (e) { /* * Audio的缓存只有一个分段,开始位置为0,结束位置为timeRange.end(0) */ //console.info(myAudio.buffered); //console.info(myAudio.buffered.length); // console.info('start:'+myAudio.buffered.start(0)+',end:'+myAudio.buffered.end(0)); var timeRange = myAudio.buffered; console.info(timeRange); console.info('start:' + timeRange.start(0) + ',end:' + timeRange.end(0)); } </script>
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!