New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@liripeng/vue-audio-player

Package Overview
Dependencies
Maintainers
1
Versions
58
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@liripeng/vue-audio-player

适用于 PC 移动端的 Vue 音频播放器组件

  • 1.1.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
3.7K
increased by8.46%
Maintainers
1
Weekly downloads
 
Created
Source

Vue音频播放器组件

npm version Build Status


在线预览

点我在线预览

特性

  • 完善的文档和示例
  • 支持进度条拖拽(PC 端需引入一个库模拟 Touch 事件,教程
  • 原生 CSS,无须引入 Less、Scss 等预编译语言

安装

npm i -S @liripeng/vue-audio-player

按需引入

import { AudioPlayer } from '@liripeng/vue-audio-player'
import '@liripeng/vue-audio-player/lib/vue-audio-player.css'

components: {
  AudioPlayer
}

全局引入

import AudioPlayer from '@liripeng/vue-audio-player'
import '@liripeng/vue-audio-player/lib/vue-audio-player.css'

Vue.use(AudioPlayer)

使用

<template>
  <div>
    {{ currentAudioName || audioList[0].name }}
    <audio-player
      ref="audioPlayer"
      :audio-list="audioList.map(elm => elm.url)"
      :before-play="handleBeforePlay"
    />
  </div>
</template>

<script>
import { AudioPlayer } from '@liripeng/vue-audio-player'
import '@liripeng/vue-audio-player/lib/vue-audio-player.css'

export default {
  components: {
    AudioPlayer
  },

  data() {
    return {
      currentAudioName: '',
      audioList: [
        {
          name: '音频1',
          url: 'https://www.0dutv.com/upload/dance/F25F74A0B8FF82503241801D0E2CA5CD.mp3'
        },
        {
          name: '音频2',
          url: 'https://www.0dutv.com/upload/dance/20200316/C719452E3C7834080007662021EA968E.mp3'
        }
      ]
    }
  },

  methods: {
    // 播放前做的事
    handleBeforePlay(next) {
      // 这里可以做一些事情...
      this.currentAudioName = this.audioList[this.$refs.audioPlayer.currentPlayIndex].name

      next() // 开始播放
    }
  }
}
</script>

Prop

参数说明类型默认值
audio-list音频播放列表Array-
show-play-button是否显示播放按钮Booleantrue
show-prev-button是否显示上一首按钮Booleantrue
show-next-button是否显示下一首按钮Booleantrue
show-volume-button是否显示音量按钮Booleantrue
show-progress-bar是否显示进度条Booleantrue
isLoop是否列表循环播放Booleantrue
progressInterval进度更新间隔Number1000
before-play播放开始前的回调函数
调用 next() 后开始播放
(next)=>void-
before-prev播放上一首前的回调函数
调用 next() 后开始播放上一首
(next)=>void-
before-next播放下一首前的回调函数
调用 next() 后开始播放下一首
(next)=>void-
其他的与原生 audio 一致

Event

事件说明回调
play播放开始后触发-
pause播放暂停后触发-
play-prev播放上一首后触发-
play-next播放下一首后触发-
playing播放中每 progressInterval 秒触发-
timeupdate当前的播放位置发送改变时触发event
loadedmetadata当媒介元素的持续时间以及其它媒介已加载数据时运行脚本触发event
ended音频播放结束后触发event
其他的与原生 audio 一致

Data

变量说明默认值
currentPlayIndex当前播放的音频索引0
isPlaying音频是否正在播放false
duration音频持续时间-
currentTime音频当前播放时间-

使用 ref 调用, 更多请自行查看组件 data

Method

方法说明回调
play开始播放-
pause暂停播放-
playPrev播放上一首-
playNext播放下一首-

使用 ref 调用, 更多请自行查看组件 methods

更新日志

v1.1.0【2020/12/11】

  • 新增调节音量功能
  • 新增 show-volume-button 属性
  • 新增 is-auto-playNext 属性
  • 新增播放失败自动播放下一首,is-auto-playNextfalse 则不会自动播放下一首
  • 新增音频加载中 svg 动画,可用 CSS 覆盖颜色
  • 修改 play 事件触发调前
  • 修改部分类名

v1.0.8【2020/11/17】

v1.0.7【2020/10/02】

v1.0.6【2020/04/28】

  • 不自带 babel-polyfill

v1.0.5【2019/11/21】

v1.0.4【2019/10/16】

  • 修复 isLoop 无效
  • 修改类名
  • 使用原生 CSS

许可证

MIT

最后

使用过程中发现任何问题都可以提 Issue,也非常欢迎提 PR

Keywords

FAQs

Package last updated on 11 Dec 2020

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