Vue Video.js Player
vue-video-player is a package that provides a Vue component for integrating the Video.js player into applications. Version 6.0.0 is the final release under this specific package name and functions primarily as a re-export of the newly named `@videojs-player/vue` package. The project has undergone a significant architectural change, now offering distinct packages for Vue and React (with `@videojs-player/react`). The current stable version for Vue 3 is `@videojs-player/vue@1.x`. This library exclusively supports Vue 3, with Vue 2 support remaining in the legacy `vue-video-player@4.x` branch. It differentiates itself by offering responsive design, extensive customization options for the control panel, and internal processing designed to abstract framework-specific complexities, aiming for a robust and flexible video integration solution.
Common errors
-
Module not found: Error: Can't resolve 'vue-video-player'
cause The package has been renamed to `@videojs-player/vue`. You are trying to import from the old package name or have not installed the new one.fixInstall the new package (`npm install @videojs-player/vue`) and update your import statements from `vue-video-player` to `@videojs-player/vue`. -
[Vue warn]: Failed to resolve component: VideoPlayer
cause This typically occurs when using `@videojs-player/vue` (or `vue-video-player@6`) in a Vue 2 application, or if the component is not correctly imported and registered in a Vue 3 setup.fixVerify that your application is running Vue 3. Ensure `VideoPlayer` is correctly imported with `import { VideoPlayer } from '@videojs-player/vue';` and included in your component's template. -
Video player appears unstyled, controls are missing, or layout is broken.
cause The required CSS files for Video.js and the wrapper component are not being loaded.fixEnsure that `import 'video.js/dist/video-js.css';` and `import '@videojs-player/vue/dist/index.css';` are present in your application's entry point or the component where `VideoPlayer` is used.
Warnings
- breaking The `vue-video-player` package has been renamed to `@videojs-player/vue`. Version 6.0.0 of `vue-video-player` only re-exports the new package and is considered the final release under the old name. Future development and features will be in `@videojs-player/vue`.
- breaking Support for Vue 2 has been dropped. The `vue-video-player@6.0.0` and `@videojs-player/vue` packages are exclusively compatible with Vue 3. Using them with Vue 2 will result in errors.
- gotcha The essential Video.js base CSS and `@videojs-player/vue` component-specific CSS must be manually imported into your application. Without these, the player controls may be missing, or the styling will be incorrect.
- gotcha The core `video.js` library and its TypeScript type definitions (`@types/video.js`) are peer dependencies. They must be explicitly installed alongside `@videojs-player/vue` for the component to function correctly and for TypeScript projects to compile without errors.
Install
-
npm install vue-video-player -
yarn add vue-video-player -
pnpm add vue-video-player
Imports
- VideoPlayer
import VideoPlayer from '@videojs-player/vue'
import { VideoPlayer } from '@videojs-player/vue' - video.js/dist/video-js.css
import 'video.js/dist/video-js.css'
- @videojs-player/vue/dist/index.css
import '@videojs-player/vue/dist/index.css'
Quickstart
<template>
<div class="video-container">
<h1>My Custom Video Player</h1>
<VideoPlayer :options="playerOptions" />
</div>
</template>
<script setup lang="ts">
import { reactive } from 'vue';
import { VideoPlayer } from '@videojs-player/vue';
import 'video.js/dist/video-js.css'; // Core Video.js CSS
import '@videojs-player/vue/dist/index.css'; // Component-specific CSS
// Basic player options (customize as needed)
const playerOptions = reactive({
autoplay: true,
controls: true,
responsive: true,
fluid: true, // Scales the player to fill the width of the container
sources: [
{
src: 'https://cdn.plyr.io/static/demo/earth.mp4',
type: 'video/mp4',
},
],
// You can add more Video.js options here, e.g., poster, language, etc.
// Example: poster: 'your-poster-image.jpg'
});
</script>
<style scoped>
.video-container {
max-width: 900px; /* Example: Constrain player width */
margin: 20px auto;
background-color: #f0f0f0;
padding: 10px;
border-radius: 8px;
box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
}
h1 {
text-align: center;
color: #333;
margin-bottom: 20px;
}
</style>