@bycrux/editor 0.6.0 → 0.6.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": "@bycrux/editor",
3
- "version": "0.6.0",
3
+ "version": "0.6.2",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "exports": {
@@ -62,6 +62,9 @@ function OverlayVideo({ src, currentTime, itemStart, inPoint, isPlaying, muted,
62
62
  return (
63
63
  <video
64
64
  ref={ref}
65
+ // Anonymous CORS so cross-origin R2 clips aren't tainted (would mute the
66
+ // Web Audio graph). crossOrigin must be set before src. R2 sends ACAO.
67
+ crossOrigin="anonymous"
65
68
  src={src}
66
69
  muted={muted}
67
70
  preload="auto"
@@ -132,6 +132,10 @@ export default function PreviewPlayer({
132
132
  {/* Slot 0 */}
133
133
  <video
134
134
  ref={video0Ref}
135
+ // Clips load cross-origin from R2; without this the media is CORS-tainted
136
+ // and the Web Audio createMediaElementSource graph outputs silence. R2
137
+ // sends Access-Control-Allow-Origin, so anonymous CORS keeps it audible.
138
+ crossOrigin="anonymous"
135
139
  onLoadedMetadata={(e) => { const v = e.currentTarget; if (v.videoWidth && v.videoHeight) setVideoDims({ w: v.videoWidth, h: v.videoHeight }) }}
136
140
  onTimeUpdate={() => { if (activeSlotRef.current === 0) handleTimeUpdate() }}
137
141
  onEnded={() => { if (activeSlotRef.current === 0) handleEnded() }}
@@ -143,6 +147,9 @@ export default function PreviewPlayer({
143
147
  {/* Slot 1 */}
144
148
  <video
145
149
  ref={video1Ref}
150
+ // See slot 0: anonymous CORS so R2 cross-origin clips aren't tainted
151
+ // (which would mute the Web Audio graph).
152
+ crossOrigin="anonymous"
146
153
  onLoadedMetadata={(e) => { const v = e.currentTarget; if (v.videoWidth && v.videoHeight) setVideoDims({ w: v.videoWidth, h: v.videoHeight }) }}
147
154
  onTimeUpdate={() => { if (activeSlotRef.current === 1) handleTimeUpdate() }}
148
155
  onEnded={() => { if (activeSlotRef.current === 1) handleEnded() }}
@@ -185,6 +185,29 @@ export function useVideoPlayback(
185
185
  }
186
186
  }
187
187
 
188
+ /**
189
+ * Start playback on a wired <video> from a user gesture. Video frame
190
+ * production is gated on the shared AudioContext clock running, and the
191
+ * context is created suspended inside a useEffect — so the FIRST play after a
192
+ * hard refresh fires while resume() is still pending and renders no frames
193
+ * until the next seek. resume() is gesture-credited at the synchronous call
194
+ * site here, so wait for it to actually resolve to 'running' before calling
195
+ * play(); the page already has sticky activation from the click, so the
196
+ * deferred play() is not autoplay-blocked.
197
+ */
198
+ function playFromGesture(video: HTMLVideoElement) {
199
+ const w = window as Window & MontajWindow
200
+ const ctx = w.__montajSharedCtx
201
+ if (ctx && ctx.state === 'suspended') {
202
+ ctx.resume().then(
203
+ () => { void video.play().catch(() => {}) },
204
+ () => { void video.play().catch(() => {}) },
205
+ )
206
+ } else {
207
+ void video.play().catch(() => {})
208
+ }
209
+ }
210
+
188
211
  function ensureVideoGain(slot: 0 | 1): GainNode | null {
189
212
  if (videoGainRef.current[slot]) return videoGainRef.current[slot]
190
213
  const video = slot === 0 ? video0Ref.current : video1Ref.current
@@ -447,7 +470,7 @@ export function useVideoPlayback(
447
470
  }
448
471
  const video = getActiveVideo()
449
472
  if (!video) return
450
- if (video.paused) { video.play().catch(() => {}) } else { video.pause() }
473
+ if (video.paused) { playFromGesture(video) } else { video.pause() }
451
474
  }
452
475
  }
453
476
  document.addEventListener('keydown', onKeyDown)
@@ -815,7 +838,7 @@ export function useVideoPlayback(
815
838
  }
816
839
  const video = getActiveVideo()
817
840
  if (!video) return
818
- if (video.paused) { video.play().catch(() => {}) } else { video.pause() }
841
+ if (video.paused) { playFromGesture(video) } else { video.pause() }
819
842
  }
820
843
 
821
844
  return {