avbridge 2.9.0 → 2.10.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.
@@ -1376,6 +1376,10 @@ var AudioOutput = class {
1376
1376
  _volume = 1;
1377
1377
  /** User-set muted flag. When true, gain is forced to 0. */
1378
1378
  _muted = false;
1379
+ /** Playback rate. Scales the media clock and each AudioBufferSourceNode's
1380
+ * playbackRate so audio pitches up/down accordingly (same as native
1381
+ * <video>.playbackRate). Default 1. */
1382
+ _rate = 1;
1379
1383
  constructor() {
1380
1384
  this.ctx = new AudioContext();
1381
1385
  this.gain = this.ctx.createGain();
@@ -1397,6 +1401,20 @@ var AudioOutput = class {
1397
1401
  getMuted() {
1398
1402
  return this._muted;
1399
1403
  }
1404
+ /** Set playback rate. Scales the media clock and pitches audio output
1405
+ * (same as native <video>.playbackRate — speed without pitch correction).
1406
+ * Rebases the anchor so the clock transition is seamless. */
1407
+ setPlaybackRate(rate) {
1408
+ if (rate === this._rate) return;
1409
+ const t = this.now();
1410
+ this.mediaTimeOfAnchor = t;
1411
+ this.ctxTimeAtAnchor = this.ctx.currentTime;
1412
+ this.wallAnchorMs = performance.now();
1413
+ this._rate = rate;
1414
+ }
1415
+ getPlaybackRate() {
1416
+ return this._rate;
1417
+ }
1400
1418
  applyGain() {
1401
1419
  const target = this._muted ? 0 : this._volume;
1402
1420
  try {
@@ -1417,12 +1435,12 @@ var AudioOutput = class {
1417
1435
  now() {
1418
1436
  if (this.noAudio) {
1419
1437
  if (this.state === "playing") {
1420
- return this.mediaTimeOfAnchor + (performance.now() - this.wallAnchorMs) / 1e3;
1438
+ return this.mediaTimeOfAnchor + (performance.now() - this.wallAnchorMs) / 1e3 * this._rate;
1421
1439
  }
1422
1440
  return this.mediaTimeOfAnchor;
1423
1441
  }
1424
1442
  if (this.state === "playing") {
1425
- return this.mediaTimeOfAnchor + (this.ctx.currentTime - this.ctxTimeAtAnchor);
1443
+ return this.mediaTimeOfAnchor + (this.ctx.currentTime - this.ctxTimeAtAnchor) * this._rate;
1426
1444
  }
1427
1445
  return this.mediaTimeOfAnchor;
1428
1446
  }
@@ -1474,7 +1492,8 @@ var AudioOutput = class {
1474
1492
  const node = this.ctx.createBufferSource();
1475
1493
  node.buffer = buffer;
1476
1494
  node.connect(this.gain);
1477
- let ctxStart = this.ctxTimeAtAnchor + (this.mediaTimeOfNext - this.mediaTimeOfAnchor);
1495
+ if (this._rate !== 1) node.playbackRate.value = this._rate;
1496
+ let ctxStart = this.ctxTimeAtAnchor + (this.mediaTimeOfNext - this.mediaTimeOfAnchor) / this._rate;
1478
1497
  if (ctxStart < this.ctx.currentTime) {
1479
1498
  this.ctxTimeAtAnchor = this.ctx.currentTime;
1480
1499
  this.mediaTimeOfAnchor = this.mediaTimeOfNext;
@@ -2122,6 +2141,14 @@ async function createHybridSession(ctx, target, transport) {
2122
2141
  get: () => ctx.duration ?? NaN
2123
2142
  });
2124
2143
  }
2144
+ Object.defineProperty(target, "playbackRate", {
2145
+ configurable: true,
2146
+ get: () => audio.getPlaybackRate(),
2147
+ set: (v) => {
2148
+ audio.setPlaybackRate(v);
2149
+ target.dispatchEvent(new Event("ratechange"));
2150
+ }
2151
+ });
2125
2152
  Object.defineProperty(target, "readyState", {
2126
2153
  configurable: true,
2127
2154
  get: () => {
@@ -2232,6 +2259,7 @@ async function createHybridSession(ctx, target, transport) {
2232
2259
  delete target.muted;
2233
2260
  delete target.readyState;
2234
2261
  delete target.seekable;
2262
+ delete target.playbackRate;
2235
2263
  } catch {
2236
2264
  }
2237
2265
  },
@@ -2767,6 +2795,14 @@ async function createFallbackSession(ctx, target, transport) {
2767
2795
  get: () => ctx.duration ?? NaN
2768
2796
  });
2769
2797
  }
2798
+ Object.defineProperty(target, "playbackRate", {
2799
+ configurable: true,
2800
+ get: () => audio.getPlaybackRate(),
2801
+ set: (v) => {
2802
+ audio.setPlaybackRate(v);
2803
+ target.dispatchEvent(new Event("ratechange"));
2804
+ }
2805
+ });
2770
2806
  Object.defineProperty(target, "readyState", {
2771
2807
  configurable: true,
2772
2808
  get: () => {
@@ -2898,6 +2934,7 @@ async function createFallbackSession(ctx, target, transport) {
2898
2934
  delete target.muted;
2899
2935
  delete target.readyState;
2900
2936
  delete target.seekable;
2937
+ delete target.playbackRate;
2901
2938
  } catch {
2902
2939
  }
2903
2940
  },
@@ -3506,5 +3543,5 @@ exports.NATIVE_VIDEO_CODECS = NATIVE_VIDEO_CODECS;
3506
3543
  exports.UnifiedPlayer = UnifiedPlayer;
3507
3544
  exports.classifyContext = classifyContext;
3508
3545
  exports.createPlayer = createPlayer;
3509
- //# sourceMappingURL=chunk-EY6DZEDT.cjs.map
3510
- //# sourceMappingURL=chunk-EY6DZEDT.cjs.map
3546
+ //# sourceMappingURL=chunk-NQULEIA3.cjs.map
3547
+ //# sourceMappingURL=chunk-NQULEIA3.cjs.map