UNPKG

5.46 kBMarkdownView Raw
1[![Video.js logo][logo]][vjs]
2
3# Video.js® - Web Video Player
4
5[![NPM][npm-icon]][npm-link]
6
7Video.js is a full featured, open source video player for all web-based platforms.
8
9Right out of the box, Video.js supports all common media formats used on the web including streaming formats like HLS and DASH. It works on desktops, mobile devices, tablets, and web-based Smart TVs. It can be further extended and customized by a robust ecosystem of [plugins][plugins].
10
11Video.js was started in the middle of 2010 and is now used on over ~~50,000~~ ~~100,000~~ ~~200,000~~ ~~400,000~~ ~~700,000~~ [800,000 websites][builtwith].
12
13## Table of Contents
14
15* [Quick Start](#quick-start)
16* [Contributing](#contributing)
17* [Code of Conduct](#code-of-conduct)
18* [License](#license)
19
20## [Quick Start][getting-started]
21
22Thanks to the awesome folks over at [Fastly][fastly], there's a free, CDN hosted version of Video.js that anyone can use. Add these tags to your document's `<head>`:
23
24```html
25<link href="//vjs.zencdn.net/8.21.0/video-js.min.css" rel="stylesheet">
26<script src="//vjs.zencdn.net/8.21.0/video.min.js"></script>
27```
28
29Alternatively, you can include Video.js by getting it from [npm](https://videojs.com/getting-started/#install-via-npm), downloading it from [GitHub releases](https://github.com/videojs/video.js/releases) or by including it via [unpkg](https://unpkg.com) or another JavaScript CDN, like CDNjs.
30
31```html
32<!-- unpkg : use the latest version of Video.js -->
33<link href="https://unpkg.com/video.js/dist/video-js.min.css" rel="stylesheet">
34<script src="https://unpkg.com/video.js/dist/video.min.js"></script>
35
36<!-- unpkg : use a specific version of Video.js (change the version numbers as necessary) -->
37<link href="https://unpkg.com/video.js@8.21.0/dist/video-js.min.css" rel="stylesheet">
38<script src="https://unpkg.com/video.js@8.21.0/dist/video.min.js"></script>
39
40<!-- cdnjs : use a specific version of Video.js (change the version numbers as necessary) -->
41<link href="https://cdnjs.cloudflare.com/ajax/libs/video.js/8.21.0/video-js.min.css" rel="stylesheet">
42<script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/8.21.0/video.min.js"></script>
43```
44
45Next, using Video.js is as simple as creating a `<video>` element, but with an additional `data-setup` attribute. At a minimum, this attribute must have a value of `'{}'`, but it can include any Video.js [options][options] - just make sure it contains valid JSON!
46
47```html
48<video
49 id="my-player"
50 class="video-js"
51 controls
52 preload="auto"
53 poster="//vjs.zencdn.net/v/oceans.png"
54 data-setup='{}'>
55 <source src="//vjs.zencdn.net/v/oceans.mp4" type="video/mp4"></source>
56 <source src="//vjs.zencdn.net/v/oceans.webm" type="video/webm"></source>
57 <source src="//vjs.zencdn.net/v/oceans.ogv" type="video/ogg"></source>
58 <p class="vjs-no-js">
59 To view this video please enable JavaScript, and consider upgrading to a
60 web browser that
61 <a href="https://videojs.com/html5-video-support/" target="_blank">
62 supports HTML5 video
63 </a>
64 </p>
65</video>
66```
67
68When the page loads, Video.js will find this element and automatically setup a player in its place.
69
70If you don't want to use automatic setup, you can leave off the `data-setup` attribute and initialize a `<video>` element manually using the `videojs` function:
71
72```js
73var player = videojs('my-player');
74```
75
76The `videojs` function also accepts an `options` object and a callback to be invoked when the player is ready:
77
78```js
79var options = {};
80
81var player = videojs('my-player', options, function onPlayerReady() {
82 videojs.log('Your player is ready!');
83
84 // In this context, `this` is the player that was created by Video.js.
85 this.play();
86
87 // How about an event listener?
88 this.on('ended', function() {
89 videojs.log('Awww...over so soon?!');
90 });
91});
92```
93
94If you're ready to dive in, the [Getting Started][getting-started] page and [documentation][docs] are the best places to go for more information. If you get stuck, head over to our [Slack][slack-link]!
95
96## [Contributing][contributing]
97
98Video.js is a free and open source library, and we appreciate any help you're willing to give - whether it's fixing bugs, improving documentation, or suggesting new features. Check out the [contributing guide][contributing] for more!
99
100_Video.js uses [BrowserStack][browserstack] for compatibility testing._
101
102## [Code of Conduct][coc]
103
104Please note that this project is released with a [Contributor Code of Conduct][coc]. By participating in this project you agree to abide by its terms.
105
106## [License][license]
107
108Video.js is [licensed][license] under the Apache License, Version 2.0.
109
110Video.js is a registered trademark of [Brightcove, Inc][bc].
111
112[bc]: https://www.brightcove.com/
113
114[browserstack]: https://browserstack.com
115
116[builtwith]: https://trends.builtwith.com/media/VideoJS
117
118[contributing]: https://github.com/videojs/admin/blob/main/CONTRIBUTING.md
119
120[docs]: https://docs.videojs.com
121
122[fastly]: https://www.fastly.com/
123
124[getting-started]: https://videojs.com/getting-started/
125
126[license]: LICENSE
127
128[logo]: https://videojs.com/logo-white.png
129
130[npm-icon]: https://nodei.co/npm/video.js.png?downloads=true&downloadRank=true
131
132[npm-link]: https://nodei.co/npm/video.js/
133
134[options]: https://videojs.com/guides/options/
135
136[plugins]: https://videojs.com/plugins/
137
138[slack-link]: https://slack.videojs.com
139
140[vjs]: https://videojs.com
141
142[coc]: https://github.com/videojs/admin/blob/main/CODE_OF_CONDUCT.md