Home

Awesome

<p align="center"> <a href="https://videojs.com#gh-dark-mode-only" target="_blank"> <br /> <img height="52px" src="/videojs-logo.png" /> </a> </p>

videojs-player

GitHub stars   GitHub issues   GitHub forks   Test Codecov   license

@videojs-player/vue   @videojs-player/react   vue-video-player

Video.js player component for Vue(3) and React.


BREAKING CHANGE ⚠️

The vue-video-player package has now been renamed to @videojs-player/vue due to the addition of support for React. Also, support for Vue has undergone a Breaking change, with the latest version of the component only supporting Vue3.

The last version of the vue-video-player package will be released in v6.0, which will just re-export everything from @videojs-player/vue, so if you're ready to use the new version of vue-video-player, please import @videojs-player/vue directly.

The latest version of videojs-player supports responsiveness for the vast majority of Video.js configuration options and allows you to fully customize the player's control panel and interaction details, thanks to the fact that the component does enough processing internally for different frameworks.

Legacy Version

If you are looking for a legacy version of the component for Vue2, use the vue-video-player@5.x


Component Documentation

Video.js Documentation


Usage (Vue)

Install

npm install video.js @videojs-player/vue --save
yarn add video.js @videojs-player/vue

Global component

import { createApp } from 'vue'
import VueVideoPlayer from '@videojs-player/vue'
import 'video.js/dist/video-js.css'

const app = createApp()

app.use(VueVideoPlayer)

Local component

<template>
  <video-player
    src="/your-path/video.mp4"
    poster="/your-path/poster.jpg"
    controls
    :loop="true"
    :volume="0.6"
    ...
    @mounted="..."
    @ready="..."
    @play="..."
    @pause="..."
    @ended="..."
    @seeking="..."
    ...
  />
</template>

<script>
  import { defineComponent } from 'vue'
  import { VideoPlayer } from '@videojs-player/vue'
  import 'video.js/dist/video-js.css'

  export default defineComponent({
    components: {
      VideoPlayer
    }
  })
</script>

Custom player controls

<template>
  <video-player :children="[]" ...>
    <template v-slot="{ player, state }">
      <div class="custom-player-controls">
        <button @click="state.playing ? player.pause() : player.play()">
          {{ state.playing ? 'Pause' : 'Play' }}
        </button>
        <button @click="player.muted(!state.muted)">
          {{ state.muted ? 'UnMute' : 'Mute' }}
        </button>
        <!-- more custom controls elements ... -->
      </div>
    </template>
  </video-player>
</template>

Usage (React)

Install

npm install video.js @videojs-player/react --save
yarn add video.js @videojs-player/react

Component

import React from 'react'
import { VideoPlayer } from '@videojs-player/react'
import 'video.js/dist/video-js.css'

export const Component: React.FC = () => {
  return (
    <VideoPlayer
      src="/your-path/video.mp4"
      poster="/your-path/poster.jpg"
      controls
      loop={true}
      volume={0.6}
      // more props...
      onMounted={/*...*/}
      onReady={/*...*/}
      onPlay={/*...*/}
      onPause={/*...*/}
      onEnded={/*...*/}
      onSeeking={/*...*/}
      // more events...
    />
  )
}

Custom player controls

import React from 'react'
import { VideoPlayer } from '@videojs-player/react'

export const Component: React.FC = () => {
  return (
    <VideoPlayer videoJsChildren={[]} /* props... */>
      {({ player, state }) => (
        <div class="custom-player-controls">
          <button onClick={() => state.playing ? player.pause() : player.play()}>
            {{ state.playing ? 'Pause' : 'Play' }}
          </button>
          <button onClick={() => player.muted(!state.muted)}>
            {{ state.muted ? 'UnMute' : 'Mute' }}
          </button>
          {/* more custom controls elements ... */}
        </div>
      )}
    </VideoPlayer>
  )
}

Component Props

All parameters are optional and Video.js determines the default value of each prop.

"responsive" means that if the prop value you pass in the component changes, Video.js will automatically respond to the corresponding update, e.g. a change in volume will cause the player to change the volume.

Prop NameVideo.js API Doc & DescriptionTypeResponsive
idoptions.idString
srcoptions.srcString
sourcesoptions.sourcesArray
widthoptions.widthNumber
heightoptions.heightNumber
preloadoptions.preloadString
loopoptions.loopBoolean
mutedoptions.mutedBoolean
posteroptions.posterString
controlsoptions.controlsBoolean
autoplayoptions.autoplayBoolean | String
playsinlineoptions.playsinlineBoolean
crossoriginoptions.crossOriginString
volumeA number, between 0 and 1, control the volume of the player.Number
playbackRateControl the playback rate of the player.Number
playbackRatesoptions.playbackRatesArray<Number>
fluidoptions.fluidBoolean
filloptions.fillBoolean
languageoptions.languageString
languagesoptions.languagesObject
tracksoptions.tracksArray
textTrackSettingsoptions.textTrackSettingsObject
responsiveoptions.responsiveBoolean
breakpointsoptions.breakpointsObject
fullscreenoptions.fullscreenFullscreenOptions
aspectRatiooptions.aspectRatioBoolean
liveuioptions.liveuiBoolean
liveTrackeroptions.liveTrackerObject
disablePictureInPictureoptions.disablePictureInPictureBoolean
notSupportedMessageoptions.notSupportedMessageString
normalizeAutoplayoptions.normalizeAutoplayBoolean
audioPosterModeoptions.audioPosterModeBoolean
audioOnlyModeoptions.audioOnlyModeBoolean
noUITitleAttributesoptions.noUITitleAttributesBoolean
preferFullWindowoptions.preferFullWindowBoolean
suppressNotSupportedErroroptions.suppressNotSupportedErrorBoolean
techCanOverridePosteroptions.techCanOverridePosterBoolean
techOrderoptions.techOrderArray
inactivityTimeoutoptions.inactivityTimeoutNumber
userActionsoptions.userActionsObject
restoreEloptions.restoreElBoolean | Element
vtt.jsoptions['vtt.js']String
children (Vue) <br> videoJsChildren (React)options.childrenArray | Object
html5options.html5Object
pluginsoptions.pluginsObject
optionsA fallback scheme, if you need to use options that don't exist in props, pass them to options.VideoJsPlayerOptions

