@viostream/viostream-player-vue

Vue 3 SDK for the Viostream video player — embed, control, and listen to player events
1,617
Install
npm install @viostream/viostream-player-vue
Latest Version:1.0.0
Vue:3
License:MIT
Last Updated:Oct 27, 2026
Links: npm
Maintainer: johnl123

viostream-player-vue

npm version License Downloads

Vue 3 SDK for the Viostream video player. Embed, control, and listen to player events with full TypeScript support.

Requirements

  • Vue 3.3+
  • A Viostream account key (found on the Settings > General page in Viostream)

Installation

npm install @viostream/viostream-player-vue

Quick Start

Component

Drop a <ViostreamPlayer> into any Vue component. The SDK loads the Viostream script automatically.

<script setup lang="ts">
import { ViostreamPlayer } from '@viostream/viostream-player-vue';
</script>

<template>
  <ViostreamPlayer
    account-key="vc-100100100"
    public-key="nhedxonrxsyfee"
    :display-title="true"
    :sharing="true"
    @play="console.log('playing')"
  />
</template>

Headless / Programmatic

Use createViostreamPlayer when you need full control without a component:

import { createViostreamPlayer } from '@viostream/viostream-player-vue';

const player = await createViostreamPlayer({
  accountKey: 'vc-100100100',
  publicKey: 'nhedxonrxsyfee',
  target: 'my-video-div', // element id or HTMLElement
  options: { displayTitle: true }
});

player.play();

<ViostreamPlayer> Component

Props

Required
Prop Type Description
account-key string Your Viostream account key (e.g. 'vc-100100100').
public-key string The public key of the media asset to embed.
Embed Options

All embed options are optional and passed directly to the Viostream embed API.

Prop Type Description
chapters boolean Display chapter markers.
chapter-slug string Seek to a named chapter before playback.
display-title boolean Show the video title overlay. Default: false.
hls-quality-selector boolean Show the HLS quality selector. Default: true.
player-key string Override the player theme to use.
player-style 'video' | 'audio' | 'audio-poster' The player rendering style. Default: 'video'.
sharing boolean Show sharing controls. Default: false.
skin-active string Custom skin active colour (e.g. '#ff0000'). Requires skinCustom: true.
skin-background string Custom skin background colour (e.g. '#000000'). Requires skinCustom: true.
skin-custom boolean Enable a custom skin via the API. Default: false.
skin-inactive string Custom skin inactive colour (e.g. '#cccccc'). Requires skinCustom: true.
speed-selector boolean Show playback speed selector. Default: true.
start-end-timespan string Play a specific section (e.g. '10,30').
start-time string Seek to a time (seconds) before playback.
transcript-download boolean Allow transcript download. Default: false.
use-settings-menu boolean Enable the settings menu on the control bar. Default: false.
force-aspect-ratio number Force a specific aspect ratio (e.g. 1.7778 for 16:9). Disables dynamic sizing. Must be a finite positive number; invalid values are ignored.
Events
Event Payload Fires when
@play — Playback starts or resumes.
@pause — Playback is paused.
@ended — Media finishes playing.
@time-update ViostreamTimeUpdateData Current time changes. .seconds, .duration.
@volume-change ViostreamVolumeChangeData Volume changes. .volume.
@error ViostreamErrorData An error occurs. .code, .message.
@progress ViostreamProgressData Buffering progress. .percent.
@ready — Player is ready.
@seeked — Seek operation completes.
@loaded — Metadata has loaded.
Other Props
Prop Type Description
class string CSS class applied to the outer wrapper <div>.
@player-ready (player: ViostreamPlayerInstance) => void Event providing the player instance for programmatic control.
Slots
Slot Scoped Props Description
loading — Custom content shown while the player is loading.
error { message: string } Custom error display. Receives the error message.

Getting the Player Instance

Use @player-ready to get a reference to the player for programmatic control:

<script setup lang="ts">
import { ref } from 'vue';
import { ViostreamPlayer } from '@viostream/viostream-player-vue';
import type { ViostreamPlayerInstance } from '@viostream/viostream-player-vue';

const player = ref<ViostreamPlayerInstance>();
</script>

<template>
  <ViostreamPlayer
    account-key="vc-100100100"
    public-key="nhedxonrxsyfee"
    @player-ready="(p) => (player = p)"
  />

  <button @click="player?.play()">Play</button>
  <button @click="player?.pause()">Pause</button>
</template>

Custom Loading and Error States

Use slots to replace the default loading/error UI:

<ViostreamPlayer
  account-key="vc-100100100"
  public-key="nhedxonrxsyfee"
>
  <template #loading>
    <p>Loading video...</p>
  </template>

  <template #error="{ message }">
    <div class="my-error">Something went wrong: {{ message }}</div>
  </template>
</ViostreamPlayer>

Cleanup

The player is destroyed automatically when the component unmounts. All event listeners are cleaned up and the player iframe is removed from the DOM.


createViostreamPlayer()

For use outside of Vue components or when you need full lifecycle control.

import { createViostreamPlayer } from '@viostream/viostream-player-vue';
import type { CreateViostreamPlayerOptions } from '@viostream/viostream-player-vue';

const player = await createViostreamPlayer({
  accountKey: 'vc-100100100',
  publicKey: 'nhedxonrxsyfee',
  target: 'my-video-div',       // element id (string) or HTMLElement
  options: {
    displayTitle: true,
    sharing: true,
    speedSelector: true
  }
});

Options

Property Type Description
accountKey string Your Viostream account key.
publicKey string Public key of the media asset.
target string | HTMLElement Container element id or direct DOM reference.
options ViostreamEmbedOptions Embed options (same as component props above).

