Installations
npm install @mux/mux-video-react
Developer Guide
Typescript
Yes
Module System
CommonJS, ESM
Node Version
20.12.1
NPM Version
10.5.0
Score
79.7
Supply Chain
92.1
Quality
93.5
Maintenance
100
Vulnerability
100
License
Releases
@mux/playback-core: v0.28.3
Updated on Feb 13, 2025
@mux/mux-video-react: v0.24.3
Updated on Feb 13, 2025
@mux/mux-video: v0.24.3
Updated on Feb 13, 2025
@mux/mux-uploader-react: v1.1.2
Updated on Feb 13, 2025
@mux/mux-uploader: v1.1.2
Updated on Feb 13, 2025
@mux/mux-player-react: v3.3.0
Updated on Feb 13, 2025
Contributors
Languages
TypeScript (53.67%)
JavaScript (33.04%)
HTML (12.08%)
CSS (1.21%)
Shell (0.01%)
validate.email 🚀
Verify real, reachable, and deliverable emails with instant MX records, SMTP checks, and disposable email detection.
Developer
Download Statistics
Total Downloads
1,242,131
Last Day
2,630
Last Week
13,880
Last Month
64,632
Last Year
758,187
GitHub Statistics
MIT License
281 Stars
1,384 Commits
53 Forks
16 Watchers
5 Branches
45 Contributors
Updated on Feb 27, 2025
Bundle Size
530.50 kB
Minified
155.28 kB
Minified + Gzipped
Package Meta Information
Latest Version
0.24.3
Package Id
@mux/mux-video-react@0.24.3
Unpacked Size
46.69 kB
Size
14.13 kB
File Count
13
NPM Version
10.5.0
Node Version
20.12.1
Published on
Feb 13, 2025
Total Downloads
Cumulative downloads
Total Downloads
1,242,131
Last Day
-2.8%
2,630
Compared to previous day
Last Week
-4.8%
13,880
Compared to previous week
Last Month
14.9%
64,632
Compared to previous month
Last Year
84%
758,187
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
<mux-video/>
Introduction
<MuxVideo/>
is a Mux-flavored React video component.
If you are familiar with using <video />
+ Hls.js in your application, then you'll feel right at home with this React component.
Installation
If you're using npm
or yarn
, install that way:
Package manager
yarn add @mux/mux-video-react
or
npm i @mux/mux-video-react
Then, import the library into your application with either import
or require
:
1import MuxVideo from '@mux/mux-video-react';
or
1const MuxVideo = require('@mux/mux-video-react');
Features and benefits
Without <MuxVideo/>
, if you want to use the browser built-in HTML5 video element for playback you would have to wire up Hls.js and Mux Data yourself.
<MuxVideo/>
will automatically handle recoverable errors that happen during video playback. This is particularly handy for live streams that may experience disconnects.
<MuxVideo/>
will use the optimial Hls.js settings for Mux Video so you don't have to worry about that. <MuxVideo/>
will also periodically test new versions of Hls.js and upgrade to known stable versions so you don't have to worry about upgrading to a new version of Hls.js yourself.
Usage
Loading this library in the browser will register a custom web component for <mux-video>
.
Now you are free to use this web component in your HTML, just as you would with the HTML5 <video>
element.
1const MuxVideoExample = () => { 2 return ( 3 <div> 4 <h1>Simple MuxVideo Example</h1> 5 <MuxVideo 6 style={{ height: '100%', maxWidth: '100%' }} 7 playbackId="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe" 8 metadata={{ 9 video_id: 'video-id-123456', 10 video_title: 'Super Interesting Video', 11 viewer_user_id: 'user-id-bc-789', 12 }} 13 controls 14 autoPlay 15 muted 16 /> 17 </div> 18 ); 19};
Primary Props:
playbackId: string
: This is the playback ID for your Mux Asset or Mux Live Stream. The playback-id is the variable you may have used before to construct a.m3u8
hls url like this:https://stream.mux.com/{PLAYBACK_ID}.m3u8
. For more, check out the Mux Docs.envKey: string
: This is the environment key for Mux Data. Note that this is different than your API Key. Get your env key from the "Mux Data" part of your Mux Environments Dashboard. If undefined and you are playing a Mux Video asset, the environment will be inferred.metadata: Object
: This is an object for configuring any metadata you'd like to send to Mux Data. For a detailed discussion of the available metadata fields and what they represent, check out the Mux Data docs. A few high priority keys that you'll likely want to set are:video_id: string
: Your internal ID for the video.video_title: string
: Title of the video player (e.g.: 'Awesome Show: Pilot')viewer_user_id: string
: An ID representing the viewer who is watching the stream. Use this to look up video views for an individual viewer. If no value is specified, a unique ID will be generated by the SDK. Note: You should not use any value that is personally identifiable on its own (such as email address, username, etc). Instead, you should supply an anonymized viewer ID which you have stored within your own system.
streamType: string
: Enum value: one of"on-demand"
,"live"
(HLS live stream),"ll-live"
(low latency live). Not strictly required, but preferred so that<MuxVideo/>
can make optimizations based on the type of stream.startTime: number (seconds)
: Set this to start playback of your media at some time other than 0.
In addition, any props that you would use on a <video>
element like poster
, controls
, muted
and autoPlay
are available and should work the same as they do when using a video element in react. One sidenote about autoPlay
though -- read this to understand why that might not always work as expected.
Advanced: preferPlayback
By default <MuxVideo/>
will try to use native playback via the underlying <video/>
tag whenever possible. However, it can also instead use an in-code player as long as the browser supports Media Source Extensions. This includes MSE in Mac OS Safari.
If you prefer to use the in-code MSE-based engine (currently hls.js) whenever possible, then simply set the preferPlayback
prop to mse
.
1<MuxVideo 2 playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe" 3 metadata={{ 4 video_id: 'video-id-123456', 5 video_title: 'Super Interesting Video', 6 viewer_user_id: 'user-id-bc-789', 7 }} 8 preferPlayback="mse" 9 controls 10/>
Advanced: type
By default <MuxVideo/>
will try to figure out the type of media you're trying to play (for example, an HLS/m3u8 media source, an mp4, etc.) based the extension of the file from the src
attribute's url. This allows <MuxVideo/>
to determine whether it can/should use an in-code player or native playback. By way of example, the code below has an identifiable "mp4" extension, so <MuxVideo/>
will rely on native playback via the underlying <video/>
tag.
1<MuxVideo 2 src="https://stream.mux.com/DS00Spx1CV902MCtPj5WknGlR102V5HFkDe/high.mp4" 3 metadata={{ 4 video_id: 'video-id-123456', 5 video_title: 'Super Interesting Video', 6 viewer_user_id: 'user-id-bc-789', 7 }} 8 controls 9/>
Sometimes, however, your src
URL may not have an identifiable extension. In these cases, we recommend relying on the type
attribute, similar to the <source/>
tag's type attribute. Below is an example of explicitly declaring the MIME type for an HLS/m3u8 media source:
1<MuxVideo 2 src="https://stream.notmux.com/path/to/an/hls/source/playlist" 3 type="application/vnd.apple.mpegurl" 4 metadata={{ 5 video_id: 'video-id-123456', 6 video_title: 'Super Interesting Video', 7 viewer_user_id: 'user-id-bc-789', 8 }} 9 controls 10/>
Or, for convenience, we also support the shorthand type="hls
:
1<MuxVideo 2 src="https://stream.notmux.com/path/to/an/hls/source/playlist" 3 type="hls" 4 metadata={{ 5 video_id: 'video-id-123456', 6 video_title: 'Super Interesting Video', 7 viewer_user_id: 'user-id-bc-789', 8 }} 9 controls 10/>
Advanced: Signed URLs and other playback query params
Mux supports a number of query parameters on HLS playback URLs. Most commonly the token=
param is used for signed URLs.
In order to use token=
-- or any other query params, pass them through with the playbackId
prop:
playbackId="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe?token=jwt-signed-token"
FAQ
Can I use <MuxVideo/>
with TypeScript
?
Yes! In fact, @mux-element/mux-video-react
is written entirely in TypeScript
and provides a definitions file automatically (no additional installs needed).
If I'm using Mux, do I have to use this library?
No, you do not. The way Mux delivers HLS video is compliant with the HLS spec. Any video player that supports HLS will work with Mux Video.
If I'm not using Mux Video, can I still use this library?
You sure can! Instead of passing in playbackId=""
prop, pass in src=""
with an HLS url. You can still use envKey=""
to get all the features of Mux Data with your non-Mux video.

