Vue-APlayer Component
Vue-APlayer is an easy-to-use music player component designed for Vue 2.x applications, built upon the APlayer prototype. The current stable version, 1.6.1, is the final minor release within the 1.x series; development efforts for new features are now directed towards an upcoming Vue-APlayer 2. Consequently, the 1.x branch is in maintenance mode, receiving only bug fixes and critical patches. Its key differentiators include a clean, highly customizable user interface featuring lyrics scrolling, playlist management with shuffle and repeat controls, drag-and-place functionality, mutex play, and integrated HLS support. The library is notably lightweight (16KB gzipped) and maintains minimal external dependencies beyond its required Vue peer dependency, providing a simple and easy-to-integrate API. It supports dynamic theme colors, including self-adapting themes based on album artwork.
Common errors
-
TypeError: Cannot read properties of undefined (reading 'finally') or similar for Promise.prototype.finally
cause Using Vue-APlayer v1.4.1 or older in browsers that do not support `Promise.prototype.finally`.fixUpgrade Vue-APlayer to version 1.4.2 or newer. -
Audio playback fails on HLS streams with no specific error from Vue-APlayer.
cause The `hls.js` library is not installed or available, which is necessary for playing HLS media sources.fixInstall `hls.js` via npm: `npm install hls.js`. -
Uncaught (in promise) DOMException: The element has no supported sources.
cause Occurs when attempting to seek an audio source that failed to load (e.g., due to a broken URL or network issue). This was largely addressed in v1.5.2 but could manifest in specific edge cases or older versions.fixEnsure all `src` URLs in your `music` data are valid and accessible. Update to v1.5.2 or newer for improved error handling during seeking. -
Player layout or alignment is incorrect or affected by parent styles.
cause Prior to v1.5.2, internal component styles could be overridden or misaligned by parent elements' CSS properties.fixUpgrade to Vue-APlayer v1.5.2 or newer, which includes improvements to prevent alignment issues and better isolation of component styles.
Warnings
- breaking The `mode` prop was completely removed in v1.5.0. It is not merely deprecated, but its usage will cause errors. Functionality for shuffle and repeat is now handled by dedicated `shuffle` and `repeat` props.
- breaking The `music.author` property within the music object was renamed to `music.artist` in v1.4.1 to align with ID3 tags standard.
- deprecated Version 1.6.0 was announced as the final minor update for Vue-APlayer 1.x. No new features will be added to the 1.x branch; future development and new features will be targeting Vue-APlayer 2.
- gotcha When playing HLS (HTTP Live Streaming) media, `hls.js` is required. If `hls.js` is not present in the project, HLS media playback may fail or cause errors, despite the fix in v1.3.1 for certain mismatch issues.
- gotcha Prior to v1.4.2, the library used the non-standard `.finally()` Promise method, which could cause errors in older browsers that do not support it.
Install
-
npm install vue-aplayer -
yarn add vue-aplayer -
pnpm add vue-aplayer
Imports
- Aplayer
const Aplayer = require('vue-aplayer');import Aplayer from 'vue-aplayer';
- Vue.component
import Aplayer from 'vue-aplayer'; Vue.component('APlayer', Aplayer); - components option
import Aplayer from 'vue-aplayer'; export default { components: { Aplayer } }
Quickstart
import Vue from 'vue';
import Aplayer from 'vue-aplayer';
// Register globally or locally
Vue.component('APlayer', Aplayer);
new Vue({
el: '#app',
template: `
<div>
<h1>My Music Player</h1>
<aplayer autoplay
:music='[
{
title: "secret base~君がくれたもの~",
artist: "Silent Siren",
src: "https://moeplayer.b0.upaiyun.com/aplayer/secretbase.mp3",
pic: "https://moeplayer.b0.upaiyun.com/aplayer/secretbase.jpg",
lrc: "[00:00.00]test
[00:00.50]lyrics
[00:01.00]here"
},
{
title: "Another Song",
artist: "Another Artist",
src: "https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.mp3",
pic: "https://moeplayer.b0.upaiyun.com/aplayer/hikarunara.jpg"
}
]'
:list-folded="false"
theme="#F06292"
></aplayer>
</div>
`
});