gapless 4.4.0 → 4.4.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gapless",
3
- "version": "4.4.0",
3
+ "version": "4.4.2",
4
4
  "description": "Gapless audio playback javascript plugin",
5
5
  "type": "module",
6
6
  "main": "dist/index.mjs",
@@ -27,22 +27,22 @@
27
27
  "author": "Daniel Saewitz",
28
28
  "license": "MIT",
29
29
  "devDependencies": {
30
- "@playwright/test": "^1.60.0",
30
+ "@playwright/test": "^1.63.0",
31
31
  "@switz/eslint-config": "^13.1.0",
32
- "@vitest/coverage-v8": "^4.1.8",
33
- "eslint": "^10.4.1",
34
- "happy-dom": "^20.10.2",
35
- "playwright": "^1.60.0",
32
+ "@vitest/coverage-v8": "^5.0.1",
33
+ "eslint": "^10.11.0",
34
+ "happy-dom": "^20.14.5",
35
+ "playwright": "^1.63.0",
36
36
  "tsup": "^8.5.1",
37
- "typescript": "^6.0.3",
38
- "vitest": "^4.1.8"
37
+ "typescript": "^7.0.2",
38
+ "vitest": "^5.0.1"
39
39
  },
40
40
  "dependencies": {
41
- "xstate": "^5.32.0"
41
+ "xstate": "^5.33.2"
42
42
  },