Player Instance API

Both the component (via @player-ready) and createViostreamPlayer() provide a ViostreamPlayerInstance with the following methods.

Playback Controls

player.play();
player.pause();
player.mute();
player.unmute();
player.setVolume(0.5);          // 0 to 1
player.setLoop(true);
player.setCurrentTime(30);      // seek to 30 seconds
player.setCurrentTime(30, true); // seek and auto-play
player.reload();                // reload the player
player.reload({ key: 'value' }); // reload with new settings

Getters (Promise-based)

All getters return promises. The SDK converts the underlying callback-based API to async/await.

const volume    = await player.getVolume();          // number (0-1)
const loop      = await player.getLoop();            // boolean
const time      = await player.getCurrentTime();     // number (seconds)
const paused    = await player.getPaused();          // boolean
const duration  = await player.getDuration();        // number (seconds)
const muted     = await player.getMuted();           // boolean
const ratio     = await player.getAspectRatio();     // number
const height    = await player.getHeight();          // number (pixels)

Events

Subscribe to player events with on(). It returns an unsubscribe function.

// Subscribe
const unsubscribe = player.on('timeupdate', (data) => {
  console.log(`${data.seconds}s / ${data.duration}s`);
});

// Unsubscribe later
unsubscribe();

// Or use off() directly
const handler = () => console.log('paused');
player.on('pause', handler);
player.off('pause', handler);
Available Events
Event Callback Data Description
play void Playback started or resumed.
pause void Playback paused.
ended void Media finished playing.
timeupdate { seconds: number, duration: number } Playback time changed.
volumechange { volume: number } Volume changed.
error { code?: number, message?: string } Error occurred.
progress { percent: number } Buffering progress.
ready void Player is ready.
seeked void Seek completed.
loaded void Metadata loaded.

Custom event names are also accepted via the string index signature:

player.on('my-custom-event', (data) => {
  console.log(data);
});

Destroy

When using createViostreamPlayer(), you are responsible for cleanup:

player.destroy();

After calling destroy():

  • All event listeners are removed.
  • The player iframe is removed from the DOM.
  • Getter calls will reject with "Player has been destroyed".

TypeScript

Every export is fully typed. Import types alongside runtime exports:

import { ViostreamPlayer, createViostreamPlayer } from '@viostream/viostream-player-vue';
import type {
  ViostreamPlayerInstance,
  ViostreamPlayerProps,
  ViostreamPlayerEventProps,
  ViostreamEmbedOptions,
  ViostreamTimeUpdateData,
  ViostreamVolumeChangeData,
  ViostreamErrorData,
  ViostreamProgressData,
  ViostreamPlayerEventMap,
  ViostreamEventHandler,
  CreateViostreamPlayerOptions,
} from '@viostream/viostream-player-vue';

Full Example

A complete example showing the component with custom controls, event logging, and async getters:

<script setup lang="ts">
import { ref, computed } from 'vue';
import { ViostreamPlayer } from '@viostream/viostream-player-vue';
import type {
  ViostreamPlayerInstance,
  ViostreamTimeUpdateData,
} from '@viostream/viostream-player-vue';

const player = ref<ViostreamPlayerInstance>();
const currentTime = ref(0);
const duration = ref(0);
const paused = ref(true);
const log = ref<string[]>([]);

function addLog(msg: string) {
  log.value = [msg, ...log.value.slice(0, 49)];
}

function handleReady(p: ViostreamPlayerInstance) {
  player.value = p;
  p.getDuration().then((d) => (duration.value = d));
}

function handleTimeUpdate(data: ViostreamTimeUpdateData) {
  currentTime.value = data.seconds;
  duration.value = data.duration;
}

function format(s: number): string {
  return `${Math.floor(s / 60)}:${Math.floor(s % 60).toString().padStart(2, '0')}`;
}
</script>

<template>
  <ViostreamPlayer
    account-key="vc-100100100"
    public-key="nhedxonrxsyfee"
    :display-title="true"
    :sharing="true"
    :speed-selector="true"
    :hls-quality-selector="true"
    @play="() => { paused = false; addLog('play'); }"
    @pause="() => { paused = true; addLog('pause'); }"
    @ended="() => addLog('ended')"
    @time-update="handleTimeUpdate"
    @player-ready="handleReady"
  />

  <div>
    <button @click="paused ? player?.play() : player?.pause()">
      {{ paused ? 'Play' : 'Pause' }}
    </button>
    <button @click="player?.setCurrentTime(0)">Restart</button>
    <span>{{ format(currentTime) }} / {{ format(duration) }}</span>
  </div>

  <div>
    <button @click="async () => {
      const vol = await player?.getVolume();
      addLog(`volume: ${vol}`);
    }">Get Volume</button>
  </div>

  <pre>{{ log.join('\n') }}</pre>
</template>

Development

# Install dependencies
npm install

# Build (compile and bundle to dist/)
npm run build

# Type-check
npm run check

# Run tests
npm run test

# Run tests in watch mode
npm run test:watch

License

MIT

Related Packages

v3d-player

Vue3 Dplayer-Lite

2,588 5
v3d-monitor

Vue3 Multi-window video player

2,371 1
embedplay-tiktok-vue

This package provides a flexible and easy way to integrate TikTok videos into yo...

3,810 2

Version History

Version Released Vue License
1.0.0 ^3.3.0 MIT
0.2.10 ^3.3.0 MIT
0.2.9 ^3.3.0 MIT
0.2.8 ^3.3.0 MIT
0.2.7 ^3.3.0 MIT