This is a media player that uses all the goods of HTML5 video/audio elements to play the most popular media in MP4/MP3, HLS and M(PEG)-DASH, and also has the ability to play VMAP, VAST and VPAID ads.
Advantages
- Supports IE11+ (Win8) and all modern browsers.
- No dependencies, since it is written in Typescript.
- Runs a simple but yet powerful algorithm to check the browser's autoplay capabilities across browsers.
- Supports for local and remote captions for both video and audio, even without including the
crossorigin
attribute. - Enhance your player adding your own buttons. Check here for more details.
- Provides the ability to use a single VAST/VPAID source or a VAST/VPAID playlist from several different sources (including URLs and valid XML strings).
- Can play ads in infinite loop, desired for ads that are in a heavy text page.
- Always responsive by default, for both video/audio tags; a new
fill
mode is also included to scale and crop media relative to its parent container.
:warning: IMPORTANT: Migrating from v1.x.x to v2.x.x :warning:
In order to achieve a smooth upgrading between version 1.x.x
and 2.x.x
, there is a couple of things to keep in mind:
- The player will only accept now 2 parameters instead of 4: the player ID and the player options.
controls
and showLiveProgress
properties are now complex object structures, where we can indicate visibility and a new set of extra layers/visibility.
To simplify this even more:
v1.x.x
const player = new OpenPlayerJS('player', 'https://ads.example.url/xml', true, {
controls: {
left: ['play', 'time', 'volume'],
middle: ['progress'],
right: ['captions', 'settings', 'fullscreen'],
},
showLiveProgress: false,
});
player.init();
v2.x.x
const player = new OpenPlayerJS('player', {
ads: {
src: 'https://ads.example.url/xml',
},
mode: 'fullscreen',
controls: {
alwaysVisible: false,
layers: {
left: ['play', 'time', 'volume'],
middle: ['progress'],
right: ['captions', 'settings', 'fullscreen'],
}
},
live: {
showLabel: true,
showProgress: false,
},
});
player.init();
Getting Started
The standard template to start using OpenPlayerJS is show in the following snippet.
<html>
<head>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/openplayerjs@latest/dist/openplayer.min.css">
</head>
<body>
<video class="op-player__media" id="player" controls playsinline>
<source src="/path/to/video.mp4" type="video/mp4">
<track kind="subtitles" src="/path/to/video.vtt" srclang="en" label="English">
</video>
<script src="https://cdn.jsdelivr.net/npm/openplayerjs@latest/dist/openplayer.min.js"></script>
<script>
const player = new OpenPlayerJS('player');
player.init();
</script>
</body>
</html>
Usage and API Guides
If you want to unleash the power of OpenPlayerJS, learn more about OpenPlayerJS by checking the following links.
Code Samples
In 2.x.x, the demo
folder is now removed in favor of code samples.
If you need a reference on how to use OpenPlayerJS in some of the most common scenarios, check the following links:
- No configuration (only DOM classes)
- Minimal configuration
- Using
fill
mode - Using
fit
mode - Using Ads
- Removing controls and using
preload="none"
- Add source after initialization (useful for AJAX)
- Fully customized audio player
- Playing HLS streaming with DRM (Encryption)
- M(PEG)-DASH with Ads
- Basic playlist (video and audio)
- Ads playlist (multiple URLs)
- Retrieve data from audio streaming (HLS)
- YouTube video (using plugin)
- Addition of a custom control
- OpenPlayerJS with Next.js
- Using
Levels
and setting width/height - Trigger Ad manually
- Use FLV source (only modern browsers and Android, not iOS)
- Using hls.js p2p plugin
Built With
Authors
See also the list of contributors who participated in this project.
License
This project is licensed under the MIT License - see the LICENSE.md file for details.