No vulnerabilities found.
Reason
30 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 10
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
packaging workflow detected
Details
- Info: Project packages its releases by way of GitHub Actions.: .github/workflows/cd.yml:11
Reason
Found 5/24 approved changesets -- score normalized to 2
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: jobLevel 'contents' permission set to 'write': .github/workflows/cd.yml:15
- Warn: no topLevel permission defined: .github/workflows/cd.yml:1
- Warn: no topLevel permission defined: .github/workflows/ci.yml:1
- Warn: no topLevel permission defined: .github/workflows/project.yml:1
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/cd.yml:20: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/cd.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/cd.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/cd.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/cd.yml:37: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/cd.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/cd.yml:73: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/cd.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:26: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:47: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:52: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:66: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/ci.yml:67: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:77: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/ci.yml/main?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/ci.yml:84: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/ci.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/project.yml:14: update your workflow using https://app.stepsecurity.io/secureworkflow/muxinc/elements/project.yml/main?enable=pin
- Info: 0 out of 9 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 4 third-party GitHubAction dependencies pinned
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 22 are checked with a SAST tool
Reason
19 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-mh2x-fcqh-fmqv
- Warn: Project is vulnerable to: GHSA-rjjv-87mx-6x3h
- Warn: Project is vulnerable to: GHSA-pxg6-pf52-xh8x
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-67mh-4wv8-2f99
- Warn: Project is vulnerable to: GHSA-c7qv-q95q-8v27
- Warn: Project is vulnerable to: GHSA-593f-38f6-jp5m
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-7gfc-8cq8-jh5f
- Warn: Project is vulnerable to: GHSA-7m27-7ghc-44w9
- Warn: Project is vulnerable to: GHSA-rp65-9cf3-cjxr
- Warn: Project is vulnerable to: GHSA-rhx6-c78j-4q9w
- Warn: Project is vulnerable to: GHSA-7fh5-64p2-3v2j
- Warn: Project is vulnerable to: GHSA-gcx4-mw62-g8wm
- Warn: Project is vulnerable to: GHSA-76p7-773f-r4q5
- Warn: Project is vulnerable to: GHSA-8266-84wp-wv5c
- Warn: Project is vulnerable to: GHSA-c76h-2ccp-4975
- Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6
- Warn: Project is vulnerable to: GHSA-3h5v-q93c-6h6q
Score
4.4
/10
Last Scanned on 2025-02-17
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn MoreOther packages similar to @mux/mux-video-react
@mux/mux-player-react
An open source Mux player for React that Just Works™
@mux/mux-uploader-react
An uploader element for React that handles Mux Direct Uploads and a visual progress bar for you
@mux/mux-data-react-native-video
Mux Data SDK for monitoring react-native-video
@mux-elements/mux-video-react
A custom mux video element for React that Just Works™