1.0.3 • Published 3 years ago

vue-flv-player v1.0.3

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

Vue-Flv-Player 播放器

NPM version GitHub stars GitHub issues GitHub forks

  • 😊 基于 Vue + flv.js 开发;
  • 😂 支持现代浏览器;

NPM安装

npm i vue-flv-player --save

CDN引用

目前可以通过 unpkg.com/vue-flv-player 或者 www.jsdelivr.com/package/npm/vue-flv-player 获取到最新版本的资源,在页面上引入 js 和 css 文件即可开始使用。

<!-- 引入组件库 -->
<script src="https://unpkg.com/vue-flv-player/dist/vue-flv-player.umd.min.js"></script>

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

使用

全局使用

// 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>

局部使用

<template>
  <div id="app">
    <vue-flv-player :autoplay="true" :controls="true" :muted="true" ref="myPlayer" :source="src"/>
  </div>
</template>

<script>
import vueFlvPlayer from 'vue-flv-player'

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

FLV

FLV例子

<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

<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>

切换类型

切换类型

<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

参数说明类型可选值默认值
source播放流string
type流类型stringmp4/flvflv
width宽度number800
height高度number600
poster视频封面string
muted是否静音booleanfalse
autoplay是否自动播放booleanfalse
controls是否显示控件booleanfalse
preload预加载stringauto/metadata/noneauto
mediaDataSource高级媒体数据源设置Object
config高级设置Object

mediaDataSource

参数说明类型可选值默认值
type流类型stringmp4/flvflv
isLive指示数据源是否为实时流boolean
cors是否为http获取启用CORSboolean
withCredentials发送跨域请求凭据boolean
hasAudio指示流是否有音频曲目boolean
hasVideo指示流是否有视频曲目boolean
duration总媒体持续时间,单位为毫秒number
filesize表示媒体文件的总文件大小number
url媒体URL,设置后覆盖 sourcestringhttps(s) / ws(s)
segments多部分播放,请参见MediaSegmentArray

MediaSegment

参数类型说明
durationnumber必填字段,表示以毫秒为单位的段持续时间
filesizenumber可选字段,表示段文件大小
urlstring必填字段,表示段文件URL

Config

参数类型默认值说明
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

更多配置,请看 flv.js 官方文档

Methods

方法名说明参数
play播放
pause暂停
dispose销毁