点击下载教程相关资源
play 可用于在有信号源的播放器上开始播放。例如:
var myPlayer = videojs('some-player-id'); myPlayer.src({type: 'video/mp4', src: 'http://www.example.com/path/to/video.mp4'}); myPlayer.ready(function() { myPlayer.play(); });
pause 可以用来暂停正在播放的播放器的播放。例如:
var myPlayer = videojs('some-player-id'); myPlayer.src({type: 'video/mp4', src: 'http://www.example.com/path/to/video.mp4'}); myPlayer.ready(function() { myPlayer.play(); myPlayer.pause(); });
paused 可用于确定播放器当前是否暂停。
var myPlayer = videojs('some-player-id'); myPlayer.src({type: 'video/mp4', src: 'http://www.example.com/path/to/video.mp4'}); myPlayer.ready(function() { // true console.log(myPlayer.paused()); // false console.log(!myPlayer.paused()); myPlayer.play(); // false console.log(myPlayer.paused()); // true console.log(!myPlayer.paused()); myPlayer.pause(); // true console.log(myPlayer.paused()); // false console.log(!myPlayer.paused()); });
currentTime 将显示当前播放的时间(以秒为单位)。例如:
var myPlayer = videojs('some-player-id'); myPlayer.src({type: 'video/mp4', src: 'http://www.example.com/path/to/video.mp4'}); myPlayer.ready(function() { // set current time to 2 minutes into the video myPlayer.currentTime(120); // get the current time, should be 120 seconds var whereYouAt = myPlayer.currentTime(); });
duration 将显示正在播放的视频的总持续时间。例如:
var myPlayer = videojs('some-player-id'); myPlayer.src({type: 'video/mp4', src: 'http://www.example.com/path/to/video.mp4'}); myPlayer.ready(function() { var lengthOfVideo = myPlayer.duration(); });
remainTime(剩余时间)会显示视频中剩余的秒数。例如:
var myPlayer = videojs('some-player-id'); myPlayer.src({type: 'video/mp4', src: 'http://www.example.com/path/to/video.mp4'}); myPlayer.ready(function() { myPlayer.currentTime(10); // should be 10 seconds less than duration console.log(myPlayer.remainingTime()); });
buffered 将为您提供一个 timeRange 对象,该对象代表当前时间范围,可在未来某个时间播放。例如:
var myPlayer = videojs('some-player-id'); myPlayer.src({type: 'video/mp4', src: 'http://www.example.com/path/to/video.mp4'}); myPlayer.ready(function() { var bufferedTimeRange = myPlayer.buffered(); // number of different ranges of time have been buffered. // Usually 1 var numberOfRanges = bufferedTimeRange.length, // Time in seconds when the first range starts. // Usually 0 var firstRangeStart = bufferedTimeRange.start(0), // Time in seconds when the first range ends var firstRangeEnd = bufferedTimeRange.end(0), // Length in seconds of the first time range var firstRangeLength = firstRangeEnd - firstRangeStart; });
bufferedPercent 会显示当前缓冲视频的百分比。例如:
var myPlayer = videojs('some-player-id'); myPlayer.src({type: 'video/mp4', src: 'http://www.example.com/path/to/video.mp4'}); myPlayer.ready(function() { // example 0.11 aka 11% var howMuchIsDownloaded = myPlayer.bufferedPercent(); });