@twick/timeline 0.14.11 → 0.14.12

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/dist/index.js CHANGED
@@ -221,6 +221,12 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
221
221
  const isSafeUrl = /^(https?:|blob:|data:)/i.test(src);
222
222
  if (!isSafeUrl) throw new Error("Unsafe media source URL");
223
223
  const audioBuffer = await fetchAndDecodeAudio(src);
224
+ if (audioBuffer.duration === 0 || audioBuffer.length === 0) {
225
+ throw new Error("No audio track found in the media source");
226
+ }
227
+ if (isAudioSilent(audioBuffer)) {
228
+ throw new Error("Audio track is silent (no audio content detected)");
229
+ }
224
230
  const clampedStart = Math.max(0, start || 0);
225
231
  const fullDuration = audioBuffer.duration;
226
232
  const clampedEnd = Math.min(
@@ -262,13 +268,24 @@ var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "sy
262
268
  audioContext.decodeAudioData(
263
269
  arrayBuffer.slice(0),
264
270
  (buf) => resolve(buf),
265
- (err) => reject(err || new Error("Failed to decode audio"))
271
+ (err) => reject(err || new Error("Failed to decode audio: no audio track found or unsupported format"))
266
272
  );
267
273
  });
268
274
  } finally {
269
275
  audioContext.close();
270
276
  }
271
277
  };
278
+ const isAudioSilent = (buffer, threshold = 1e-3) => {
279
+ for (let channel = 0; channel < buffer.numberOfChannels; channel++) {
280
+ const channelData = buffer.getChannelData(channel);
281
+ for (let i2 = 0; i2 < channelData.length; i2 += 100) {
282
+ if (Math.abs(channelData[i2]) > threshold) {
283
+ return false;
284
+ }
285
+ }
286
+ }
287
+ return true;
288
+ };
272
289
  const renderAudioSegment = async (audioBuffer, start, end, playbackRate) => {
273
290
  const OfflineAudioContextCtor = window.OfflineAudioContext || window.webkitOfflineAudioContext;
274
291
  if (!OfflineAudioContextCtor) throw new Error("OfflineAudioContext not supported");