mediaelement
HTML5 <audio> or <video> player with support for MP4, WebM, and MP3 as well as HLS, Dash, YouTube, Facebook, SoundCloud and others with a common HTML5 MediaElement API, enabling a consistent UI in all browsers.
Top Related Projects
HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
Video.js - open source HTML5 video player
:clapper: An extensible media player for the web.
The HTML5 video player for the web
JW Player is the world's most popular embeddable media player.
HTML5 FLV Player
Quick Overview
MediaElement.js is a feature-rich HTML5 audio and video player with a consistent UI across browsers and devices. It supports various media formats and can fall back to alternative technologies like Flash or Silverlight when HTML5 is not supported. The project aims to simplify media playback across different platforms and browsers.
Pros
- Cross-browser compatibility and consistent UI
- Supports a wide range of media formats
- Customizable with plugins and skinning options
- Accessible with full keyboard support and screen reader compatibility
Cons
- Larger file size compared to simpler HTML5 players
- Some legacy browser support may increase complexity
- Requires additional setup for advanced features
- Performance may be impacted on older devices or with complex configurations
Code Examples
- Basic video player setup:
const player = new MediaElementPlayer('player1', {
videoWidth: '100%',
videoHeight: '100%',
enableAutosize: true
});
- Audio player with custom controls:
const player = new MediaElementPlayer('audio1', {
features: ['playpause', 'current', 'progress', 'duration', 'volume'],
audioWidth: 300,
audioHeight: 40
});
- Video player with multiple source formats:
const player = new MediaElementPlayer('video1', {
sources: [
{ src: 'video.mp4', type: 'video/mp4' },
{ src: 'video.webm', type: 'video/webm' },
{ src: 'video.ogv', type: 'video/ogg' }
]
});
Getting Started
- Include the MediaElement.js files in your HTML:
<script src="https://cdnjs.cloudflare.com/ajax/libs/mediaelement/4.2.17/mediaelement-and-player.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/mediaelement/4.2.17/mediaelementplayer.min.css">
- Add a video or audio element to your HTML:
<video id="player1" width="640" height="360" style="max-width:100%;">
<source src="video.mp4" type="video/mp4">
</video>
- Initialize the player in your JavaScript:
document.addEventListener('DOMContentLoaded', function() {
const player = new MediaElementPlayer('player1', {
// Options here
});
});
Competitor Comparisons
HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
Pros of hls.js
- Specialized focus on HLS streaming, providing robust support for adaptive bitrate streaming
- Lightweight and efficient, with a smaller footprint compared to MediaElement
- Active development and frequent updates, ensuring compatibility with latest standards
Cons of hls.js
- Limited to HLS streaming, lacking support for other media formats
- Requires more setup and configuration for basic playback scenarios
- Less extensive plugin ecosystem compared to MediaElement
Code Comparison
MediaElement:
var player = new MediaElementPlayer('player1', {
features: ['playpause', 'current', 'progress', 'duration', 'volume'],
success: function(mediaElement, domObject) {
// Player is ready
}
});
hls.js:
var video = document.getElementById('video');
var hls = new Hls();
hls.loadSource('https://example.com/video.m3u8');
hls.attachMedia(video);
hls.on(Hls.Events.MANIFEST_PARSED, function() {
video.play();
});
MediaElement provides a higher-level API with built-in UI components, while hls.js offers more granular control over HLS streaming but requires additional setup for UI elements. MediaElement supports various media formats out of the box, whereas hls.js specializes in HLS streaming with optimized performance for that specific use case.
Video.js - open source HTML5 video player
Pros of Video.js
- Larger community and more frequent updates
- Better documentation and extensive API
- More customizable with a wide range of plugins
Cons of Video.js
- Larger file size, which may impact page load times
- Steeper learning curve for advanced customizations
- Some features require additional plugins, increasing complexity
Code Comparison
MediaElement:
var player = new MediaElementPlayer('player1', {
features: ['playpause', 'current', 'progress', 'duration', 'volume'],
success: function(mediaElement, domObject) {
// do something
}
});
Video.js:
var player = videojs('my-video', {
controls: true,
autoplay: false,
preload: 'auto',
fluid: true,
plugins: {
// plugin configurations
}
});
Both libraries offer similar basic functionality for creating customizable video players. MediaElement focuses on simplicity and cross-browser compatibility, while Video.js provides more advanced features and customization options. The choice between the two depends on project requirements, desired features, and development preferences.
:clapper: An extensible media player for the web.
Pros of Clappr
- Modern architecture with a plugin-based system for easy extensibility
- Better support for adaptive streaming formats like HLS and DASH
- More active development and frequent updates
Cons of Clappr
- Steeper learning curve for customization compared to MediaElement
- Less extensive browser compatibility, especially for older versions
- Smaller community and fewer third-party plugins available
Code Comparison
MediaElement:
var player = new MediaElementPlayer('player1', {
features: ['playpause', 'current', 'progress', 'duration', 'volume'],
success: function(mediaElement, domObject) {
// do something with the player
}
});
Clappr:
var player = new Clappr.Player({
source: 'https://your.video/here.mp4',
parentId: '#player',
plugins: [LevelSelector],
height: 360,
width: 640
});
Both libraries offer straightforward ways to initialize players, but Clappr's approach is more modern and concise. MediaElement provides more granular control over features, while Clappr focuses on a plugin-based architecture for extensibility. Clappr's code is generally more compact and easier to read, but MediaElement's structure may be more familiar to developers used to older JavaScript patterns.
The HTML5 video player for the web
Pros of Flowplayer
- More active development with frequent updates and releases
- Better support for modern streaming protocols like HLS and DASH
- Extensive API and plugin system for customization
Cons of Flowplayer
- Commercial product with paid licensing for some features
- Steeper learning curve for advanced customization
- Larger file size compared to MediaElement
Code Comparison
MediaElement basic setup:
var player = new MediaElementPlayer('player1', {
features: ['playpause', 'current', 'progress', 'duration', 'volume']
});
Flowplayer basic setup:
flowplayer("#player", {
clip: {
sources: [
{ type: "application/x-mpegurl", src: "video.m3u8" }
]
}
});
Both players offer simple setup options, but Flowplayer's configuration tends to be more concise and focused on modern streaming formats. MediaElement provides more granular control over player features in its initial setup.
While both libraries serve similar purposes, Flowplayer is generally more suited for professional streaming applications with its advanced features and protocols support. MediaElement, on the other hand, offers a simpler, open-source solution that may be sufficient for basic video playback needs.
JW Player is the world's most popular embeddable media player.
Pros of JW Player
- More comprehensive feature set, including advanced streaming capabilities and analytics
- Better documentation and support, with extensive API references and tutorials
- Larger community and ecosystem, with more plugins and integrations available
Cons of JW Player
- Proprietary software with licensing costs for commercial use
- Steeper learning curve due to more complex API and configuration options
- Heavier footprint, which may impact page load times and performance
Code Comparison
MediaElement.js:
var player = new MediaElementPlayer('player1', {
features: ['playpause', 'current', 'progress', 'duration', 'volume'],
success: function(mediaElement, domObject) {
// Player is ready
}
});
JW Player:
jwplayer("myElement").setup({
file: "https://example.com/video.mp4",
width: "100%",
aspectratio: "16:9",
autostart: false,
analytics: {
pid: "YOUR_ANALYTICS_ID"
}
});
Both players offer easy setup, but JW Player provides more configuration options out of the box, including built-in analytics. MediaElement.js focuses on a simpler, more lightweight approach with modular features.
HTML5 FLV Player
Pros of flv.js
- Specialized for FLV playback, offering better performance for this format
- Lightweight and focused, with a smaller footprint
- Supports live streaming of FLV content
Cons of flv.js
- Limited to FLV format, while MediaElement supports multiple formats
- Less extensive plugin ecosystem compared to MediaElement
- Fewer built-in UI controls and customization options
Code Comparison
flv.js:
if (flvjs.isSupported()) {
var videoElement = document.getElementById('videoElement');
var flvPlayer = flvjs.createPlayer({
type: 'flv',
url: 'http://example.com/flv/video.flv'
});
flvPlayer.attachMediaElement(videoElement);
flvPlayer.load();
}
MediaElement:
var player = new MediaElementPlayer('player1', {
success: function(mediaElement, originalNode, instance) {
// do something with the player
},
features: ['playpause', 'current', 'progress', 'duration', 'volume']
});
The code examples show that flv.js is more focused on FLV playback, while MediaElement offers a more general-purpose player with built-in UI features. flv.js requires manual attachment to the video element, whereas MediaElement provides a higher-level abstraction for player creation and management.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
One file. Any browser. Same UI.
- Author: John Dyer http://j.hn/
- Website: http://mediaelementjs.com/
- License: MIT
- Meaning: Use everywhere, keep copyright, it'd be swell if you'd link back here.
- Thanks: my employer, Dallas Theological Seminary
- Contributors: all contributors
Table of Contents
- Introduction
- Installation and Usage
- API and Configuration
- Guidelines for Contributors
- Change Log
- Migration
- TODO list
Introduction
MediaElementPlayer: HTML5 <video>
and <audio>
player
A complete HTML/CSS audio/video player built on top MediaElement.js
.
In general, MediaElement.js
supports IE11+, MS Edge, Chrome, Firefox, Safari, iOS 8+ and Android 4.0+.
It is strongly recommended to read the entire documentation and check the demo
folder to get the most out of this package. Visit here to start.
Installation and Usage
The full documentation on how to install MediaElement.js
is available at Installation.
A brief guide on how to create and use instances of MediaElement
available at Usage.
Additional features can be found at https://github.com/mediaelement/mediaelement-plugins.
API and Configuration
MediaElement.js
has many options that you can take advantage from. Visit API and Configuration for more details.
Also, a Utilities/Features
guide is available for development. Visit Utilities/Features for more details.
Guidelines for Contributors
If you want to contribute to improve this package, please read Guidelines.
Useful resources
A compilation of useful articles can be found here.
Change Log
Changes available at Change Log.
Migration
For migrating mediaelement see Migration guide.
TODO list
IMPORTANT: Before posting an issue, it is strongly encouraged to read the whole documentation since it covers the majority of scenarios exposed in prior issues.
New features and pending bugs can be found at TODO list.
Top Related Projects
HLS.js is a JavaScript library that plays HLS in browsers with support for MSE.
Video.js - open source HTML5 video player
:clapper: An extensible media player for the web.
The HTML5 video player for the web
JW Player is the world's most popular embeddable media player.
HTML5 FLV Player
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot