video.dev 源码解析
来源:互联网 发布:淘宝直通车分时折扣 编辑:程序博客网 时间:2024/06/05 23:55
知识回顾
//播放的时候会回调改方法 timeupdate。myPlayer=vjs.players['my-video'];myPlayer.on("timeupdate", function(){console.log("start");});//获取总时长 vjs.players['my-video'].duration();//获取当前时长 vjs.players['my-video'].currentTime();
myPlayer=vjs.players['my-video'];
开始 播放:myPlayer.play();
结束 播放:myPlayer.pause();
设置 播放进度:myPlayer.currentTime(120);
/** * Displays the current time * @param {vjs.Player|Object} player * @param {Object=} options * @constructor */vjs.CurrentTimeDisplay = vjs.Component.extend({ /** @constructor */ init: function(player, options){ vjs.Component.call(this, player, options); player.on('timeupdate', vjs.bind(this, this.updateContent)); }});vjs.CurrentTimeDisplay.prototype.createEl = function(){ var el = vjs.Component.prototype.createEl.call(this, 'div', { className: 'vjs-current-time vjs-time-controls vjs-control' }); this.contentEl_ = vjs.createEl('div', { className: 'vjs-current-time-display', innerHTML: '<span class="vjs-control-text">Current Time </span>' + '0:00', // label the current time for screen reader users 'aria-live': 'off' // tell screen readers not to automatically read the time as it changes }); el.appendChild(this.contentEl_); return el;};vjs.CurrentTimeDisplay.prototype.updateContent = function(){ // Allows for smooth scrubbing, when player can't keep up. var time = (this.player_.scrubbing) ? this.player_.getCache().currentTime : this.player_.currentTime(); this.contentEl_.innerHTML = '<span class="vjs-control-text">Current Time </span>' + vjs.formatTime(time, this.player_.duration());};
//鼠标移动进度条代码
vjs.SeekBar.prototype.onMouseMove = function(event){ var newTime = this.calculateDistance(event) * this.player_.duration(); // Don't let video end while scrubbing. if (newTime == this.player_.duration()) { newTime = newTime - 0.1; } // Set new time (tell player to seek to new time) this.player_.currentTime(newTime); this.player_.play(); };
vjs.Slider.prototype.onMouseUp = function() { vjs.unblockTextSelection(); vjs.off(document, 'mousemove', this.boundEvents.move, false); vjs.off(document, 'mouseup', this.boundEvents.end, false); vjs.off(document, 'touchmove', this.boundEvents.move, false); vjs.off(document, 'touchend', this.boundEvents.end, false); this.update();};vjs.Slider.prototype.update = function(){ // In VolumeBar init we have a setTimeout for update that pops and update to the end of the // execution stack. The player is destroyed before then update will cause an error if (!this.el_) return; // If scrubbing, we could use a cached value to make the handle keep up with the user's mouse. // On HTML5 browsers scrubbing is really smooth, but some flash players are slow, so we might want to utilize this later. // var progress = (this.player_.scrubbing) ? this.player_.getCache().currentTime / this.player_.duration() : this.player_.currentTime() / this.player_.duration(); var barProgress, progress = this.getPercent(), handle = this.handle, bar = this.bar; // Protect against no duration and other division issues if (isNaN(progress)) { progress = 0; } barProgress = progress; // If there is a handle, we need to account for the handle in our calculation for progress bar // so that it doesn't fall short of or extend past the handle. //change by david if (false) { var box = this.el_, boxWidth = box.offsetWidth, handleWidth = handle.el().offsetWidth, // The width of the handle in percent of the containing box // In IE, widths may not be ready yet causing NaN handlePercent = (handleWidth) ? handleWidth / boxWidth : 0, // Get the adjusted size of the box, considering that the handle's center never touches the left or right side. // There is a margin of half the handle's width on both sides. boxAdjustedPercent = 1 - handlePercent, // Adjust the progress that we'll use to set widths to the new adjusted box width adjustedProgress = progress * boxAdjustedPercent; // The bar does reach the left side, so we need to account for this in the bar's width barProgress = adjustedProgress + (handlePercent / 2); // Move the handle from the left based on the adjected progress handle.el().style.left = vjs.round(adjustedProgress * 100, 2) + '%'; } // Set the new bar width bar.el().style.width = vjs.round(barProgress * 100, 2) + '%';};
阅读全文
0 0
- video.dev 源码解析
- react vr 视频(video)源码解析
- HTML5 Dev (1) Live Video Streaming Player
- WebKit之video解析
- IOS Dev Intro - Video 420v 420f
- linux /dev/console设备解析
- >/dev/null 2>&1解析
- linux /dev/console设备解析
- linux /dev/console设备解析
- contiki 源码分析之dev(六)(core / dev)
- WebRTC源码分析之Video Capture
- html5 video自动播放下一个源码
- video
- Video
- video
- Video
- video
- PostgreSQL9.3dev 源码阅读: 开篇(系统启动)
- tensorflow 环境搭建
- 热分析原理搞一搞
- [LeetCode]173. Binary Search Tree Iterator
- python实例(暂停一秒输出)
- tensorflow学习:错误 InternalError: Dst tensor is not initialized
- video.dev 源码解析
- 一份非常棒的vim配置
- docker logs 查看实时日志
- python 中字典{ }的嵌套
- Android初级开发(四)——补充8、ViewPager的使用
- 7620:区间合并
- hdu
- 浪漫圣地1
- mysql 5.7.16 在window 下安装配置