1.0.0 β€’ Published 3 years ago

jpvp v1.0.0

Weekly downloads
-
License
MIT
Repository
-
Last release
3 years ago

Vue-Flv-Player

NPM version GitHub stars GitHub issues GitHub forks

NPM

npm i vue-flv-player --save

CDN

Get the latest version from unpkg.com/vue-flv-player or www.jsdelivr.com/package/npm/vue-flv-player , and import JavaScript and CSS file in your page.

<script src="https://unpkg.com/vue-flv-player/dist/vue-flv-player.umd.min.js"></script>
<!-- or -->
<script src="https://cdn.jsdelivr.net/npm/vue-flv-player/dist/vue-flv-player.umd.min.js"></script>

Quick Start

// main.js
import Vue from 'vue'
import App from './App.vue'

import vueFlvPlayer from 'vue-flv-player'
Vue.use(vueFlvPlayer)
<template>
  <div id="app">
    <vue-flv-player :autoplay="true" :controls="true" :muted="true" ref="myPlayer" :source="src" />
  </div>
</template>

<script>
export default {
  name: 'App',
  data() {
    return {
      src:"http://resource.wangdaodao.com/test.flv"
    };
  }
};
</script>

FLV

FLV-demo

<template>
  <div>
    <vue-flv-player :autoplay="true" :controls="true" :muted="true" ref="myPlayer" :source="src"/>
  </div>
</template>
<script>
export default {
  data() {
    return {
      src:"http://resource.wangdaodao.com/test.flv"
    };
  }
};
</script>

MP4

MP4-demo

<template>
  <div>
    <vue-flv-player controls autoplay :muted="true" :source="src" type="mp4"/>
  </div>
</template>

<script>
export default {
  data() {
    return {
      src: "http://vjs.zencdn.net/v/oceans.mp4",
    };
  },
};
</script>

Change type

Change-type

<template>
  <div>
    <button @click="change(1)">FLV</button>
    <button @click="change(2)">MP4</button>
    <vue-flv-player controls autoplay :muted="true" :source="src" :type="type"/>
  </div>
</template>

<script>
export default {
  data() {
    return {
      type: '',
      src: '',
    };
  },
  methods: {
    change(val){
      switch (val) {
        case 1:
          this.type = 'flv';
          this.src = 'http://resource.wangdaodao.com/test.flv';
          break;
        case 2:
          this.type = 'mp4';
          this.src = 'http://vjs.zencdn.net/v/oceans.mp4';
          break;
      }
    }
  }
};
</script>

Attributes

AttributeDescriptionTypeAccepted ValuesDefault
sourcesourcestringβ€”β€”
typetypestringmp4/flvflv
widthwidthnumberβ€”800
heightheightnumberβ€”600
posterVideo coverstringβ€”β€”
mutedmutedbooleanβ€”false
autoplayautoplaybooleanβ€”false
controlscontrolsbooleanβ€”false
preloadpreloadstringauto/metadata/noneauto
mediaDataSourceMedia data source settingsObjectβ€”β€”
configadvanced settingObjectβ€”β€”

mediaDataSource

AttributeDescriptionTypeAccepted ValuesDefault
typetypestringmp4/flvflv
isLivethe data source is a live streambooleanβ€”β€”
corsIndicates whether to enable CORS for http fetchingbooleanβ€”β€”
withCredentialsIndicates whether to do http fetching with cookiesbooleanβ€”β€”
hasAudioIndicates whether the stream has audio trackbooleanβ€”β€”
hasVideoIndicates whether the stream has video trackbooleanβ€”β€”
durationIndicates total media duration, in millisecondsnumberβ€”β€”
filesizeIndicates total file size of media file, in bytesnumberβ€”β€”
urlIndicates media URL, can be starts with 'https(s)' or 'ws(s)' (WebSocket)stringhttps(s) / ws(s)β€”
segmentsOptional field for multipart playback, see MediaSegmentArrayβ€”β€”

MediaSegment

AttributeTypeDescription
durationnumberRequired field, indicates segment duration in milliseconds
filesizenumberOptional field, indicates segment file size in bytes
urlstringRequired field, indicates segment file URL

Config

AttributeTypeDefaultDescription
enableWorker?booleanfalseEnable separated thread for transmuxing (unstable for now)
enableStashBuffer?booleantrueEnable IO stash buffer. Set to false if you need realtime (minimal latency) for live stream playback, but may stalled if there's network jittering.
stashInitialSize?number384KBIndicates IO stash buffer initial size. Default is 384KB. Indicate a suitable size can improve video load/seek time.
isLive?booleanfalseSame to isLive in MediaDataSource, ignored if has been set in MediaDataSource structure.
lazyLoad?booleantrueAbort the http connection if there's enough data for playback.
lazyLoadMaxDuration?number3 * 60Indicates how many seconds of data to be kept for lazyLoad.
lazyLoadRecoverDuration?number30Indicates the lazyLoad recover time boundary in seconds.
deferLoadAfterSourceOpen?booleantrueDo load after MediaSource sourceopen event triggered. On Chrome, tabs which be opened in background may not trigger sourceopen event until switched to that tab.
autoCleanupSourceBufferbooleanfalseDo auto cleanup for SourceBuffer
autoCleanupMaxBackwardDurationnumber3 * 60When backward buffer duration exceeded this value (in seconds), do auto cleanup for SourceBuffer
autoCleanupMinBackwardDurationnumber2 * 60Indicates the duration in seconds to reserve for backward buffer when doing auto cleanup.
fixAudioTimestampGapbooleantrueFill silent audio frames to avoid a/v unsync when detect large audio timestamp gap.
accurateSeek?booleanfalseAccurate seek to any frame, not limited to video IDR frame, but may a bit slower. Available on Chrome > 50, FireFox and Safari.
seekType?string'range''range' use range request to seek, or 'param' add params into url to indicate request range.
seekParamStart?string'bstart'Indicates seek start parameter name for seekType = 'param'
seekParamEnd?string'bend'Indicates seek end parameter name for seekType = 'param'
rangeLoadZeroStart?booleanfalseSend Range: bytes=0- for first time load if use Range seek
customSeekHandler?objectundefinedIndicates a custom seek handler
reuseRedirectedURL?booleanfalseReuse 301/302 redirected url for subsequence request like seek, reconnect, etc.
referrerPolicy?stringno-referrer-when-downgradeIndicates the Referrer Policy when using FetchStreamLoader
headers?objectundefinedIndicates additional headers that will be added to request

More configuration,flv.js flv-api

Methods

MethodDescriptionParameters
playplay
pausepause
disposedispose