用vue简单写一个音乐播放组件「附源码」

作者:vipbic

转发链接:https://segmentfault.com/a/1190000022980992

上次小编也分享一个关于Vue 开发过音乐播放对项目:

这次公司有个单位项目,需要读取语音文件并进行播放,其实用audio引入个播放链接即可,不需要太多功能后来想到网站是不是也可以放个小播放器插件,索性查了audio相关api,也学习其中相关技巧,分享给大家

整个代码很简单,有些audio-api注释也写在了后面html

js

less

github完整代码用vue简单写一个音乐播放组件

github:https://github.com/hangjob/vue-admin/blob/master/src/view/music/music.vue

HTML audio基础API完全使用指南

地址:https://www.zhangxinxu.com/wordpress/2019/07/html-audio-api-guide/

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

《》

作者:vipbic

转发链接:https://segmentfault.com/a/1190000022980992

一个漂亮的开源HTML5音乐播放器——APlayer

APlayer是一个简约且漂亮的HTML5音乐播放器,支持多种模式,包括播放列表模式、吸底模式

、迷你模式、MSE模式、HLS模式。

https://github.com/DIYgod/APlayer

使用 npm:

使用 Yarn:

或者使用模块化方式

  • APlayer.version: 静态属性, 返回 APlayer 的版本号
  • ap.play(): 播放音频
  • ap.pause(): 暂停音频
  • ap.seek(time: number): 跳转到特定时间,时间的单位为秒
  • ap.toggle(): 切换播放和暂停
  • ap.on(event: string, handler: function): 绑定音频和播放器事件,详情
  • ap.volume(percentage: number, nostorage: boolean): 设置音频音量
  • ap.theme(color: string, index: number): 设置播放器主题色, index 默认为当前音频的 index
  • ap.setMode(mode: string): 设置播放器模式,mode 取值应为 \’mini\’ 或 \’normal\’
  • ap.mode: 返回播放器当前模式,\’mini\’ 或 \’normal\’
  • ap.notice(text: string, time: number, opacity: number): 显示通知,时间的单位为毫秒,默认时间 2000 毫秒,默认透明度 0.8,设置时间为 0 可以取消通知自动隐藏
  • ap.skipBack(): 切换到上一首音频
  • ap.skipForward(): 切换到下一首音频
  • ap.destroy(): 销毁播放器
  • ap.lrc-ap.lrc.show(): 显示歌词ap.lrc.hide(): 隐藏歌词ap.lrc.toggle(): 显示/隐藏歌词
  • ap.list-ap.list.show(): 显示播放列表ap.list.hide(): 隐藏播放列表ap.list.toggle(): 显示/隐藏播放列表ap.list.add(audios: array | object): 添加一个或几个新音频到播放列表ap.list.add([{ name: \’name\’, artist: \’artist\’, url: \’url.mp3\’, cover: \’cover.jpg\’, lrc: \’lrc.lrc\’, theme: \’#ebd0c2\’ }]); ap.list.remove(index: number): 移除播放列表中的一个音频ap.list.remove(1); ap.list.switch(): 切换到播放列表里的其他音频ap.list.switch(1); ap.list.clear(): 清空播放列表
  • ap.audio: 原生 audioap.audio.currentTime: 返回音频当前播放时间ap.audio.duration: 返回音频总时间ap.audio.paused: 返回音频是否暂停支持大多数原生audio接口

ap.on(event, handler)

音频事件

  • abort
  • canplay
  • canplaythrough
  • durationchange
  • emptied
  • ended
  • error
  • loadeddata
  • loadedmetadata
  • loadstart
  • mozaudioavailable
  • pause
  • play
  • playing
  • progress
  • ratechange
  • seeked
  • seeking
  • stalled
  • suspend
  • timeupdate
  • volumechange
  • waiting

播放器事件

  • listshow
  • listhide
  • listadd
  • listremove
  • listswitch
  • listclear
  • noticeshow
  • noticehide
  • destroy
  • lrcshow
  • lrchide

APlayer是一个不错的HTML5小型音乐播放器,可以将它嵌入到自己的网页中!

本文作者及来源:Renderbus瑞云渲染农场https://www.renderbus.com

点赞 0
收藏 0

文章为作者独立观点不代本网立场,未经允许不得转载。