Component Events

Events emitted by Video.js, the argument type is always EventTarget.

Video.js Event🫥 🫥 🫥 🫥 🫥 🫥VueReact
event.loadstart-@loadstartonLoadStart
event.suspend-@suspendonSuspend
event.abort-@abortonAbort
event.error-@erroronError
event.emptied-@emptiedonEmptied
event.stalled-@stalledonStalled
event.loadedmetadata-@loadedmetadataonLoadedMetadata
event.loadeddata-@loadeddataonLoadedData
event.canplay-@canplayonCanPlay
event.canplaythrough-@canplaythroughonCanPlayThrough
event.playing-@playingonPlaying
event.waiting-@waitingonWaiting
event.seeking-@seekingonSeeking
event.seeked-@seekedonSeeked
event.ended-@endedonEnded
event.durationchange-@durationchangeonDurationChange
event.timeupdate-@timeupdateonTimeUpdate
event.progress-@progressonProgress
event.play-@playonPlay
event.pause-@pauseonpause
event.ratechange-@ratechangeonRateChange
event.resize-@resizeonResize
event.volumechange-@volumechangeonVolumeChange
event.posterchange-@posterchangeonPosterChange
event.languagechange-@languagechangeonLanguageChange
event.fullscreenchange-@fullscreenchangeonFullscreenChange
event.playbackrateschange-@playbackrateschangeonPlaybackRatesChange
event.controlsdisabled-@controlsdisabledonControlsDisabled
event.controlsenabled-@controlsenabledonControlsEnabled
event.enterFullWindow-@enterFullWindowonEnterFullWindow
event.exitFullWindow-@exitFullWindowonExitFullWindow
event.enterpictureinpicture-@enterpictureinpictureonEnterPictureInPicture
event.leavepictureinpicture-@leavepictureinpictureonLeavePictureInPicture
event.sourceset-@sourcesetonSourceSet
event.texttrackchange-@texttrackchangeonTextTrackChange
event.textdata-@textdataonTextData
event.useractive-@useractiveonUserActive
event.userinactive-@userinactiveonUserInactive
event.usingcustomcontrols-@usingcustomcontrolsonUsingCustomControls
event.usingnativecontrols-@usingnativecontrolsonUsingNativeControls
event.dispose-@disposeonDispose
event.beforepluginsetup-@beforepluginsetuponBeforePluginSetup
event.pluginsetup-@pluginsetuponPluginSetup
event.componentresize-@componentresizeonComponentResize
event.playerresize-@playerresizeonPlayerResize
event.tap-@taponTap
event.ready-@readyonReady

The events emitted by videojs-player component.

Component EventDescriptionVueReact
mountedFires when player component mounted. <br> ({ video: HTMLVideoElement, player: VideoJsPlayer, state: VideoPlayerState })@mountedonMounted
unmountedFires when player component unmounted.@unmountedonUnmounted
stateChangeFires when player state changed (React only). (state: VideoPlayerState)-onStateChange

Player State

The component maintains a fully responsive state object internally with the player so that you can consume the player state out-of-the-box outside the player, you can get this object via the mounted event or stateChange (React Only).

KeyDescriptionValue type
srcThe URL of the currently playing video.String
currentSrcdittoString
currentSourceThe currently playing video source object.videojs.Tech.SourceObject
widthPlayer's width.Number
heightPlayer's height.Number
currentWidthdittoNumber
currentHeightdittoNumber
videoWidthVideo element's width.Number
videoHeightVideo element's height.Number
controlsWhether player controls are enabled or not.Boolean
volumePlayer's volume.Number
mutedIs the player muted.Boolean
posterPlayer poster image URL.String
playingIs it playing now.Boolean
waitingIs it waiting now.Boolean
seekingA seek operation began.Boolean
pausedPlayback has been paused.Boolean
endedPlayback has stopped because the end of the media was reached.Boolean
currentTime-Number
duration-Number
playbackRate-Number
playbackRates-Array<Number>
isFullscreen-Boolean
isInPictureInPictureWhether it is picture-in-picture mode.Boolean
isLiveIs the currently playing live video.Boolean
languageVideo.js current language.String
userActive-Boolean
readyState-videojs.ReadyState
networkState-videojs.NetworkState
errorA Custom MediaError of Video.js.MediaError | Null
bufferedAn object that contains ranges of time.videojs.TimeRange
bufferedPercent-Number
played-TimeRanges
seekable-TimeRanges
textTracks-videojs.TextTrackList
audioTracks-videojs.AudioTrackList
videoTracks-videojs.VidioTrackList

Video.js extension

import videojs from 'video.js'

// Video.js plugin
const Plugin = videojs.getPlugin('plugin')
class ExamplePlugin extends Plugin {
  // do something...
}

videojs.registerPlugin('examplePlugin', ExamplePlugin)

// more Video.js operation...

Development

pnpm install

pnpm dev
pnpm dev:vue
pnpm dev:react

pnpm build
pnpm build:vue
pnpm build:react

pnpm lint
pnpm test
pnpm rebirth
pnpm release

Changelog

License

Licensed under the MIT License.