@dongido/vue-viaudio

中文文档
0.3.5发布于 2019/09/16ISCCommonJS近 30 天下载 2282

A package that helps you dynamically/reactively render video and audio elements in Vue.js

原始使用文档
文档目录19 节
  1. Project setup
  2. Example Usage
  3. Basic usage - Play a video ( :src )
  4. Basic usage - Play an audio
  5. Play a video - WebRTC example ( :srcObject )
  6. A bit advanced usage - with events
  7. Media sources
  8. Properties - supports all Video and Audio Element propertie…
  9. Video Events
  10. Audio Events
  11. Contribute
  12. [0.2.4] - 2019-04-10
  13. Added
  14. Changed
  15. Removed
  16. [0.3.2] - 2019-07-16
  17. Fixes
  18. Changed
  19. Removed

vue-viaudio

Dynamically/Reactively render videos and audios.

Project setup

Install the package:

Using npm

  npm i @dongido/vue-viaudio

OR Using yarn

  yarn add @dongido/vue-viaudio

On the browser

<script src="https://cdn.jsdelivr.net/npm/@dongido/[email protected]/dist/vue-viaudio.umd.js"></script>

Demos

Example Usage

Basic usage - Play a video (:src)

<script>
import Media from '@dongido/vue-viaudio'

export default {
  name: 'app',
  components: {
    Media
  },
}
</script>

<template>
  <div id="app">
    <Media 
      :kind="'video'"
      :controls="true"
      :src="['https://www.w3schools.com/html/mov_bbb.mp4']"
    >
    </Media>
  </div>
</template>

Basic usage - Play an audio

<script>
import Media from '@dongido/vue-viaudio'

export default {
  name: 'app',
  components: {
    Media
  },
}
</script>

<template>
  <div id="app">
    <Media 
      :kind="'audio'"
      :controls="true"
      :src="['https://www.w3schools.com/html/mov_bbb.mp4']"
    >
    </Media>
  </div>
</template>

Play a video - WebRTC example (:srcObject)

<template>
  <div class="example">
    <Media
      :kind="'video'"
      :srcObject="streamObject"
      autoplay
      playinline
    />
  </div>
</template>

<script>
import Media from './vue-viaudio'
import { setTimeout } from 'timers';

export default {
  components: {
   Media
  },
  name: 'Example',
  data() {
    return {
      streamObject: {}
    }
  },
  mounted() {
    navigator.mediaDevices
      .getUserMedia({ video: true, audio: false })
      .then(stream => {
        this.streamObject = stream;
      })
      .catch(function(err) {
        console.log("An error occurred: " + err);
      })
  },
}
</script>

A bit advanced usage - with events

<template>
  <div id="app">
    <Media 
      :kind="'video'"
      :muted="(false)"
      :src="['https://www.w3schools.com/html/mov_bbb.mp4']"
      :poster="'https://peach.blender.org/wp-content/uploads/title_anouncement.jpg?x11217'"
      :autoplay="true"
      :controls="true"
      :loop="true"
      :ref="'fish'"
      :style="{width: '500px'}"
      @pause="handle()"
    >
    </Media>
  </div>
</template>

<script>
import Media from '@dongido/vue-viaudio'

export default {
  name: 'app',
  components: {
    Media
  },
  methods: {
    handle() {
      console.log('Video paused!, playing in 2 sec...')

      setTimeout( () => {
        this.$refs.fish.play() 
      }, 2000)
    }
  }
}
</script>

<style>
#app {
  width: 100%;
  text-align: center;
  margin-top: 40vh;
}
</style>

Media sources

This package can accept its source of media from either the :src or :srcObject property.

The src property can be either a string or an array.

The :srcObject is particularly useful when you need to render a stream source like from WebRTC.

Properties - supports all Video and Audio Element properties.

| Props | Required | Description | | ------------------------ | --------------------------------------- | ------------------------- | | src [Array or String ] | True (if srcObject is not provided) | The source of the media | | srcObject [Object] | True (if src is not provided) | The source of the media | | kind [String] | True | It's either audio or video. | | muted [String] | False | Determines if a video will be muted or not. It's either true or false. |

