@smooth-player/react 1.0.1 → 2.1.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 +55 -6
- package/dist/SmoothAudioPlayer.d.ts +6 -3
- package/dist/SmoothAudioPlayer.js +19 -56
- package/dist/assets/menu.svg +5 -0
- package/package.json +6 -2
package/README.md
CHANGED
|
@@ -13,11 +13,60 @@ npm install smooth-player @smooth-player/react
|
|
|
13
13
|
```tsx
|
|
14
14
|
import "smooth-player/dist/smooth-player.css";
|
|
15
15
|
import { SmoothAudioPlayer } from "@smooth-player/react";
|
|
16
|
+
import type { PlaylistEntry } from "smooth-player";
|
|
16
17
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
18
|
+
const tracks: PlaylistEntry[] = [
|
|
19
|
+
{
|
|
20
|
+
id: "demo",
|
|
21
|
+
title: "Demo Playlist",
|
|
22
|
+
tracks: [
|
|
23
|
+
{
|
|
24
|
+
id: "song-1",
|
|
25
|
+
src: "https://cdn.pixabay.com/audio/2020/08/17/audio_613575b827.mp3",
|
|
26
|
+
metadata: { title: "Robot Gypsy Jazz", artist: "Frank Vanga" },
|
|
27
|
+
},
|
|
28
|
+
],
|
|
29
|
+
},
|
|
30
|
+
];
|
|
31
|
+
|
|
32
|
+
export function App() {
|
|
33
|
+
return (
|
|
34
|
+
<SmoothAudioPlayer
|
|
35
|
+
tracks={tracks}
|
|
36
|
+
accentColor="#0ed2a4"
|
|
37
|
+
backgroundColor="#0b1220"
|
|
38
|
+
visualizer="spectrum"
|
|
39
|
+
initialVolume={0.8}
|
|
40
|
+
uiOptions={{ showLogo: true }}
|
|
41
|
+
/>
|
|
42
|
+
);
|
|
43
|
+
}
|
|
23
44
|
```
|
|
45
|
+
|
|
46
|
+
## Component props
|
|
47
|
+
|
|
48
|
+
- `tracks: PlaylistEntry[]`
|
|
49
|
+
- `accentColor?: string`
|
|
50
|
+
- `backgroundColor?: string`
|
|
51
|
+
- `visualizer?: "spectrum" | "waveform" | "none"`
|
|
52
|
+
- `initialVolume?: number`
|
|
53
|
+
- `playerOptions?: Omit<SmoothPlayerOptions, "playlist" | "accentColor" | "backgroundColor" | "visualizer" | "initialVolume">`
|
|
54
|
+
- `uiOptions?: StandardPlayerUIMountOptions`
|
|
55
|
+
|
|
56
|
+
## Prop Mapping
|
|
57
|
+
|
|
58
|
+
| Wrapper prop | Core equivalent |
|
|
59
|
+
| --- | --- |
|
|
60
|
+
| `tracks` | `new SmoothPlayer({ playlist: tracks })` |
|
|
61
|
+
| `accentColor` | `new SmoothPlayer({ accentColor })` |
|
|
62
|
+
| `backgroundColor` | `new SmoothPlayer({ backgroundColor })` |
|
|
63
|
+
| `visualizer` | `new SmoothPlayer({ visualizer })` |
|
|
64
|
+
| `initialVolume` | `new SmoothPlayer({ initialVolume })` |
|
|
65
|
+
| `playerOptions` | Spread into `SmoothPlayerOptions` |
|
|
66
|
+
| `uiOptions` | Passed to `mountPlayerUI(player, root, uiOptions)` |
|
|
67
|
+
|
|
68
|
+
## Documentation
|
|
69
|
+
|
|
70
|
+
For the full list of player config options, runtime APIs, events, and UI options, see the main docs:
|
|
71
|
+
|
|
72
|
+
- [smooth-player README](https://github.com/marlenesco/smooth-player#readme)
|
|
@@ -1,8 +1,11 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type PlaylistEntry, type SmoothPlayerOptions, type StandardPlayerUIMountOptions, type VisualizerMode } from "smooth-player";
|
|
2
2
|
export interface SmoothAudioPlayerProps {
|
|
3
|
-
tracks:
|
|
3
|
+
tracks: PlaylistEntry[];
|
|
4
4
|
accentColor?: string;
|
|
5
|
+
backgroundColor?: string;
|
|
5
6
|
visualizer?: VisualizerMode;
|
|
6
7
|
initialVolume?: number;
|
|
8
|
+
playerOptions?: Omit<SmoothPlayerOptions, "playlist" | "accentColor" | "backgroundColor" | "visualizer" | "initialVolume">;
|
|
9
|
+
uiOptions?: StandardPlayerUIMountOptions;
|
|
7
10
|
}
|
|
8
|
-
export declare function SmoothAudioPlayer({ tracks, accentColor, visualizer, initialVolume, }: SmoothAudioPlayerProps): import("react/jsx-runtime").JSX.Element;
|
|
11
|
+
export declare function SmoothAudioPlayer({ tracks, accentColor, backgroundColor, visualizer, initialVolume, playerOptions, uiOptions, }: SmoothAudioPlayerProps): import("react/jsx-runtime").JSX.Element;
|
|
@@ -1,62 +1,25 @@
|
|
|
1
|
-
import { jsx as _jsx
|
|
2
|
-
import { useEffect,
|
|
3
|
-
import { SmoothPlayer,
|
|
4
|
-
|
|
5
|
-
import nextIcon from "./assets/next.svg";
|
|
6
|
-
import playIcon from "./assets/play.svg";
|
|
7
|
-
import pauseIcon from "./assets/pause.svg";
|
|
8
|
-
export function SmoothAudioPlayer({ tracks, accentColor = "#0ed2a4", visualizer = "spectrum", initialVolume = 0.8, }) {
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useEffect, useRef } from "react";
|
|
3
|
+
import { SmoothPlayer, mountPlayerUI, } from "smooth-player";
|
|
4
|
+
export function SmoothAudioPlayer({ tracks, accentColor = "#0ed2a4", backgroundColor = "#0b1220", visualizer = "spectrum", initialVolume = 0.8, playerOptions, uiOptions, }) {
|
|
9
5
|
const rootRef = useRef(null);
|
|
10
|
-
const spectrumRef = useRef(null);
|
|
11
|
-
const waveformRef = useRef(null);
|
|
12
|
-
const playerRef = useRef(null);
|
|
13
|
-
const [index, setIndex] = useState(0);
|
|
14
|
-
const [isPlaying, setIsPlaying] = useState(false);
|
|
15
|
-
const currentTrack = tracks[index] ?? null;
|
|
16
|
-
const showPlaylist = tracks.length > 1;
|
|
17
6
|
useEffect(() => {
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
const offTrack = player.on("trackchange", ({ index: nextIndex }) => setIndex(nextIndex));
|
|
32
|
-
const offPlay = player.on("play", () => setIsPlaying(true));
|
|
33
|
-
const offPause = player.on("pause", () => setIsPlaying(false));
|
|
7
|
+
const root = rootRef.current;
|
|
8
|
+
if (!root)
|
|
9
|
+
return;
|
|
10
|
+
const player = new SmoothPlayer({
|
|
11
|
+
...playerOptions,
|
|
12
|
+
accentColor,
|
|
13
|
+
backgroundColor,
|
|
14
|
+
visualizer,
|
|
15
|
+
initialVolume,
|
|
16
|
+
playlist: tracks,
|
|
17
|
+
});
|
|
18
|
+
const ui = mountPlayerUI(player, root, uiOptions);
|
|
34
19
|
return () => {
|
|
35
|
-
|
|
36
|
-
offPlay();
|
|
37
|
-
offPause();
|
|
38
|
-
spectrum?.stop();
|
|
39
|
-
waveform?.stop();
|
|
20
|
+
ui.destroy();
|
|
40
21
|
player.destroy();
|
|
41
22
|
};
|
|
42
|
-
}, [tracks,
|
|
43
|
-
|
|
44
|
-
const player = playerRef.current;
|
|
45
|
-
const root = rootRef.current;
|
|
46
|
-
if (!player || !root)
|
|
47
|
-
return;
|
|
48
|
-
player.setAccentColor(accentColor);
|
|
49
|
-
player.applyAccentColor(root);
|
|
50
|
-
}, [accentColor]);
|
|
51
|
-
const handlers = useMemo(() => ({
|
|
52
|
-
toggle: async () => {
|
|
53
|
-
await playerRef.current?.toggle();
|
|
54
|
-
},
|
|
55
|
-
previous: () => playerRef.current?.previous(),
|
|
56
|
-
next: () => playerRef.current?.next(),
|
|
57
|
-
pick: async (nextIndex) => {
|
|
58
|
-
await playerRef.current?.play(nextIndex);
|
|
59
|
-
},
|
|
60
|
-
}), []);
|
|
61
|
-
return (_jsxs("section", { ref: rootRef, className: "smooth-player", children: [_jsxs("div", { className: "smooth-player__main", children: [_jsxs("div", { className: "smooth-player__row", children: [_jsx("h2", { className: "smooth-player__title", children: "Smooth Player" }), _jsxs("div", { className: "smooth-player__controls", children: [_jsx("button", { className: "secondary", onClick: handlers.previous, "aria-label": "Previous", children: _jsx("img", { className: "smooth-player__icon", src: prevIcon, alt: "" }) }), _jsx("button", { onClick: handlers.toggle, "aria-label": isPlaying ? "Pause" : "Play", children: _jsx("img", { className: "smooth-player__icon", src: isPlaying ? pauseIcon : playIcon, alt: "" }) }), _jsx("button", { className: "secondary", onClick: handlers.next, "aria-label": "Next", children: _jsx("img", { className: "smooth-player__icon", src: nextIcon, alt: "" }) })] })] }), _jsxs("div", { className: "smooth-player__meta", children: [_jsx("strong", { children: currentTrack?.metadata?.title ?? "Unknown title" }), _jsx("div", { className: "smooth-player__artist", children: currentTrack?.metadata?.artist ?? "Unknown artist" })] }), _jsx("canvas", { ref: spectrumRef, id: "spectrum", className: "smooth-player__canvas", width: 860, height: 180, hidden: visualizer !== "spectrum" }), _jsx("canvas", { ref: waveformRef, id: "waveform", className: "smooth-player__canvas", width: 860, height: 120, hidden: visualizer !== "waveform" })] }), showPlaylist ? (_jsxs("aside", { className: "smooth-player__playlist", "aria-hidden": "false", children: [_jsx("div", { className: "smooth-player__playlist-head", children: _jsx("h2", { children: "Playlist" }) }), _jsx("ul", { className: "smooth-player__playlist-list", children: tracks.map((track, listIndex) => (_jsx("li", { children: _jsxs("button", { className: "smooth-player__playlist-item", "aria-current": listIndex === index ? "true" : undefined, onClick: () => handlers.pick(listIndex), children: [_jsx("span", { className: "smooth-player__playlist-title", children: track.metadata?.title ?? track.id }), _jsx("span", { className: "smooth-player__playlist-artist", children: track.metadata?.artist ?? "Unknown artist" })] }) }, track.id))) })] })) : null] }));
|
|
23
|
+
}, [tracks, accentColor, backgroundColor, visualizer, initialVolume, playerOptions, uiOptions]);
|
|
24
|
+
return _jsx("section", { ref: rootRef });
|
|
62
25
|
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="none">
|
|
2
|
+
<path d="M5 7.5H19" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>
|
|
3
|
+
<path d="M5 12H19" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>
|
|
4
|
+
<path d="M5 16.5H19" stroke="currentColor" stroke-width="1.9" stroke-linecap="round"/>
|
|
5
|
+
</svg>
|
package/package.json
CHANGED
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@smooth-player/react",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "2.1.0",
|
|
4
4
|
"description": "React component for Smooth Player",
|
|
5
5
|
"type": "module",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/marlenesco/smooth-player"
|
|
9
|
+
},
|
|
6
10
|
"main": "./dist/index.js",
|
|
7
11
|
"module": "./dist/index.js",
|
|
8
12
|
"types": "./dist/index.d.ts",
|
|
@@ -23,7 +27,7 @@
|
|
|
23
27
|
"peerDependencies": {
|
|
24
28
|
"react": ">=18",
|
|
25
29
|
"react-dom": ">=18",
|
|
26
|
-
"smooth-player": "^
|
|
30
|
+
"smooth-player": "^2.0.0"
|
|
27
31
|
},
|
|
28
32
|
"scripts": {
|
|
29
33
|
"build": "tsc -p tsconfig.build.json && mkdir -p dist/assets && cp -R src/assets/* dist/assets/",
|