vue使用wavesurfer.js解決音頻可視化播放問題
之前給大家介紹過vue中音頻wavesurfer.js的使用方法,感興趣的朋友可以點(diǎn)擊查看,今天繼續(xù)給大家普及vue解決音頻可視化播放,使用wavesurfer.js問題,效果圖如下所示:
上效果:
1.安裝wavesurfer
npm install wavesurfer.js
2.在頁(yè)面導(dǎo)入
import WaveSurfer from 'wavesurfer.js'
注:我沒有使用時(shí)間軸,所以沒有引入,如果需要再引入
import Timeline from 'wavesurfer.js/dist/plugin/wavesurfer.timeline.js'
3.上源碼
<template> <el-row> <el-card class="card" :body-style="{ padding: '10px' }"> <div id="waveform" ref="waveform"> </div> </el-card> </el-row> <div> <el-button type="primary" @click="playMusic"> <i class="el-icon-video-play"></i> 播放 / <i class="el-icon-video-pausee"></i> 暫停 </el-button> </template> <script> import WaveSurfer from "wavesurfer.js"; // import Timeline from "wavesurfer.js/dist/plugin/wavesurfer.timeline.js"; export default { name: "Details", data() { return { wavesurfer: null, }; }, mounted() { this.$nextTick(() => { this.wavesurfer = WaveSurfer.create({ container: this.$refs.waveform, // waveColor: '#409EFF', barWidth: 1, cursorColor: "black", progressColor: "blue", backend: "MediaElement", // mediaControls: false, audioRate: "1", //使用時(shí)間軸插件 }); // 特別提醒:此處需要使用require(相對(duì)路徑),否則會(huì)報(bào)錯(cuò) this.wavesurfer.load(require("../mp3/living.mp3")); }); methods: { playMusic() { //"播放/暫停"按鈕的單擊觸發(fā)事件,暫停的話單擊則播放,正在播放的話單擊則暫停播放 this.wavesurfer.playPause.bind(this.wavesurfer)(); }, }; </script> <style > .mixin-components-container { width: 100% !important; #f0f2f5; padding: 30px; /* min-height: calc(100vh - 84px); */ } .el-card__body { height: 70px !important; padding: 0 auto !important; .card { height: 70px; #waveform { wave { height: 50px !important; </style>
4.注釋:
這個(gè)插件實(shí)在太吊了,官方文檔太厲害,上鏈接:https://wavesurfer-js.org/
我用到了幾個(gè)方法:
4.1.
this.wavesurfer.play(0, 212); 指定開始時(shí)間和結(jié)束時(shí)間,以秒為單位,0秒開始,212秒結(jié)束
4.2.
this.wavesurfer.on("pause", () => { console.log('我暫停了') });
監(jiān)聽暫停
4.3.
this.wavesurfer.load(require("../mp3/living.mp3")); 讀取目錄路徑里面的Mp3文件,可以測(cè)試用 this.wavesurfer.load('xxx.mp3')); 讀取網(wǎng)絡(luò)地址,有接口就用這個(gè)
到此這篇關(guān)于vue使用wavesurfer.js解決音頻可視化播放的文章就介紹到這了,更多相關(guān)vue音頻可視化播放內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
基于腳手架創(chuàng)建Vue項(xiàng)目實(shí)現(xiàn)步驟詳解
這篇文章主要介紹了基于腳手架創(chuàng)建Vue項(xiàng)目實(shí)現(xiàn)步驟詳解,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08vue.js實(shí)現(xiàn)回到頂部動(dòng)畫效果
這篇文章主要為大家詳細(xì)介紹了vue.js實(shí)現(xiàn)回到頂部動(dòng)畫效果,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-07-07vue與iframe頁(yè)面數(shù)據(jù)互相通信的實(shí)現(xiàn)示例
這篇文章主要給大家介紹了vue與iframe頁(yè)面數(shù)據(jù)互相通信的實(shí)現(xiàn)示例,文中通過代碼示例給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作有一定的幫助,需要的朋友可以參考下2023-12-12vue+element項(xiàng)目實(shí)時(shí)監(jiān)聽div寬度的變化
這篇文章主要介紹了vue+element項(xiàng)目里實(shí)時(shí)監(jiān)聽某個(gè)div寬度的變化,然后執(zhí)行相應(yīng)的事件,本文結(jié)合示例代碼給大家介紹的非常詳細(xì),感興趣的朋友一起看看吧2024-08-08