vue中音频wavesurfer.js的使用方法
网络编程 2021-07-04 15:02www.168986.cn编程入门
这篇文章主要为大家详细介绍了vue中音频wavesurfer.js的使用方法,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
本文为大家分享了vue中音频wavesurfer.js的使用方法,供大家参考,具体内容如下
效果图
引入wavesurfer.js
封装 wavesurfer.js`
<template> <div class="waveformOuter"> <div id="waveform" ref="waveform" /> <div class="play" @click="playMusic"> <svg-icon v-if="!isPlaying" icon-class="play" class="icon myplay" /> <svg-icon v-else icon-class="s" class="icon mys" /> <p>{{ time }}</p> </div> <!-- <p>{{ url }}</p> --> </div> </template> <script> import WaveSurfer from '@/assets/js/wavesurfer' export default { props: ['url', 'toSMusic', 'loadWave'], data() { return { isPlaying: false, time: '00:00', wavesurfer: null, } }, watch: { 'loadWave': function() { this.loadMusic() }, 'url': function() { // return this.wavesurfer.getCurrentTime() this.loadMusic(true) console.log('url---------------------------------------') }, 'toSMusic': function() { console.log('toSMusic---------------------------------------') if (this.wavesurfer) { this.wavesurfer.pause() } } }, mounted() { this.$nextTick(() => { if (this.loadWave) { console.log('haha') this.loadMusic() } }) }, methods: { itemClick(node) { console.log(node.model.id) }, buZero(num) { return num > 9 ? num : '0' + num }, loadMusic(bool) { console.log('this.WaveSurfer--------------------------------------', WaveSurfer) if (this.wavesurfer) { if (bool) { this.time = '00:00' this.wavesurfer.load(this.url) } } else { this.wavesurfer = WaveSurfer.create({ container: this.$refs.waveform, waveColor: 'violet', progressColor: 'purple' }) this.wavesurfer.load(this.url) this.wavesurfer.on('ready', () => { // this.wavesurfer.play() }) this.wavesurfer.on('audioprocess', (e) => { const times = Math.floor(e) this.time = this.buZero(Math.floor(times / 60)) + ':' + this.buZero(times % 60) }) this.wavesurfer.on('finish', () => { this.isPlaying = false }) } }, sMusic(){ if (this.wavesurfer) { this.wavesurfer.s(); } }, playMusic() { console.log("开始") console.log(this.wavesurfer) console.log("点击开始播放按钮",this.url) if (this.wavesurfer) { if (this.wavesurfer.isPlaying()) { this.isPlaying = false debugger this.wavesurfer.pause() } else { this.isPlaying = true this.wavesurfer.play() } } } } } </script> <!-- Add "scoped" attribute to limit CSS to this ponent only --> <style scoped> .myplay{ position: absolute; : 50%; font-size: 17px; margin: -10px 0 0 -9px; left: 50%; } .mys{ position: absolute; : 50%; margin: -15px 0 0 -18px; left: 50%; font-size: 25px; } #waveform{ width: calc(100% - 150px); height:128px; float: left; margin-right: 22px; background: black; } .play{ position: relative; width: 128px; height:128px; border-radius:3px; background-color:#EBEEF5; float: left; text-align: center; } .play p{ margin-: 85px; color: #3683FA; } .waveformOuter{ margin-bottom: 20px; overflow: hidden; } </style>
再然后 在需要的组件中引入
<div class="luyin" v-if="this.isYinyin"> <!-- {{this.isYinyin}} --> <my-wave-sufer ref="handleDialogClose" :url="luyinUrl" :load-wave="showDialog" :to-s-music="!showDialog" /> </div> isYinyin: false,//是否加载录音组件 showDialog: true, //是否初始化录音组件 luyinUrl: "", //录音url 数据库录音格式 123.wav
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持狼蚁SEO。
编程语言
- 宿迁百度关键词排名指南:实现精准营销的关键
- 四川SEO优化怎么做网络推广
- 立昂技术备案老域名收购:如何为您的业务赋能
- 安徽百度关键词seo贵不贵,一般需要多少钱
- 吉林百度快照排名怎么做电话营销
- 多伦新手做SEO怎么做
- 甘肃优化关键词排名推广怎么做论坛营销
- 沙雅SEO网站推广:提升您的在线可见性
- 四川SEO优化如何提升销售额和销售量
- 聂荣网站排名优化:提升网站可见性的全方位指
- 涞水SEO:提升地方企业在线可见性的策略
- 辽宁百度seo排名怎样做网站排名
- 临湘哪有关键词排名优化:提升网站可见度的关
- 黑龙江百度网站优化有没有优惠
- 凉城优化关键词排名推广:提升您的网络可见性
- 萝北整站优化:提升您网站流量和排名的全面指