Skip to content

Vue.js Video Player

By , Head of Sirv StudioUpdated

Open this page in a new chat

Short answer

Upload your videos to Sirv, then install the @sirv/sirvjs-vue npm package, register Sirv Media Viewer as a plugin and load Sirv JS. Add your videos to the component's slides array and set player options in the div or as props. The player streams Sirv videos and can also show YouTube and Vimeo videos alongside images and spins.

After reading this you will know

  • How to add a video player to a Vue app
  • Which video types the player supports
  • How to set player options with props and div options

The Sirv Media Viewer component for Vue simplifies embedding media into your applications. You can easily integrate many types of media:

The component allows you to create rich media galleries by combining those different media types into a single gallery viewer.

Sirv Media Viewer supports all kinds of image and video formats, with options to customize the appearance and behavior of the embedded content.

Some key video features of Sirv Media Viewer include:

  • Adaptive bitrate streaming for smooth video playback
  • Intuitive API for easy integration into Vue apps
  • Customizable UI to match your app’s branding
  • Cross-device compatibility
  • Automatic schema markup generation for better SEO

With its comprehensive functionality and seamless integration, Sirv Media Viewer streamlines the process of adding engaging multimedia experiences to your Vue applications.

View on StackBlitz.

Sign up for a Sirv account, you’ll automatically start a free trial (no credit card required). Then upload your videos and enable video streaming.

npm install @sirv/sirvjs-vue
#pnpm add @sirv/sirvjs-vue
#yarn add @sirv/sirvjs-vue
main.js
import { createApp } from 'vue';
import App from './App.vue';
import SirvjsVue from '@sirv/sirvjs-vue';
const app = createApp(App);
app.use(SirvjsVue);
app.mount('#app');

You can load the Sirv Media Viewer script in your HTML:

<script src="https://scripts.sirv.com/sirvjs/v3/sirv.js"></script>

If you need finer control, use the loadScript module:

import { loadScript } from '@sirv/sirvjs-vue';
loadScript().then((sirv) => {
sirv.start();
})

There are two ways to use the Sirv Media Viewer component in your Vue app.

The slides object accepts other props, which you can find below.

Alternatively, you can use the component by adding each element of the gallery as a div, for example:

You can apply data types and data options in the div itself. You can find all the options in the Sirv Media Viewer Image Zoom documentation.

String accepts a URL e.g. https://demo.sirv.com/video.mp4.

An Object has additional props:

  • id - Slide id [String]
  • src - Source [String]
  • dataOptions - Local slide options [Object]
  • type - Type of slide [String]. The available props are: `spin`, `zoom`, `image`, `model`, `youtube`, `vimeo`, `video`, `html`
  • dataThumbnailImage - Custom thumbnail image [String]
  • dataThumbnailHtml - Custom thumbnail html [String]
  • dataDisabled - Disable slide [Boolean]
  • dataSwipeDisabled - Disable slide swipe [Boolean]
  • dataHiddenSelector - Hide selector [Boolean]
  • dataPinned - Pinned selector [String]. The available props are: `left`, `right`
  • staticImage - Static image [Boolean].

Full list of API methods and Events.

Here’s a sample component that utilizes the next and previous methods to control the Sirv Media Viewer slides.

<template>
<sirv-media-viewer :id="id" :slides="[
{
src: 'https://demo.sirv.com/video.mp4',
type: 'video',
dataOptions: {
autoplay: 'true',
},
},
{
src: 'https://demo.sirv.com/videos/e-tron_quattro.mp4',
type: 'video',
},
{
src: 'https://demo.sirv.com/demo/303/testing.mp4',
type: 'video',
},
{
src: 'https://www.youtube.com/watch?v=svK_DnHu-7I',
type: 'youtube',
},
{
src: 'https://vimeo.com/76979871',
type: 'vimeo',
},
]"></sirv-media-viewer>
</template>
<script setup="">
//import dependencies
import { onMounted, ref } from 'vue';
import { loadScript } from '@sirv/sirvjs-vue';
//define the viewer and methods
const viewer = ref(null);
const id = ref('smv-test');
const prev = () => {
if (viewer.value) {
viewer.value.prev();
}
};
const next = () => {
if (viewer.value) {
viewer.value.next();
}
};
//load Sirv JS after the app is mounted, start SMV and define the viewer
onMounted(() => {
loadScript().then((sirv) => {
sirv.start();
sirv.on('viewer:ready', (e) => {
if (e.id === 'smv-test') {
viewer.value = e;
console.log('viewer:ready', e);
}
});
});
});
</script>

When the viewer is ready, you can control the video from your Vue.js code.

Back to top