@scarlett-player/core 0.5.2 → 0.5.3

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
@@ -1887,8 +1887,9 @@ class ScarlettPlayer {
1887
1887
  */
1888
1888
  setPlaybackRate(rate) {
1889
1889
  this.checkDestroyed();
1890
- this.stateManager.set("playbackRate", rate);
1891
- this.eventBus.emit("playback:ratechange", { rate });
1890
+ const clampedRate = Math.max(0.0625, Math.min(16, rate));
1891
+ this.stateManager.set("playbackRate", clampedRate);
1892
+ this.eventBus.emit("playback:ratechange", { rate: clampedRate });
1892
1893
  }
1893
1894
  /**
1894
1895
  * Set autoplay state.
@@ -2017,6 +2018,13 @@ class ScarlettPlayer {
2017
2018
  }
2018
2019
  const provider = this._currentProvider;
2019
2020
  if (typeof provider.setLevel === "function") {
2021
+ if (index !== -1) {
2022
+ const levels = this.getQualities();
2023
+ if (levels.length > 0 && (index < 0 || index >= levels.length)) {
2024
+ this.logger.warn(`Invalid quality index: ${index} (available: ${levels.length})`);
2025
+ return;
2026
+ }
2027
+ }
2020
2028
  provider.setLevel(index);
2021
2029
  this.eventBus.emit("quality:change", {
2022
2030
  quality: index === -1 ? "auto" : `level-${index}`,
@@ -2257,18 +2265,40 @@ class ScarlettPlayer {
2257
2265
  * @private
2258
2266
  */
2259
2267
  detectMimeType(source) {
2260
- const ext = source.split(".").pop()?.toLowerCase();
2268
+ let path = source;
2269
+ try {
2270
+ path = new URL(source).pathname;
2271
+ } catch {
2272
+ const noQuery = source.split("?")[0] ?? source;
2273
+ path = noQuery.split("#")[0] ?? noQuery;
2274
+ }
2275
+ const ext = path.split(".").pop()?.toLowerCase() ?? "";
2261
2276
  switch (ext) {
2262
2277
  case "m3u8":
2263
2278
  return "application/x-mpegURL";
2264
2279
  case "mpd":
2265
2280
  return "application/dash+xml";
2266
2281
  case "mp4":
2282
+ case "m4v":
2267
2283
  return "video/mp4";
2268
2284
  case "webm":
2269
2285
  return "video/webm";
2270
2286
  case "ogg":
2287
+ case "ogv":
2271
2288
  return "video/ogg";
2289
+ case "mov":
2290
+ return "video/quicktime";
2291
+ case "mkv":
2292
+ return "video/x-matroska";
2293
+ case "mp3":
2294
+ return "audio/mpeg";
2295
+ case "wav":
2296
+ return "audio/wav";
2297
+ case "flac":
2298
+ return "audio/flac";
2299
+ case "aac":
2300
+ case "m4a":
2301
+ return "audio/mp4";
2272
2302
  default:
2273
2303
  return "video/mp4";
2274
2304
  }