Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@byteark/byteark-player-vue

Package Overview
Dependencies
Maintainers
0
Versions
40
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@byteark/byteark-player-vue

ByteArk Player Container for Vue

  • 4.1.2
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

ByteArk Player Container for Vue.js

NPM

Table of Contents

Demo

You can try on the demo page.

Features

  • Remote player updates. No need to update your code for minor improvements.
  • Show placeholder while waiting the player to be ready.
  • Controls basic behaviours via props.
  • Custom advanced callbacks to access ByteArk Player/VideoJS instance directly.

Compatibility

Since Vue 3 is not backward compatible, please make sure to install the correct ByteArk Player Container version based on your Vue version.

Vue VersionPackage VersionBranch
2.x3.xmaster
3.x4.xmain

Installation

This library is distributed via NPM. You may install from NPM, Yarn, PNPM.

# For NPM
npm install --save @byteark/byteark-player-vue
# For Yarn
yarn add @byteark/byteark-player-vue
# For PNPM
pnpm add @byteark/byteark-player-vue

Usage

  1. Include and register ByteArkPlayerContainer in your project.
<template>
  <ByteArkPlayerContainer
    :options="playerOptions"
  />
</template>

<script setup lang="ts">
import ByteArkPlayerContainer from '@byteark/byteark-player-vue';
import type { ByteArkPlayerOptions } from '@byteark/byteark-player-vue';

const playerOptions: ByteArkPlayerOptions = {
  autoplay: 'any',
  fluid: true,
  aspectRatio: '16:9',
  poster: 'https://stream-image.byteark.com/image/video-cover-480p/7/K/7KPloVWgN.png',
  sources: [{
    src: 'https://byteark-playertzxedwv.stream-playlist.byteark.com/streams/TZyZheqEJUwC/playlist.m3u8',
    type: 'application/x-mpegURL',
    title: 'Big Buck Bunny',
    videoId: 'TZyZheqEJUwC',
    poster: 'https://stream-image.byteark.com/image/video-cover-480p/7/K/7KPloVWgN.png',
  }]
};
</script>
  1. Include stylesheet in your project
// Inside your main SCSS file
@import '~@byteark/byteark-player-vue/dist/@byteark/byteark-player-vue.css';

// Or inside the component
<style lang="scss" scoped>
@import '~@byteark/byteark-player-vue/dist/@byteark/byteark-player-vue.css';
</style>

In case that you want to display videos inside a fix-sized container, use fill layout mode by passing fill: true in the player options.

playerOptions: {
  ...options,
  fill: true,
},

ByteArkPlayerContainer Props

Following properties are the properties that can be updated to the ByteArkPlayerContainer.