It accepts all video and audio attributes. You just need to pass the one you need. You can also bind them if you need some reactivity.

Video Events

You can listen to video element events when they happen. These events are available when you pass the prop kind as video.

| Events | Description | | ---------------- | ------------------------- | | canplay | The browser can play the media | | canplaythrough | The browser estimates it can play the media up to its end without stopping for content buffering.| | complete | The rendering of an OfflineAudioContext is terminated.| | durationchange | The duration attribute has been updated.| | emptied | The media has become empty| | ended | Playback has stopped because the end of the media was reached.| | loadeddata | The first frame of the media has finished loading.| | pause | Playback has been paused.| | play | Playback has begun.| | loadedmetadata | The metadata has been loaded.| | playing | Playback is ready to start after having been paused or delayed due to lack of data.| | ratechange | The playback rate has changed.| | seeked | A seek operation completed. | seeking | A seek operation began.| | stalled | The user agent is trying to fetch media data, but data is unexpectedly not forthcoming.| | suspend | Media data loading has been suspended. | | timeupdate | The time indicated by the currentTime attribute has been updated.| | volumechange | Trggers when volume has changed.| | waiting | Triggers when the media has stoped playing because of temproray lack of data|

You can read more about these events here.

Example usage

Assuming, you want to listen to when the user pauses a video. You can do that using:

<script>
import Media from '@dongido/vue-viaudio'

export default {
  name: 'app',
  components: {
    Media
  },
  methods: {
    handlePauseEvent() {
      console.log('The video is now paused.')
    }
  }
}
</script>

<template>
  <div id="app">
    <Media 
      :kind="'video'"
      :controls="true"
      :src="'https://www.w3schools.com/html/mov_bbb.mp4'"
      @pause="handlePauseEvent()" // The event
    >
    </Media>
  </div>
</template>

Audio Events

You can also listen to audio element events when they happen. These events are available when you pass the prop kind as audio. You can listen to it same way as the video events.

You can read about these events here.

Contribute

GitHub

Changelog

Notable changes:

[0.2.4] - 2019-04-10

Added

  • Added srcObject props use-case using WebRTC.

Changed

  • Updated the props required types
  • Fix srcObject that was not working

Removed

[0.3.2] - 2019-07-16

Fixes

  • StreamObject not playing by default

Changed

  • isMuted props is now muted

Removed

版本与发布记录

@dongido/vue-viaudio 共发布 17 个版本,首次发布于 2019/05/02;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.3.5latest2019/09/167 年前
0.3.42019/08/247 年前
0.3.32019/08/247 年前
0.3.22019/07/187 年前
0.3.12019/07/187 年前
0.3.02019/07/187 年前

关于 @dongido/vue-viaudio 的常见问题

@dongido/vue-viaudio 是什么?

A package that helps you dynamically/reactively render video and audio elements in Vue.js

如何安装 @dongido/vue-viaudio?

在项目目录运行 npm install @dongido/vue-viaudio,或使用 pnpm add / yarn add / bun add。

@dongido/vue-viaudio 支持 TypeScript 吗?

该包的 package.json 没有声明类型入口。需要类型提示时,可以在 npm 上查找社区维护的 @types/dongido__vue-viaudio 是否存在。

@dongido/vue-viaudio 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@dongido/vue-viaudio 可以商用吗?

@dongido/vue-viaudio 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@dongido/vue-viaudio 的下载量有多少?

根据 npm 官方下载统计,@dongido/vue-viaudio 在 2026/10/13 – 2026/11/11 这 30 天内被下载 2,282 次,日均约 76 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@dongido/vue-viaudio 还在维护吗?

最新版本 0.3.5 发布于 2019/09/16(7 年前);至今共发布 17 个版本,其中过去 12 个月发布了 0 个;首次发布于 2019/05/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。