43
43
  "scripts": {
44
44
  "test": "vitest run",
45
- "build": "tsup",
45
+ "build": "tsup && tsc -p tsconfig.build.json",
46
46
  "build:demo": "pnpm --dir demo build",
47
47
  "dev": "pnpm --dir demo dev",
48
48
  "types": "tsc --noEmit",
package/src/Queue.ts CHANGED
@@ -198,8 +198,9 @@ export class Queue implements TrackQueueRef {
198
198
  const e = event as { type: 'SEEK'; time: number };
199
199
  this._trackAt(context.currentTrackIndex)?.seek(e.time);
200
200
  },
201
- seekCurrentToZero: ({ context }) => {
202
- this._trackAt(context.currentTrackIndex)?.seek(0);
201
+ seekCurrentToStartTime: ({ context, event }) => {
202
+ const e = event as { type: 'GOTO'; startTime?: number };
203
+ this._trackAt(context.currentTrackIndex)?.seek(e.startTime ?? 0);
203
204
  },
204
205
  scheduleGapless: ({ context }) => {
205
206
  this._tryScheduleGapless(context.currentTrackIndex);
@@ -278,12 +279,12 @@ export class Queue implements TrackQueueRef {
278
279
  this._actor.send({ type: 'PREVIOUS' });
279
280
  }
280
281
 
281
- gotoTrack(index: number, playImmediately = false): void {
282
+ gotoTrack(index: number, playImmediately = false, startTime?: number): void {
282
283
  if (index < 0 || index >= this._tracks.length) return;
283
284
  this.onDebug(
284
- `gotoTrack(${index}, playImmediately=${playImmediately}) queueState=${this._actor.getSnapshot().value} curIdx=${this._actor.getSnapshot().context.currentTrackIndex}`
285
+ `gotoTrack(${index}, playImmediately=${playImmediately}, startTime=${startTime}) queueState=${this._actor.getSnapshot().value} curIdx=${this._actor.getSnapshot().context.currentTrackIndex}`
285
286
  );
286
- this._actor.send({ type: 'GOTO', index, playImmediately });
287
+ this._actor.send({ type: 'GOTO', index, playImmediately, startTime });
287
288
  }
288
289
 
289
290
  seek(time: number): void {
package/src/Track.ts CHANGED
@@ -637,7 +637,11 @@ export class Track {
637
637
  private _crossoverHtml5ToWebAudio(wasPlaying: boolean): void {
638
638
  if (!this.ctx || !this.audioBuffer || !this.gainNode) return;
639
639
 
640
- const offset = this.audio.currentTime;
640
+ const htmlTime = this.audio.currentTime;
641
+ const offset =
642
+ isFinite(this.pausedAtTrackTime) && this.pausedAtTrackTime > htmlTime
643
+ ? this.pausedAtTrackTime
644
+ : htmlTime;
641
645
  this.pausedAtTrackTime = isFinite(offset) ? offset : 0;
642
646
 
643
647
  if (!wasPlaying) {
@@ -33,7 +33,7 @@ export type QueueEvent =
33
33
  | { type: 'TOGGLE' }
34
34
  | { type: 'NEXT' }
35
35
  | { type: 'PREVIOUS' }
36
- | { type: 'GOTO'; index: number; playImmediately?: boolean }
36
+ | { type: 'GOTO'; index: number; playImmediately?: boolean; startTime?: number }
37
37
  | { type: 'SEEK'; time: number }
38
38
  | { type: 'SET_VOLUME'; volume: number }
39
39
  | { type: 'ADD_TRACK' }
@@ -113,7 +113,7 @@ export function createQueueMachine(initialContext: QueueContext) {
113
113
  playCurrent: () => {},
114
114
  pauseCurrent: () => {},
115
115
  seekCurrent: () => {},
116
- seekCurrentToZero: () => {},
116
+ seekCurrentToStartTime: () => {},
117
117
  scheduleGapless: () => {},
118
118
  cancelScheduledGapless: () => {},
119
119
  cancelAndRescheduleGapless: () => {},
@@ -151,6 +151,7 @@ export function createQueueMachine(initialContext: QueueContext) {
151
151
  'deactivateCurrent',
152
152
  'cancelAllGapless',
153
153
  'gotoTrackIndex',
154
+ 'seekCurrentToStartTime',
154
155
  'activateAndPlayCurrent',
155
156
  'notifyStartNewTrack',
156
157
  'updateMediaSessionMetadata',
@@ -163,7 +164,7 @@ export function createQueueMachine(initialContext: QueueContext) {
163
164
  'deactivateCurrent',
164
165
  'cancelAllGapless',
165
166
  'gotoTrackIndex',
166
- 'seekCurrentToZero',
167
+ 'seekCurrentToStartTime',
167
168
  'preloadAhead',
168
169
  ],
169
170
  },
@@ -239,6 +240,7 @@ export function createQueueMachine(initialContext: QueueContext) {
239
240
  'deactivateCurrent',
240
241
  'cancelAllGapless',
241
242
  'gotoTrackIndex',
243
+ 'seekCurrentToStartTime',
242
244
  'activateAndPlayCurrent',
243
245
  'notifyStartNewTrack',
244
246
  'updateMediaSessionMetadata',
@@ -250,7 +252,7 @@ export function createQueueMachine(initialContext: QueueContext) {
250
252
  'deactivateCurrent',
251
253
  'cancelAllGapless',
252
254
  'gotoTrackIndex',
253
- 'seekCurrentToZero',
255
+ 'seekCurrentToStartTime',
254
256
  'preloadAhead',
255
257
  ],
256
258
  },
@@ -353,6 +355,7 @@ export function createQueueMachine(initialContext: QueueContext) {
353
355
  'deactivateCurrent',
354
356
  'cancelAllGapless',
355
357
  'gotoTrackIndex',
358
+ 'seekCurrentToStartTime',
356
359
  'activateAndPlayCurrent',
357
360
  'notifyStartNewTrack',
358
361
  'updateMediaSessionMetadata',
@@ -364,7 +367,7 @@ export function createQueueMachine(initialContext: QueueContext) {
364
367
  'deactivateCurrent',
365
368
  'cancelAllGapless',
366
369
  'gotoTrackIndex',
367
- 'seekCurrentToZero',
370
+ 'seekCurrentToStartTime',
368
371
  'preloadAhead',
369
372
  ],
370
373
  },
@@ -421,6 +424,7 @@ export function createQueueMachine(initialContext: QueueContext) {
421
424
  'deactivateCurrent',
422
425
  'cancelAllGapless',
423
426
  'gotoTrackIndex',
427
+ 'seekCurrentToStartTime',
424
428
  'activateAndPlayCurrent',
425
429
  'notifyStartNewTrack',
426
430
  'updateMediaSessionMetadata',
@@ -433,7 +437,7 @@ export function createQueueMachine(initialContext: QueueContext) {
433
437
  'deactivateCurrent',
434
438
  'cancelAllGapless',
435
439
  'gotoTrackIndex',
436
- 'seekCurrentToZero',
440
+ 'seekCurrentToStartTime',
437
441
  'preloadAhead',
438
442
  ],
439
443
  },