NameTypeDefaultDescription
optionsByteArkPlayerOptions-An options pass to ByteArk Player (See ByteArk Player Options Object)
customClassString-Add custom css class to ByteArkPlayerContainer component
lazyloadBoolean-The player loads its asset files once it got rendered on the webpage. By passing this prop, the player then loads its asset files once the user clicked on the player instead.
playerEndpointString-Endpoint to the video player (without version part).
playerSlugIdString-SlugId of player created via api player server service
playerVersionStringv2Custom version of the player.
playerJsFileNameStringFile name of player's JS.
playerCssFileNameStringFile name of player's CSS.
setupPlayerFunction(options: ByteArkPlayerOptions, loadScriptOrStyleFunction: (id: string, url: string, type: 'script' | 'style') => Promise-This function call to before create player function
createPlayerFunction(node: HTMLMediaElement, options: ByteArkPlayerOptions, onReady: () => void) => ByteArkPlayer-This function should return a VideoJS's player instance.
onPlayerLoaded() => void-Callback function to be called when loaded player's resources.
onPlayerLoadError(error: ByteArkPlayerContainerError, originalError: ByteArkPlayerError | unknown) => void-Callback function to be called when there're an error about loading player.
onPlayerSetup() => void-Callback function to be called when player is setup.
onPlayerSetupError(error: ByteArkPlayerContainerError, originalError: ByteArkPlayerError | unknown) => void-Callback function to be called when there're an error when setup player.
onPlayerCreated(player: ByteArkPlayer) => void-Callback function to be called when a player instance is created.
onPlayerReady(player: ByteArkPlayer) => void-Callback function to be called when a player instance is ready.

ByteArk Player Options

You have to pass options object to ByteArkPlayerContainer in order to create ByteArk Player instance.

NameTypeDefaultDescription
autoplayBoolean/String-Autoplay the video after the player is created. (Seee VideoJS's autoplay options)
aspectRatioString-Use with fluid layout mode, to inform expected video's aspect ratio
controlsBooleantrueShow the controls bar.
fillBoolean-Use fill layout mode.
fluidBoolean-Use fluid layout mode.
loopBoolean-Replay the video after ending
mutedBoolean-Play the video without sounds.
playbackRateNumber1.0Playback speed. 1.0 means original speed.
playsinlineBooleantrueShould be true so custom controls available on all platforms, including iOS.
posterString-Image to show before playing the video.
preloadString-Preload the video before playing. (none / metadata / auto)
responsiveBoolean-Auto show/hide controls depending on the screen size.
seekButtonsBoolean-Show 10 seconds seek buttons and allow double-tap to seek on mobile.
sourcesArray-Array of video source object to be played. (See Source Object)
volumeNumber-Video's volume between 0 and 1.
pluginsArray-Videojs's plugins

You can also use other props not listed here, but appear as VideoJS's options. However, changing props will not effective after the player is created.

Source Object

The sources object has 2 required fields.

NameTypeRequiredDescription
srcStringtrueURL to the video.
typeStringtrueVideo content type.
titleStringfalseVideo title to display on the player.
videoIdStringfalseVideo's ID, usually used by analytical applications.
posterStringfalseImage to show before playing the video.

To provide multiple version of sources, you can use array of source objects.

Event Handling

ByteArkPlayerContainer emits events that you can use to trigger your custom functions.

Event NameCallback ParametersTrigger Condition
loaded-When loaded player's resources.
loaderror(error: ByteArkPlayerContainerError, originalError: ByteArkPlayerError | unknown): voidWhen there're an error about loading player's resources.
setup-When player is setup.
setuperror(error: ByteArkPlayerContainerError, originalError: ByteArkPlayerError | unknown): voidWhen there're an error when setup player.
created(player: ByteArkPlayer)When the player instance was created.
ready(player: ByteArkPlayer)When the player instance was ready to play.
firstplay(player: ByteArkPlayer)When the video played for the first time.
play(player: ByteArkPlayer, currentTime: number)When the video played or the user hit play. (Value of currentTime is a number in seconds)
pause(player: ByteArkPlayer, currentTime: number)When the video played or the user hit pause. (Value of currentTime is a number in seconds)
ended(player: ByteArkPlayer)When the video ended.
timeupdate(player: ByteArkPlayer, currentTime: number)When the current playback time changed. (Value of currentTime is a number in seconds)
seeking(player: ByteArkPlayer, currentTime: number)When the the user seeked the video. (Value of currentTime is a number in seconds)
seeked(player: ByteArkPlayer, currentTime: number)When the the user seeked the video. (Value of currentTime is a number in seconds)
waiting(player: ByteArkPlayer)When the player is waiting for the video.
stalled(player: ByteArkPlayer)When the player is waiting for the video.
fullscreenchange(player: ByteArkPlayer, isFullscreen: boolean)When the user entered or exited the full screen mode. (Value of isFullscreen is True or False)
volumechange(player: ByteArkPlayer, volume: number)When the user adjusted the volume. (Value of volume is between 0 - 1)
ratechange(player: ByteArkPlayer, playbackSpeed: number)When the user adjusted the playback speed. (Value of playbackSpeed is a number)
enterpictureinpicture(player: ByteArkPlayer)When the user entered Picture-in-Picture mode.
leavepictureinpicture(player: ByteArkPlayer)When the user exited Picture-in-Picture mode.
error(error: ByteArkPlayerError | MediaError | unknown | null)When there was an error while loading player.

For an example of implementing these events, please see Controlling Players Section.

Advanced Usages

Controlling Players

You may access the player instance from onReady callback parameter.

<template>
  <ByteArkPlayerContainer
    @ready="onReady"
    @firstplay="onFirstPlay"
    @play="onPlay"
    @pause="onPause"
    @ended="onVideoEnded"
    @timeupdate="onTimeUpdated"
    @seeking="onVideoSeeking"
    @seeked="onVideoSeeked"
    @fullscreenchange="onToggleFullScreen"
    @volumechange="onVolumeChange"
    @ratechange="onPlaybackSpeedChanged"
    @enterpictureinpicture="onPIPEntered"
    @leavepictureinpicture="onPIPExited"
    :options="playerOptions" />
  <button @click="player.value?.play()">Play</button>
  <button @click="player.value?.pause()">Pause</button>
</template>

<script setup lang="ts">
import { ref } from 'vue'
import ByteArkPlayerContainer from '@byteark/byteark-player-vue'
import type { ByteArkPlayerOptions, ByteArkPlayer } from '@byteark/byteark-player-vue'

const playerRef = ref<ByteArkPlayer | null>(null)

const playerOptions: ByteArkPlayerOptions = {
  autoplay: 'any',
  fluid: true,
  aspectRatio: '16:9',
  poster: 'https://stream-image.byteark.com/image/video-cover-480p/7/K/7KPloVWgN.png',
  sources: [{
    src: 'https://byteark-playertzxedwv.stream-playlist.byteark.com/streams/TZyZheqEJUwC/playlist.m3u8',
    type: 'application/x-mpegURL',
    title: 'Big Buck Bunny',
    videoId: 'TZyZheqEJUwC',
    poster: 'https://stream-image.byteark.com/image/video-cover-480p/7/K/7KPloVWgN.png',
  }]
}

const onReady = (player: ByteArkPlayer) => {
  // The player is ready! save player instance
  playerRef.value = player
}

const onFirstPlay = (player: ByteArkPlayer) => {
  // Do something...
}

const onPlay = (player: ByteArkPlayer, currentTime: number) => {
  // Do something...
}

const onPause = (player: ByteArkPlayer, currentTime: number) => {
  // Do something...
}

const onVideoEnded = () => {
  // Do something...
}

const onTimeUpdated = (player: ByteArkPlayer, currentTime: number) => {
  // Do something...
}

const onVideoSeeking = (player: ByteArkPlayer, currentTime: number) => {
  // Do something...
}

const onVideoSeeked = (player: ByteArkPlayer, currentTime: number) => {
  // Do something...
}

const onToggleFullScreen = (player: ByteArkPlayer, isFullscreen: boolean) => {
  // Do something...
}

const onVolumeChange = (player: ByteArkPlayer, volume: number) => {
  // Do something...
}

const onPlaybackSpeedChanged = (player: ByteArkPlayer, playbackSpeed: number) => {
  // Do something...
}

const onPIPEntered = (player: ByteArkPlayer,) => {
  // Do something...
}

const onPIPExited = (player: ByteArkPlayer,) => {
  // Do something...
}
</script>

Using VideoJS Plugins

<template>
  <ByteArkPlayerContainer
    @ready="onReady"
    :options="playerOptions"
  />
</template>

<script setup lang="ts">
import ByteArkPlayerContainer from '@byteark/byteark-player-vue'
import type { ByteArkPlayerOptions, ByteArkPlayer } from '@byteark/byteark-player-vue'

const playerOptions: ByteArkPlayerOptions = {
  autoplay: 'any',
  fluid: true,
  aspectRatio: '16:9',
  poster: 'https://stream-image.byteark.com/image/video-cover-480p/7/K/7KPloVWgN.png',
  sources: [{
    src: 'https://byteark-playertzxedwv.stream-playlist.byteark.com/streams/TZyZheqEJUwC/playlist.m3u8',
    type: 'application/x-mpegURL',
    title: 'Big Buck Bunny',
    videoId: 'TZyZheqEJUwC',
    poster: 'https://stream-image.byteark.com/image/video-cover-480p/7/K/7KPloVWgN.png',
  }]
}

const onReady = (player: ByteArkPlayer) => {
  // The player is ready! Initialize plugins here.
  player.somePlugin()
}
</script>

Request Media/Encryption with credentials

<template>
  <ByteArkPlayerContainer
    :options="playerOptions"
  />
</template>

<script setup lang="ts">
import ByteArkPlayerContainer from '@byteark/byteark-player-vue'
import type { ByteArkPlayerOptions, ByteArkPlayer } from '@byteark/byteark-player-vue'

const playerOptions: ByteArkPlayerOptions = {
  autoplay: 'any',
  fluid: true,
  aspectRatio: '16:9',
  poster: 'https://stream-image.byteark.com/image/video-cover-480p/7/K/7KPloVWgN.png',
  sources: [{
    src: 'https://byteark-playertzxedwv.stream-playlist.byteark.com/streams/TZyZheqEJUwC/playlist.m3u8',
    type: 'application/x-mpegURL',
    title: 'Big Buck Bunny',
    videoId: 'TZyZheqEJUwC',
    poster: 'https://stream-image.byteark.com/image/video-cover-480p/7/K/7KPloVWgN.png',
  }],
  html5: {
    hlsjs: {
      xhrSetup: function(xhr, url) {
        xhr.withCredentials = true;
      },
    },
  },
}
</script>

License

MIT © ByteArk Co. Ltd.

FAQs

Package last updated on 13 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc