@smooth-player/vue 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +22 -0
- package/package.json +29 -0
- package/src/SmoothAudioPlayer.vue +110 -0
- package/src/assets/next.svg +4 -0
- package/src/assets/pause.svg +4 -0
- package/src/assets/play.svg +3 -0
- package/src/assets/prev.svg +4 -0
- package/src/index.d.ts +14 -0
- package/src/index.js +4 -0
- package/src/shims-svg.d.ts +4 -0
package/README.md
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# @smooth-player/vue
|
|
2
|
+
|
|
3
|
+
Vue wrapper component for [`smooth-player`](https://www.npmjs.com/package/smooth-player).
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install smooth-player @smooth-player/vue
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Usage
|
|
12
|
+
|
|
13
|
+
```vue
|
|
14
|
+
<script setup>
|
|
15
|
+
import "smooth-player/dist/smooth-player.css";
|
|
16
|
+
import { SmoothAudioPlayer } from "@smooth-player/vue";
|
|
17
|
+
</script>
|
|
18
|
+
|
|
19
|
+
<template>
|
|
20
|
+
<SmoothAudioPlayer :tracks="tracks" accent-color="#0ed2a4" visualizer="spectrum" :initial-volume="0.8" />
|
|
21
|
+
</template>
|
|
22
|
+
```
|
package/package.json
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@smooth-player/vue",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Vue component for Smooth Player",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"import": "./src/index.js"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"src",
|
|
16
|
+
"README.md"
|
|
17
|
+
],
|
|
18
|
+
"publishConfig": {
|
|
19
|
+
"access": "public"
|
|
20
|
+
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"vue": ">=3.3.0",
|
|
23
|
+
"smooth-player": "^1.0.0"
|
|
24
|
+
},
|
|
25
|
+
"scripts": {
|
|
26
|
+
"build": "echo \"No build step required for source-distributed Vue component\"",
|
|
27
|
+
"typecheck": "echo \"Typecheck in consumer app (Vite/Nuxt)\""
|
|
28
|
+
}
|
|
29
|
+
}
|
|
@@ -0,0 +1,110 @@
|
|
|
1
|
+
<script setup lang="ts">
|
|
2
|
+
import { onMounted, onBeforeUnmount, ref, computed, watch } from "vue";
|
|
3
|
+
import {
|
|
4
|
+
SmoothPlayer,
|
|
5
|
+
CanvasSpectrumVisualizer,
|
|
6
|
+
CanvasWaveformVisualizer,
|
|
7
|
+
type AudioTrack,
|
|
8
|
+
type VisualizerMode,
|
|
9
|
+
} from "smooth-player";
|
|
10
|
+
import prevIcon from "./assets/prev.svg";
|
|
11
|
+
import nextIcon from "./assets/next.svg";
|
|
12
|
+
import playIcon from "./assets/play.svg";
|
|
13
|
+
import pauseIcon from "./assets/pause.svg";
|
|
14
|
+
|
|
15
|
+
const props = withDefaults(defineProps<{
|
|
16
|
+
tracks: AudioTrack[];
|
|
17
|
+
accentColor?: string;
|
|
18
|
+
visualizer?: VisualizerMode;
|
|
19
|
+
initialVolume?: number;
|
|
20
|
+
}>(), {
|
|
21
|
+
accentColor: "#0ed2a4",
|
|
22
|
+
visualizer: "spectrum",
|
|
23
|
+
initialVolume: 0.8,
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
const rootRef = ref<HTMLElement | null>(null);
|
|
27
|
+
const spectrumRef = ref<HTMLCanvasElement | null>(null);
|
|
28
|
+
const waveformRef = ref<HTMLCanvasElement | null>(null);
|
|
29
|
+
const player = ref<SmoothPlayer | null>(null);
|
|
30
|
+
const currentIndex = ref(0);
|
|
31
|
+
const isPlaying = ref(false);
|
|
32
|
+
|
|
33
|
+
const currentTrack = computed(() => props.tracks[currentIndex.value] ?? null);
|
|
34
|
+
|
|
35
|
+
let spectrum: CanvasSpectrumVisualizer | null = null;
|
|
36
|
+
let waveform: CanvasWaveformVisualizer | null = null;
|
|
37
|
+
|
|
38
|
+
onMounted(() => {
|
|
39
|
+
const instance = new SmoothPlayer({
|
|
40
|
+
initialVolume: props.initialVolume,
|
|
41
|
+
visualizer: props.visualizer,
|
|
42
|
+
accentColor: props.accentColor,
|
|
43
|
+
});
|
|
44
|
+
instance.setPlaylist(props.tracks, 0);
|
|
45
|
+
player.value = instance;
|
|
46
|
+
|
|
47
|
+
if (props.visualizer === "spectrum") {
|
|
48
|
+
spectrum = new CanvasSpectrumVisualizer(spectrumRef.value!, instance, { color: "#3cc8d9" });
|
|
49
|
+
spectrum.start();
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (props.visualizer === "waveform") {
|
|
53
|
+
waveform = new CanvasWaveformVisualizer(waveformRef.value!, instance, { color: "#e7f0ff" });
|
|
54
|
+
waveform.start();
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
instance.on("trackchange", ({ index }) => (currentIndex.value = index));
|
|
58
|
+
instance.on("play", () => (isPlaying.value = true));
|
|
59
|
+
instance.on("pause", () => (isPlaying.value = false));
|
|
60
|
+
|
|
61
|
+
applyAccent();
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
onBeforeUnmount(() => {
|
|
65
|
+
spectrum?.stop();
|
|
66
|
+
waveform?.stop();
|
|
67
|
+
player.value?.destroy();
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
watch(() => props.accentColor, () => applyAccent());
|
|
71
|
+
|
|
72
|
+
function applyAccent() {
|
|
73
|
+
if (!player.value || !rootRef.value) return;
|
|
74
|
+
player.value.setAccentColor(props.accentColor);
|
|
75
|
+
player.value.applyAccentColor(rootRef.value);
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
async function toggle() {
|
|
79
|
+
await player.value?.toggle();
|
|
80
|
+
}
|
|
81
|
+
</script>
|
|
82
|
+
|
|
83
|
+
<template>
|
|
84
|
+
<section ref="rootRef" class="smooth-player">
|
|
85
|
+
<div class="smooth-player__main">
|
|
86
|
+
<div class="smooth-player__row">
|
|
87
|
+
<h2 class="smooth-player__title">Smooth Player</h2>
|
|
88
|
+
<div class="smooth-player__controls">
|
|
89
|
+
<button class="secondary" @click="player?.previous()" aria-label="Previous">
|
|
90
|
+
<img class="smooth-player__icon" :src="prevIcon" alt="" />
|
|
91
|
+
</button>
|
|
92
|
+
<button @click="toggle" :aria-label="isPlaying ? 'Pause' : 'Play'">
|
|
93
|
+
<img class="smooth-player__icon" :src="isPlaying ? pauseIcon : playIcon" alt="" />
|
|
94
|
+
</button>
|
|
95
|
+
<button class="secondary" @click="player?.next()" aria-label="Next">
|
|
96
|
+
<img class="smooth-player__icon" :src="nextIcon" alt="" />
|
|
97
|
+
</button>
|
|
98
|
+
</div>
|
|
99
|
+
</div>
|
|
100
|
+
|
|
101
|
+
<div class="smooth-player__meta">
|
|
102
|
+
<strong>{{ currentTrack?.metadata?.title ?? "Unknown title" }}</strong>
|
|
103
|
+
<div class="smooth-player__artist">{{ currentTrack?.metadata?.artist ?? "Unknown artist" }}</div>
|
|
104
|
+
</div>
|
|
105
|
+
|
|
106
|
+
<canvas ref="spectrumRef" id="spectrum" class="smooth-player__canvas" width="860" height="180" :hidden="props.visualizer !== 'spectrum'"></canvas>
|
|
107
|
+
<canvas ref="waveformRef" id="waveform" class="smooth-player__canvas" width="860" height="120" :hidden="props.visualizer !== 'waveform'"></canvas>
|
|
108
|
+
</div>
|
|
109
|
+
</section>
|
|
110
|
+
</template>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
|
2
|
+
<path d="M17.5 6V18" stroke="currentColor" stroke-width="2.1" stroke-linecap="round"/>
|
|
3
|
+
<path d="M7.3 6.7C6.74 6.34 6 6.74 6 7.41V16.59C6 17.26 6.74 17.66 7.3 17.3L13.85 13.09C14.35 12.77 14.35 11.23 13.85 10.91L7.3 6.7Z" fill="currentColor"/>
|
|
4
|
+
</svg>
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
|
2
|
+
<path d="M6.5 6V18" stroke="currentColor" stroke-width="2.1" stroke-linecap="round"/>
|
|
3
|
+
<path d="M16.7 6.7C17.26 6.34 18 6.74 18 7.41V16.59C18 17.26 17.26 17.66 16.7 17.3L10.15 13.09C9.65 12.77 9.65 11.23 10.15 10.91L16.7 6.7Z" fill="currentColor"/>
|
|
4
|
+
</svg>
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { DefineComponent } from "vue";
|
|
2
|
+
import type { AudioTrack, VisualizerMode } from "smooth-player";
|
|
3
|
+
|
|
4
|
+
export interface SmoothAudioPlayerProps {
|
|
5
|
+
tracks: AudioTrack[];
|
|
6
|
+
accentColor?: string;
|
|
7
|
+
visualizer?: VisualizerMode;
|
|
8
|
+
initialVolume?: number;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
declare const SmoothAudioPlayer: DefineComponent<SmoothAudioPlayerProps>;
|
|
12
|
+
|
|
13
|
+
export { SmoothAudioPlayer };
|
|
14
|
+
export default SmoothAudioPlayer;
|
package/src/index.js
ADDED