Install & Download:
# NPM
$ npm install vue-wave-playerDescription:
Vue Wave Player is a Vue component that visualizes audio files with a Canvas-based waveform. It handles waveform rendering, playback controls, and time tracking.
You can configure the player through props for visual style and audio behavior. Styles load automatically without a separate CSS import.
Features
- 🎵 Canvas Waveform: Renders an audio waveform on an HTML5 canvas element. You control the bar width and gap.
- 🎨 Telegram Style: Applies a specific UI design from Telegram’s voice messages, including color scheme and layout.
- ⚙️ Configurable Playback: Controls playback speed with a toggle button. You define the available speed rates.
- 📊 Convenient API: Exposes methods for play, pause, stop, seek, and rate change. It provides reactive properties for the current time and duration.
- 🎚️ Customizable Slots: Offers slots to replace the default play button and time display with your own components.
- 🔊 Event Handling: Emits standard audio events like play, pause, ended, timeupdate, and seeking for external logic.
Use Cases
- Chat Applications: Renders voice messages with visual feedback in messaging interfaces.
- Music Portfolios: Displays track previews with interactive waveforms for artists.
- Podcast Players: Manages episode playback with adjustable speed controls.
- Sound Libraries: Previews short audio clips or sound effects efficiently.
How to Use It
1. Register the plugin in your main entry file to use the component across your entire application.
// main.js
import { createApp } from 'vue'
import App from './App.vue'
import VueWavePlayer from 'vue-wave-player'
const app = createApp(App)
app.use(VueWavePlayer)
app.mount('#app')2. Insert the component into your template and bind the src prop to your audio file. The player renders the waveform immediately upon loading the file.
<template>
<div class="player-container">
<VueWavePlayer src="/assets/audio/track-1.mp3" />
</div>
</template>3. You can adjust the visual appearance and control playback programmatically. This example demonstrates how to change the bar styles and use a reference to control the player methods.
<template>
<VueWavePlayer
ref="audioPlayer"
src="/music/demo.mp3"
:bar-width="4"
:bar-gap="2"
primary-color="#6366f1"
background-color="#f3f4f6"
show-playback-rate
/>
<div class="controls">
<button @click="playAudio">Play</button>
<button @click="pauseAudio">Pause</button>
</div>
</template>
<script setup>
import { ref } from 'vue'
// Create a reference to the component
const audioPlayer = ref(null)
// Access internal methods via the reference
const playAudio = () => {
audioPlayer.value?.play()
}
const pauseAudio = () => {
audioPlayer.value?.pause()
}
</script>4. Available component props
| Prop | Type | Default | Description |
|---|---|---|---|
src | string | — | Defines the audio source URL (Required). |
barWidth | number | 3 | Sets the width of each waveform bar in pixels. |
barGap | number | 2 | Sets the space between bars in pixels. |
primaryColor | string | #3390EC | Applies color to the waveform and buttons. |
backgroundColor | string | #FFFFFF | Sets the background color of the player container. |
showPlaybackRate | boolean | false | Toggles the visibility of the speed control button. |
playbackRates | number[] | [1, 1.5, 2] | Defines the available playback speed options. |
autoplay | boolean | false | Starts playback automatically when the component loads. |
5. slots
| Slot | Data | Description |
|---|---|---|
#play-button | { isPlaying, isLoading, toggle } | Replaces the default play/pause button. |
#time | { currentTime, duration, formattedCurrentTime, formattedDuration } | Replaces the default time display. |
6. Available events:
| Event | Data | Description |
|---|---|---|
@play | — | Fires when playback starts. |
@pause | — | Fires when playback pauses. |
@ended | — | Fires when the audio track finishes. |
@timeupdate | number | Emits the current playback time in seconds. |
@durationchange | number | Emits the total duration in seconds once determined. |
@seeking | number | Fires when a seek operation begins. |
@seeked | number | Fires when a seek operation completes. |
@ratechange | number | Fires when the playback speed changes. |
@error | Error | Fires when an error occurs during load or playback. |
7. API methods:
| Method / Property | Type | Description |
|---|---|---|
play() | function | Starts audio playback. |
pause() | function | Pauses audio playback. |
stop() | function | Stops playback and resets the playhead to the start. |
seek(time) | function | Jumps to the specified time in seconds. |
setRate(rate) | function | Updates the playback speed. |
currentTime | number | Returns the current playback position. |
duration | number | Returns the total length of the audio. |
isPlaying | boolean | Returns true if audio is currently playing. |
Related Resources
- Wavesurfer.js: Renders interactive waveforms using the Web Audio API and HTML5 Canvas.
- Howler.js: Manages audio sprites and playback consistency across all modern browsers.
FAQs
Q: Does this library support Vue 2?
A: No, this package targets Vue 3 applications specifically.
Q: Can I use this with Nuxt?
A: Yes, you can use it with Nuxt 3 by registering it as a client-side plugin.
Q: How does it handle large audio files?
A: The browser must load the file to analyze the frequency data, so very large files may delay the initial rendering.
Q: Do I need to import a CSS file?
A: No, the component injects the required styles automatically.
Q: Can I fetch the audio source dynamically?
A: Yes. The src prop is reactive. You can bind it to a variable and update it. The component will load the new audio source.
Q: Is the waveform generated from the audio file?
A: No. The component uses a simplified, simulated waveform for visual effect. It does not perform audio analysis to generate a true waveform from the audio data.





