微信小程序选项卡功能开发步骤与方法全解析
1737
2022-10-28
vidz:一个零依赖,框架无关的视频实现
vidz
Tiny library to provide a no-muss, no-fuss HTML5 video element
Purpose
To introduce a simple, straightforward method to dynamically add well-formatted HTML5 video to the DOM. vidz has no dependencies, and is based off of the native DOM elements and selectors, however if you are using jQuery it will also work with elements in jQuery objects.
Installation
$ npm i vidz --save
Usage
// ES2015import vidz from 'vidz';// CommonJSconst vidz = require('vidz').default;// scriptconst vidz = window.vidz;const vidzInstance = vidz('#video-container', { mp4: './videos/test.mp4', ogg: './videos/test.ogg'});
This will instantiate a new vidz instance, appending a generated
Advanced usage
vidz(selector: string|HTMLElement|jQueryObject, config: object)
const standardSelector = vidz('#video-container', config);const domElement = vidz(document.querySelector('#video-container'), config);const jqueryObject = vidz($('#video-container'), config);
Available options in the config object:
attributes {object} defaults to {}Additional attributes that you want to pass to the
Methods for the Vidz instance
add()
If the player has been previously removed from the selector passed originally, it re-appends the player to the selector.
canPlayType(format: string)
Returns the same format string if it supports the type format, else returns an empty string
getBuffered()
Returns the value of the buffered property for the player
getCurrentTime()
Returns the value of the currentTime property for the player
getDuration()
Returns the value of the duration property for the player
getFlashObject()
Returns the
getPercentLoaded()
Returns the percent loaded the video is (rounded to two decimal places)
getPlaybackRate()
Returns the playbackRate of the video player (standard playbackRate is 1, valid values are between 0.25 and 16)
getPlayer()
Returns the
getSource()
Returns an object of {mp4: string, ogg: string, webm: string} with the source values for the player
getVideoDimensions
Returns an object of {height: number, width: number} which reflects the height and width of the video (not the
getVolume()
Returns the volume of the player (standard volume is 1, valid values are between 0 and 1)
load()
Triggers a load event on the player
mute()
Mutes the player
pause()
If the player is playing, it pauses the player
play()
If the player is paused, it plays the player
remove()
Removes the player as a child from the selector passed originally.
restart()
Sets the currentTime to 0
setCurrentTime(value: number)
Jumps the currentTime to the value provided
setPlaybackRate(value: number) defaults to 1
Sets the playbackRate to the value provided
setSource({mp4: string, ogg: string, web: string})
Sets the players src attribute to the value provided
setVolume(value: number) defaults to 1
Sets the player's volume to the value provided (standard volume is 1, valid values are between 0 and 1)
unmute()
If muted, it unmutes the player
Note
All of the methods above save for add and remove are specific to the HTML5 video element. Unfortunately we cannot provide the same programmatic controls for the Flash instance, as it is dependent on the SWF file you use. There is a getFlashObject convenience function to get the flash object you can control.
Development
Standard stuff, clone the repo and npm i to get the dependencies. npm scripts available:
build => builds the distributed JS with NODE_ENV=development and with sourcemapsbuild-minified => builds the distributed JS with NODE_ENV=production and minifiedcompile-for-publish => runs the lint, test, transpile, and dist scriptsdev => runs the webpack dev server for the playgrounddist => runs the build and build-minifiedlint => runs ESLint against files in the src folderprepublish => if in publish, runs compile-for-publishtest => runs AVA teststest:watch => runs AVA tests with persistent watchertranspile => runs Babel against files in src to files in lib
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~