Vue.js Video Player
npm install @sirv/sirvjs-vue2. Register the plugin in main.jsimport SirvjsVue from '@sirv/sirvjs-vue';
app.use(SirvjsVue);3. Load Sirv JS in your HTML<script src="https://scripts.sirv.com/sirvjs/v3/sirv.js"></script>4. Add your first viewer<sirv-media-viewer
:slides="[{ src: 'https://your-account.sirv.com/shoe.jpg', type: 'zoom' }]"
></sirv-media-viewer>Put your own Sirv domain in src. No account yet? Create one freeOpen on npmShort 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:
- Streaming videos
- YouTube and Vimeo videos
- 360-degree spins and 3D models
- Zoomable images
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.
Getting started
Section titled “Getting started”1. Sign up and upload your videos
Section titled “1. Sign up and upload your videos”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.
2. Install Sirv NPM package
Section titled “2. Install Sirv NPM package”npm install @sirv/sirvjs-vue#pnpm add @sirv/sirvjs-vue#yarn add @sirv/sirvjs-vue3. Register Sirv Media Viewer as a plugin
Section titled “3. Register Sirv Media Viewer as a plugin”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');Loading Sirv JS
Section titled “Loading Sirv JS”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();})Using the component
Section titled “Using the component”There are two ways to use the Sirv Media Viewer component in your Vue app.
Add your videos to the slides array:
Section titled “Add your videos to the slides array:”The slides object accepts other props, which you can find below.
Use div options
Section titled “Use div options”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.
slides
Section titled “slides”- :id - viewer id
- :data-src - used for `*.view` files, overrides `:slides`. .view files documentation
- data-options. Full list of options.
- :slides - an Array with slide sources. Sources can be a String or an Object.
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].
Events and API
Section titled “Events and API”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 dependenciesimport { onMounted, ref } from 'vue';import { loadScript } from '@sirv/sirvjs-vue';//define the viewer and methodsconst 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 vieweronMounted(() => { 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.
