@students-dev/audify-js 1.0.1 → 1.0.2
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 +92 -441
- package/dist/AudioEngine.js +232 -0
- package/dist/cjs/index.js +1478 -1746
- package/dist/cjs/index.js.map +1 -1
- package/dist/constants/index.js +35 -0
- package/dist/engine/Filters.js +137 -0
- package/dist/engine/MockAudioContext.js +53 -0
- package/dist/engine/Player.js +209 -0
- package/dist/esm/index.js +1474 -1744
- package/dist/esm/index.js.map +1 -1
- package/dist/events/EventBus.js +61 -0
- package/dist/index.js +18 -0
- package/dist/interfaces/index.js +1 -0
- package/dist/plugins/Plugin.js +27 -0
- package/dist/plugins/PluginManager.js +106 -0
- package/dist/providers/LavalinkProvider.js +81 -0
- package/dist/providers/LocalProvider.js +70 -0
- package/dist/providers/ProviderRegistry.js +20 -0
- package/dist/providers/SpotifyProvider.js +59 -0
- package/dist/providers/YouTubeProvider.js +48 -0
- package/dist/queue/Queue.js +186 -0
- package/dist/queue/Track.js +54 -0
- package/dist/types/AudioEngine.d.ts +107 -0
- package/dist/types/constants/index.d.ts +39 -0
- package/dist/types/engine/Filters.d.ts +25 -24
- package/dist/types/engine/MockAudioContext.d.ts +43 -0
- package/dist/types/engine/Player.d.ts +25 -21
- package/dist/types/events/EventBus.d.ts +17 -15
- package/dist/types/index.d.ts +17 -15
- package/dist/types/interfaces/index.d.ts +31 -0
- package/dist/types/plugins/Plugin.d.ts +11 -43
- package/dist/types/plugins/PluginManager.d.ts +19 -19
- package/dist/types/providers/LavalinkProvider.d.ts +15 -46
- package/dist/types/providers/LocalProvider.d.ts +11 -22
- package/dist/types/providers/ProviderRegistry.d.ts +10 -0
- package/dist/types/providers/SpotifyProvider.d.ts +12 -52
- package/dist/types/providers/YouTubeProvider.d.ts +11 -28
- package/dist/types/queue/Queue.d.ts +28 -22
- package/dist/types/queue/Track.d.ts +18 -16
- package/dist/types/utils/Logger.d.ts +12 -16
- package/dist/types/utils/Metadata.d.ts +16 -15
- package/dist/types/utils/Probe.d.ts +7 -7
- package/dist/types/utils/Time.d.ts +9 -9
- package/dist/utils/Logger.js +59 -0
- package/dist/utils/Metadata.js +90 -0
- package/dist/utils/Probe.js +59 -0
- package/dist/utils/Time.js +54 -0
- package/package.json +14 -8
package/README.md
CHANGED
|
@@ -1,19 +1,38 @@
|
|
|
1
|
-
# audify-js
|
|
1
|
+
# audify-js v1.0.2
|
|
2
2
|
|
|
3
3
|
[](https://badge.fury.io/js/%40students-dev%2Faudify-js)
|
|
4
4
|
[](https://opensource.org/licenses/MIT)
|
|
5
5
|
|
|
6
6
|
A lightweight, modern, modular audio engine that provides playback, filters, queue management, events, and extensibility through plugins. Works in both **Node.js** and **browser** environments.
|
|
7
7
|
|
|
8
|
+
**Version 1.0.2** represents a major stability and architecture enhancement, introducing a standardized provider system, robust plugin lifecycle, and full TypeScript support.
|
|
9
|
+
|
|
8
10
|
## Features
|
|
9
11
|
|
|
10
|
-
- 🎵 **Unified Audio Engine**: Cross-environment abstraction using Web Audio API
|
|
11
|
-
- 📋 **Queue Management**: Add, remove, shuffle, jump,
|
|
12
|
-
- 🎛️ **Audio Filters**: Bassboost, nightcore, vaporwave, 8D rotate, pitch/speed adjustment, reverb
|
|
13
|
-
- 🔌 **Plugin System**: Extensible architecture with lifecycle hooks
|
|
14
|
-
- 📡 **Event-Driven**: Comprehensive event system for all operations
|
|
15
|
-
- 🌐 **
|
|
16
|
-
- 🛠️ **Developer-Friendly**: TypeScript
|
|
12
|
+
- 🎵 **Unified Audio Engine**: Cross-environment abstraction using Web Audio API.
|
|
13
|
+
- 📋 **Advanced Queue Management**: Add, remove, shuffle, jump, loop (track/queue) modes.
|
|
14
|
+
- 🎛️ **Audio Filters**: Bassboost, nightcore, vaporwave, 8D rotate, pitch/speed adjustment, reverb.
|
|
15
|
+
- 🔌 **Robust Plugin System**: Extensible architecture with safe lifecycle hooks and error isolation.
|
|
16
|
+
- 📡 **Event-Driven**: Comprehensive event system for all operations.
|
|
17
|
+
- 🌐 **Provider Registry**: Standardized interface for providers (Local, YouTube, Spotify, Lavalink).
|
|
18
|
+
- 🛠️ **Developer-Friendly**: Full TypeScript support, strict typings, and ESM/CJS builds.
|
|
19
|
+
|
|
20
|
+
## Architecture Overview
|
|
21
|
+
|
|
22
|
+
Audify-js v1.0.2 uses a modular architecture:
|
|
23
|
+
- **AudioEngine**: The central controller orchestrating playback, queue, and events.
|
|
24
|
+
- **ProviderRegistry**: Manages source providers (e.g., resolving URLs to streams).
|
|
25
|
+
- **Player**: Handles low-level audio context and buffer management.
|
|
26
|
+
- **Queue**: Manages track list and state.
|
|
27
|
+
- **PluginManager**: Handles extensions and hooks.
|
|
28
|
+
|
|
29
|
+
## Documentation
|
|
30
|
+
|
|
31
|
+
For more detailed information, check out the documentation:
|
|
32
|
+
|
|
33
|
+
- [Architecture Overview](docs/ARCHITECTURE.md)
|
|
34
|
+
- [Providers System](docs/PROVIDERS.md)
|
|
35
|
+
- [Plugin Development](docs/PLUGINS.md)
|
|
17
36
|
|
|
18
37
|
## Installation
|
|
19
38
|
|
|
@@ -33,17 +52,16 @@ npm install @students-dev/audify-js
|
|
|
33
52
|
</head>
|
|
34
53
|
<body>
|
|
35
54
|
<script type="module">
|
|
36
|
-
import { AudioEngine } from '
|
|
55
|
+
import { AudioEngine } from './dist/esm/index.js';
|
|
37
56
|
|
|
38
57
|
const engine = new AudioEngine();
|
|
39
58
|
|
|
40
|
-
engine.on('ready', () => {
|
|
59
|
+
engine.eventBus.on('ready', () => {
|
|
41
60
|
console.log('Audio engine ready!');
|
|
42
|
-
engine.
|
|
43
|
-
engine.play();
|
|
61
|
+
engine.play('https://example.com/audio.mp3');
|
|
44
62
|
});
|
|
45
63
|
|
|
46
|
-
engine.on('trackStart', (track) => {
|
|
64
|
+
engine.eventBus.on('trackStart', (track) => {
|
|
47
65
|
console.log('Now playing:', track.title);
|
|
48
66
|
});
|
|
49
67
|
</script>
|
|
@@ -54,475 +72,108 @@ npm install @students-dev/audify-js
|
|
|
54
72
|
### Node.js
|
|
55
73
|
|
|
56
74
|
```javascript
|
|
57
|
-
import { AudioEngine } from '@students-dev/audify-js';
|
|
75
|
+
import { AudioEngine, LocalProvider } from '@students-dev/audify-js';
|
|
58
76
|
|
|
59
77
|
const engine = new AudioEngine();
|
|
60
78
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
engine.play();
|
|
64
|
-
});
|
|
65
|
-
```
|
|
66
|
-
|
|
67
|
-
## API Reference
|
|
68
|
-
|
|
69
|
-
### AudioEngine
|
|
70
|
-
|
|
71
|
-
The main class that orchestrates all audio functionality.
|
|
72
|
-
|
|
73
|
-
#### Constructor
|
|
74
|
-
|
|
75
|
-
```javascript
|
|
76
|
-
const engine = new AudioEngine(options);
|
|
77
|
-
```
|
|
78
|
-
|
|
79
|
-
#### Spotify Integration
|
|
80
|
-
|
|
81
|
-
```javascript
|
|
82
|
-
// Initialize Spotify provider
|
|
83
|
-
engine.initSpotify({
|
|
84
|
-
clientId: 'your_client_id',
|
|
85
|
-
clientSecret: 'your_client_secret'
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
// Search tracks
|
|
89
|
-
const results = await engine.searchSpotifyTracks('query', { token: 'access_token' });
|
|
90
|
-
|
|
91
|
-
// Load track
|
|
92
|
-
const track = await engine.loadSpotifyTrack('track_id', { token: 'access_token' });
|
|
93
|
-
```
|
|
94
|
-
|
|
95
|
-
#### Lavalink Integration
|
|
79
|
+
// Engine automatically registers default providers (Local, YouTube)
|
|
80
|
+
// But you can register custom ones or configure them
|
|
96
81
|
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
await engine.connectLavalink({
|
|
100
|
-
host: 'localhost',
|
|
101
|
-
port: 2333,
|
|
102
|
-
password: 'youshallnotpass'
|
|
82
|
+
engine.eventBus.on('ready', async () => {
|
|
83
|
+
await engine.play('./music/song.mp3');
|
|
103
84
|
});
|
|
104
|
-
|
|
105
|
-
// Load track from Lavalink
|
|
106
|
-
const track = await engine.loadLavalinkTrack('ytsearch:query');
|
|
107
|
-
|
|
108
|
-
// Get Lavalink player for Discord bots
|
|
109
|
-
const player = engine.getLavalinkPlayer('guild_id', 'channel_id');
|
|
110
85
|
```
|
|
111
86
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
##### Playback Controls
|
|
115
|
-
|
|
116
|
-
- `play(track?)`: Play a track or resume current playback
|
|
117
|
-
- `pause()`: Pause playback
|
|
118
|
-
- `stop()`: Stop playback
|
|
119
|
-
- `seek(time)`: Seek to specific time (seconds)
|
|
120
|
-
- `setVolume(volume)`: Set volume (0-1)
|
|
121
|
-
|
|
122
|
-
##### Queue Management
|
|
123
|
-
|
|
124
|
-
- `add(tracks)`: Add track(s) to queue
|
|
125
|
-
- `remove(identifier)`: Remove track by index or ID
|
|
126
|
-
- `next()`: Skip to next track
|
|
127
|
-
- `previous()`: Go to previous track
|
|
128
|
-
- `shuffle()`: Shuffle the queue
|
|
129
|
-
- `clear()`: Clear the queue
|
|
130
|
-
- `jump(index)`: Jump to track at index
|
|
87
|
+
## Providers
|
|
131
88
|
|
|
132
|
-
|
|
89
|
+
Providers allow `audify-js` to resolve and play tracks from various sources. v1.0.2 introduces a **Provider Registry**.
|
|
133
90
|
|
|
134
|
-
-
|
|
135
|
-
- `removeFilter(type)`: Remove audio filter
|
|
91
|
+
### Built-in Providers
|
|
136
92
|
|
|
137
|
-
|
|
93
|
+
- **LocalProvider**: Plays local files (Node.js) or direct URLs.
|
|
94
|
+
- **YouTubeProvider**: Resolves YouTube URLs (requires `ytdl-core` in real usage, mock included).
|
|
95
|
+
- **SpotifyProvider**: Integrates with Spotify Web API.
|
|
96
|
+
- **LavalinkProvider**: Connects to Lavalink nodes.
|
|
138
97
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
##### State
|
|
142
|
-
|
|
143
|
-
- `getState()`: Get current engine state
|
|
144
|
-
|
|
145
|
-
#### Events
|
|
146
|
-
|
|
147
|
-
- `ready`: Engine initialized
|
|
148
|
-
- `play`: Playback started
|
|
149
|
-
- `pause`: Playback paused
|
|
150
|
-
- `stop`: Playback stopped
|
|
151
|
-
- `error`: Error occurred
|
|
152
|
-
- `queueEmpty`: Queue became empty
|
|
153
|
-
- `trackStart`: Track started playing
|
|
154
|
-
- `trackEnd`: Track ended
|
|
155
|
-
- `filterApplied`: Filter applied
|
|
156
|
-
- `trackAdd`: Track added to queue
|
|
157
|
-
- `trackRemove`: Track removed from queue
|
|
158
|
-
- `shuffle`: Queue shuffled
|
|
159
|
-
- `clear`: Queue cleared
|
|
160
|
-
|
|
161
|
-
### Queue
|
|
162
|
-
|
|
163
|
-
Manages the audio playback queue.
|
|
98
|
+
### Configuration
|
|
164
99
|
|
|
165
100
|
```javascript
|
|
166
|
-
const
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
queue.previous();
|
|
175
|
-
queue.jump(5);
|
|
176
|
-
|
|
177
|
-
// Modify
|
|
178
|
-
queue.shuffle();
|
|
179
|
-
queue.clear();
|
|
180
|
-
```
|
|
181
|
-
|
|
182
|
-
### Track
|
|
183
|
-
|
|
184
|
-
Represents an audio track.
|
|
185
|
-
|
|
186
|
-
```javascript
|
|
187
|
-
import { Track } from '@students-dev/audify-js';
|
|
188
|
-
|
|
189
|
-
const track = new Track('https://example.com/audio.mp3', {
|
|
190
|
-
title: 'My Song',
|
|
191
|
-
artist: 'Artist Name',
|
|
192
|
-
duration: 180
|
|
193
|
-
});
|
|
194
|
-
```
|
|
195
|
-
|
|
196
|
-
### Filters
|
|
197
|
-
|
|
198
|
-
Apply audio effects.
|
|
199
|
-
|
|
200
|
-
```javascript
|
|
201
|
-
// Bass boost
|
|
202
|
-
engine.applyFilter('bassboost', { gain: 1.5 });
|
|
203
|
-
|
|
204
|
-
// Nightcore
|
|
205
|
-
engine.applyFilter('nightcore', { rate: 1.2 });
|
|
206
|
-
|
|
207
|
-
// 8D Audio
|
|
208
|
-
engine.applyFilter('8d');
|
|
209
|
-
|
|
210
|
-
// Remove filter
|
|
211
|
-
engine.removeFilter('bassboost');
|
|
212
|
-
```
|
|
213
|
-
|
|
214
|
-
Available filters:
|
|
215
|
-
- `bassboost`: Boost low frequencies
|
|
216
|
-
- `nightcore`: Speed up and pitch up
|
|
217
|
-
- `vaporwave`: Slow down and pitch down
|
|
218
|
-
- `8d`: 8D audio rotation effect
|
|
219
|
-
- `pitch`: Adjust pitch
|
|
220
|
-
- `speed`: Adjust playback speed
|
|
221
|
-
- `reverb`: Add reverb effect
|
|
222
|
-
|
|
223
|
-
### Plugins
|
|
224
|
-
|
|
225
|
-
Extend functionality with plugins.
|
|
226
|
-
|
|
227
|
-
```javascript
|
|
228
|
-
import { Plugin } from '@students-dev/audify-js';
|
|
229
|
-
|
|
230
|
-
class MyPlugin extends Plugin {
|
|
231
|
-
constructor() {
|
|
232
|
-
super('my-plugin', '1.0.0');
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
onLoad(engine) {
|
|
236
|
-
console.log('Plugin loaded!');
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
beforePlay(track) {
|
|
240
|
-
console.log('About to play:', track.title);
|
|
101
|
+
const engine = new AudioEngine({
|
|
102
|
+
spotify: {
|
|
103
|
+
clientId: '...',
|
|
104
|
+
clientSecret: '...'
|
|
105
|
+
},
|
|
106
|
+
lavalink: {
|
|
107
|
+
host: 'localhost',
|
|
108
|
+
password: 'youshallnotpass'
|
|
241
109
|
}
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// Load plugin
|
|
245
|
-
const plugin = new MyPlugin();
|
|
246
|
-
engine.pluginManager.load(plugin);
|
|
247
|
-
engine.pluginManager.enable('my-plugin');
|
|
248
|
-
```
|
|
249
|
-
|
|
250
|
-
### Providers
|
|
251
|
-
|
|
252
|
-
Fetch metadata from different sources.
|
|
253
|
-
|
|
254
|
-
```javascript
|
|
255
|
-
import { YouTubeProvider, SoundCloudProvider, LocalProvider, SpotifyProvider, LavalinkProvider } from '@students-dev/audify-js';
|
|
256
|
-
|
|
257
|
-
// YouTube
|
|
258
|
-
const ytInfo = await YouTubeProvider.getInfo('https://youtube.com/watch?v=VIDEO_ID');
|
|
259
|
-
|
|
260
|
-
// SoundCloud
|
|
261
|
-
const scInfo = await SoundCloudProvider.getInfo('https://soundcloud.com/artist/track');
|
|
262
|
-
|
|
263
|
-
// Local file (Node.js only)
|
|
264
|
-
const localInfo = await LocalProvider.getInfo('/path/to/file.mp3');
|
|
265
|
-
|
|
266
|
-
// Spotify (requires access token)
|
|
267
|
-
const spotify = new SpotifyProvider({ clientId: 'your_client_id' });
|
|
268
|
-
spotify.setAccessToken('access_token');
|
|
269
|
-
const trackInfo = await spotify.getTrack('track_id');
|
|
270
|
-
|
|
271
|
-
// Lavalink (requires Lavalink server)
|
|
272
|
-
const lavalink = new LavalinkProvider({ host: 'localhost', port: 2333, password: 'password' });
|
|
273
|
-
await lavalink.connect();
|
|
274
|
-
const lavalinkTrack = await lavalink.loadTrack('ytsearch:query');
|
|
275
|
-
```
|
|
276
|
-
|
|
277
|
-
### Utils
|
|
278
|
-
|
|
279
|
-
Utility functions for common tasks.
|
|
280
|
-
|
|
281
|
-
```javascript
|
|
282
|
-
import { TimeUtils, MetadataUtils, ProbeUtils } from '@students-dev/audify-js';
|
|
283
|
-
|
|
284
|
-
// Time formatting
|
|
285
|
-
TimeUtils.format(125); // "02:05"
|
|
286
|
-
|
|
287
|
-
// Metadata extraction
|
|
288
|
-
const metadata = MetadataUtils.extract('https://example.com/song.mp3');
|
|
289
|
-
|
|
290
|
-
// Audio probing
|
|
291
|
-
const probe = await ProbeUtils.probe(audioBuffer);
|
|
292
|
-
```
|
|
293
|
-
|
|
294
|
-
## Examples
|
|
295
|
-
|
|
296
|
-
The `examples/` directory contains comprehensive examples demonstrating various features:
|
|
297
|
-
|
|
298
|
-
### 📁 Available Examples
|
|
299
|
-
|
|
300
|
-
- **`browser-example.html`** - Interactive browser demo with UI controls
|
|
301
|
-
- **`nodejs-example.js`** - Node.js usage with event handling
|
|
302
|
-
- **`queue-example.js`** - Queue management operations
|
|
303
|
-
- **`plugin-examples.js`** - Custom plugin implementations
|
|
304
|
-
- **`spotify-example.js`** - Spotify API integration
|
|
305
|
-
- **`lavalink-example.js`** - Lavalink server integration
|
|
306
|
-
|
|
307
|
-
### Basic Playback
|
|
308
|
-
|
|
309
|
-
```javascript
|
|
310
|
-
import { AudioEngine } from '@students-dev/audify-js';
|
|
311
|
-
|
|
312
|
-
const engine = new AudioEngine();
|
|
313
|
-
|
|
314
|
-
engine.on('ready', async () => {
|
|
315
|
-
// Add tracks
|
|
316
|
-
engine.add([
|
|
317
|
-
'track1.mp3',
|
|
318
|
-
'track2.mp3',
|
|
319
|
-
'https://example.com/track3.mp3'
|
|
320
|
-
]);
|
|
321
|
-
|
|
322
|
-
// Start playing
|
|
323
|
-
await engine.play();
|
|
324
|
-
|
|
325
|
-
// Apply filter
|
|
326
|
-
engine.applyFilter('bassboost');
|
|
327
|
-
});
|
|
328
|
-
|
|
329
|
-
// Handle events
|
|
330
|
-
engine.on('trackStart', (track) => {
|
|
331
|
-
console.log(`Playing: ${track.title}`);
|
|
332
110
|
});
|
|
333
|
-
|
|
334
|
-
engine.on('error', (error) => {
|
|
335
|
-
console.error('Playback error:', error);
|
|
336
|
-
});
|
|
337
|
-
```
|
|
338
|
-
|
|
339
|
-
### Queue Management
|
|
340
|
-
|
|
341
|
-
```javascript
|
|
342
|
-
// Add multiple tracks
|
|
343
|
-
engine.add([
|
|
344
|
-
{ url: 'song1.mp3', title: 'Song One' },
|
|
345
|
-
{ url: 'song2.mp3', title: 'Song Two' }
|
|
346
|
-
]);
|
|
347
|
-
|
|
348
|
-
// Navigation
|
|
349
|
-
engine.next();
|
|
350
|
-
engine.previous();
|
|
351
|
-
engine.jump(2); // Jump to track at index 2
|
|
352
|
-
|
|
353
|
-
// Modify queue
|
|
354
|
-
engine.shuffle();
|
|
355
|
-
engine.clear();
|
|
356
|
-
|
|
357
|
-
// Remove specific track
|
|
358
|
-
engine.remove(0); // Remove by index
|
|
359
|
-
engine.remove('track-id'); // Remove by ID
|
|
360
111
|
```
|
|
361
112
|
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
```javascript
|
|
365
|
-
// Bass boost
|
|
366
|
-
engine.applyFilter('bassboost', { gain: 1.5 });
|
|
367
|
-
|
|
368
|
-
// Nightcore effect
|
|
369
|
-
engine.applyFilter('nightcore', { rate: 1.2 });
|
|
370
|
-
|
|
371
|
-
// Vaporwave effect
|
|
372
|
-
engine.applyFilter('vaporwave', { rate: 0.8 });
|
|
113
|
+
## Plugins
|
|
373
114
|
|
|
374
|
-
|
|
375
|
-
engine.applyFilter('8d');
|
|
115
|
+
Create powerful extensions using the `Plugin` class.
|
|
376
116
|
|
|
377
|
-
|
|
378
|
-
|
|
117
|
+
```typescript
|
|
118
|
+
import { Plugin, IAudioEngine } from '@students-dev/audify-js';
|
|
379
119
|
|
|
380
|
-
|
|
381
|
-
engine.applyFilter('speed', { speed: 1.25 });
|
|
382
|
-
|
|
383
|
-
// Reverb
|
|
384
|
-
engine.applyFilter('reverb', { preset: 'hall' });
|
|
385
|
-
|
|
386
|
-
// Remove filter
|
|
387
|
-
engine.removeFilter('bassboost');
|
|
388
|
-
```
|
|
389
|
-
|
|
390
|
-
### Custom Plugin
|
|
391
|
-
|
|
392
|
-
```javascript
|
|
393
|
-
import { Plugin } from '@students-dev/audify-js';
|
|
394
|
-
|
|
395
|
-
class LoggerPlugin extends Plugin {
|
|
120
|
+
class MyLoggerPlugin extends Plugin {
|
|
396
121
|
constructor() {
|
|
397
|
-
super('logger');
|
|
122
|
+
super('logger', '1.0.0');
|
|
398
123
|
}
|
|
399
124
|
|
|
400
|
-
|
|
401
|
-
console.log(
|
|
125
|
+
onLoad(engine: IAudioEngine) {
|
|
126
|
+
console.log('Plugin loaded');
|
|
402
127
|
}
|
|
403
128
|
|
|
404
|
-
|
|
405
|
-
console.log(
|
|
129
|
+
beforePlay(track: any) {
|
|
130
|
+
console.log('About to play:', track.title);
|
|
406
131
|
}
|
|
407
132
|
|
|
408
|
-
trackEnd(track) {
|
|
409
|
-
console.log(
|
|
133
|
+
trackEnd(track: any) {
|
|
134
|
+
console.log('Finished:', track.title);
|
|
410
135
|
}
|
|
411
136
|
}
|
|
412
137
|
|
|
413
|
-
// Register
|
|
414
|
-
const
|
|
415
|
-
engine.
|
|
416
|
-
engine.
|
|
417
|
-
```
|
|
418
|
-
|
|
419
|
-
### Browser Usage
|
|
420
|
-
|
|
421
|
-
```html
|
|
422
|
-
<!DOCTYPE html>
|
|
423
|
-
<html>
|
|
424
|
-
<head>
|
|
425
|
-
<title>audify-js Demo</title>
|
|
426
|
-
</head>
|
|
427
|
-
<body>
|
|
428
|
-
<button id="playBtn">Play</button>
|
|
429
|
-
<button id="bassBtn">Bass Boost</button>
|
|
430
|
-
|
|
431
|
-
<script type="module">
|
|
432
|
-
import { AudioEngine } from '@students-dev/audify-js';
|
|
433
|
-
|
|
434
|
-
const engine = new AudioEngine();
|
|
435
|
-
|
|
436
|
-
engine.on('ready', () => {
|
|
437
|
-
engine.add('audio.mp3');
|
|
438
|
-
|
|
439
|
-
document.getElementById('playBtn').onclick = () => engine.play();
|
|
440
|
-
document.getElementById('bassBtn').onclick = () =>
|
|
441
|
-
engine.applyFilter('bassboost');
|
|
442
|
-
});
|
|
443
|
-
</script>
|
|
444
|
-
</body>
|
|
445
|
-
</html>
|
|
138
|
+
// Register
|
|
139
|
+
const plugin = new MyLoggerPlugin();
|
|
140
|
+
engine.plugins.load(plugin);
|
|
141
|
+
engine.plugins.enable('logger');
|
|
446
142
|
```
|
|
447
143
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
```bash
|
|
451
|
-
# Browser example
|
|
452
|
-
# Open examples/browser-example.html in your browser
|
|
453
|
-
|
|
454
|
-
# Node.js examples
|
|
455
|
-
node examples/nodejs-example.js
|
|
456
|
-
node examples/queue-example.js
|
|
457
|
-
```
|
|
144
|
+
## API Reference
|
|
458
145
|
|
|
459
|
-
|
|
146
|
+
### AudioEngine
|
|
460
147
|
|
|
461
|
-
-
|
|
462
|
-
-
|
|
463
|
-
-
|
|
464
|
-
-
|
|
148
|
+
- `play(track?: ITrack | string)`: Play a track object or resolve a string (URL/ID).
|
|
149
|
+
- `pause()`: Pause playback.
|
|
150
|
+
- `stop()`: Stop playback.
|
|
151
|
+
- `seek(time)`: Seek to time in seconds.
|
|
152
|
+
- `setVolume(volume)`: 0.0 to 1.0.
|
|
153
|
+
- `setLoopMode(mode)`: 'off', 'track', 'queue'.
|
|
154
|
+
- `add(tracks)`: Add to queue.
|
|
155
|
+
- `next()`: Skip to next.
|
|
156
|
+
- `previous()`: Skip to previous.
|
|
157
|
+
- `shuffle()`: Shuffle queue.
|
|
158
|
+
- `getProvider(name)`: Get a provider instance.
|
|
465
159
|
|
|
466
|
-
|
|
160
|
+
### Events
|
|
467
161
|
|
|
468
|
-
|
|
162
|
+
Access via `engine.eventBus.on(event, callback)`.
|
|
469
163
|
|
|
470
|
-
|
|
164
|
+
- `ready`
|
|
165
|
+
- `play`, `pause`, `stop`
|
|
166
|
+
- `trackStart`, `trackEnd`
|
|
167
|
+
- `queueUpdate`
|
|
168
|
+
- `error`
|
|
471
169
|
|
|
472
170
|
## Contributing
|
|
473
171
|
|
|
474
172
|
1. Fork the repository
|
|
475
|
-
2. Create
|
|
476
|
-
3. Commit
|
|
477
|
-
4. Push
|
|
478
|
-
5. Open a Pull Request
|
|
173
|
+
2. Create feature branch
|
|
174
|
+
3. Commit changes
|
|
175
|
+
4. Push and PR
|
|
479
176
|
|
|
480
177
|
## License
|
|
481
178
|
|
|
482
|
-
MIT
|
|
483
|
-
|
|
484
|
-
## Troubleshooting
|
|
485
|
-
|
|
486
|
-
### Audio not playing in browser
|
|
487
|
-
|
|
488
|
-
Ensure you're handling user interaction requirements for Web Audio API:
|
|
489
|
-
|
|
490
|
-
```javascript
|
|
491
|
-
// Resume AudioContext on user interaction
|
|
492
|
-
document.addEventListener('click', () => {
|
|
493
|
-
if (engine.audioContext.state === 'suspended') {
|
|
494
|
-
engine.audioContext.resume();
|
|
495
|
-
}
|
|
496
|
-
});
|
|
497
|
-
```
|
|
498
|
-
|
|
499
|
-
### CORS issues with remote audio
|
|
500
|
-
|
|
501
|
-
When loading audio from different domains, ensure proper CORS headers are set on the server.
|
|
502
|
-
|
|
503
|
-
### Node.js audio output
|
|
504
|
-
|
|
505
|
-
For actual audio playback in Node.js, you may need additional packages like `speaker` or `node-speaker`.
|
|
506
|
-
|
|
507
|
-
### Filter not working
|
|
508
|
-
|
|
509
|
-
Some filters require AudioWorklet support in modern browsers. Check browser compatibility.
|
|
510
|
-
|
|
511
|
-
## Changelog
|
|
512
|
-
|
|
513
|
-
### v1.1.0
|
|
514
|
-
- Added Spotify integration with client-side API support
|
|
515
|
-
- Added Lavalink integration for server-based audio streaming
|
|
516
|
-
- Updated dependencies for better performance and security
|
|
517
|
-
- Enhanced TypeScript type definitions
|
|
518
|
-
- Added comprehensive examples for new integrations
|
|
519
|
-
|
|
520
|
-
### v1.0.0
|
|
521
|
-
- Initial release
|
|
522
|
-
- Core audio engine
|
|
523
|
-
- Queue management
|
|
524
|
-
- Audio filters
|
|
525
|
-
- Plugin system
|
|
526
|
-
- Event system
|
|
527
|
-
- Provider abstractions
|
|
528
|
-
- Utility functions
|
|
179
|
+
MIT
|