@video-lab/player-core 4.1.2 → 4.1.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/README.md CHANGED
@@ -103,7 +103,7 @@ window.addEventListener('pagehide', () => player.destroy(), { once: true })
103
103
 
104
104
  **换内核会明确报错。** hls.js / flv.js 的内核插件在构造时注册,运行时换不了。`load()` 一个需要不同内核的源时抛 `E_METHOD_NOT_SUPPORTED`,而不是悄悄播不出来。消费方需要销毁 player 用新 source 重建。
105
105
 
106
- **新源加载失败只经 `error` 事件报告一次。** `load()` 在这次换源有结论时 resolve:新源起播、源故障已通过 `error` 报出、被更新的 `load()` 取代或播放器销毁。它只在换源前的校验失败(非法 source、换内核、改构造期配置、选不出可播放源)时 reject(ADR-136)。
106
+ **新源加载失败只经 `error` 事件报告一次。** `load()` 在这次换源有结论时 resolve:新源起播、源故障已通过 `error` 报出、被更新的 `load()` 取代或播放器销毁。它只在换源前的校验失败(非法 source、换内核、改构造期配置、选不出可播放源)时 reject(ADR-136);reject 前会先暂停旧源,避免它在错误层下继续播放(ADR-137)。
107
107
 
108
108
  **直播的 `duration` 是 0,不是 Infinity。** Infinity 过不了 JSON 序列化(变成 null),而事件要跨 iframe 传,所以在源头就归一成 0。
109
109
 
package/dist/index.cjs CHANGED
@@ -4063,8 +4063,15 @@ function createPlayer(options) {
4063
4063
  },
4064
4064
  async load(source) {
4065
4065
  if (destroyed) return;
4066
+ const pauseBeforeReject = () => {
4067
+ setPlayingIntent(false);
4068
+ player.pause();
4069
+ };
4066
4070
  const parsedSource = _video_lab_protocol.MediaSourceSchema.safeParse(source);
4067
- if (!parsedSource.success) throwPlayerError("E_METHOD_NOT_SUPPORTED", `非法换源:${parsedSource.error.issues.map((i) => `${i.path.join(".") || "(根)"} ${i.message}`).join("; ")}`);
4071
+ if (!parsedSource.success) {
4072
+ pauseBeforeReject();
4073
+ throwPlayerError("E_METHOD_NOT_SUPPORTED", `非法换源:${parsedSource.error.issues.map((i) => `${i.path.join(".") || "(根)"} ${i.message}`).join("; ")}`);
4074
+ }
4068
4075
  const nextNormalized = normalizeSource(source);
4069
4076
  const nextSessionId = newSessionId();
4070
4077
  let nextRouted;
@@ -4075,11 +4082,18 @@ function createPlayer(options) {
4075
4082
  event: "sourceroute",
4076
4083
  payload: unsupportedRoutePayload(nextSessionId, nextNormalized, env)
4077
4084
  });
4085
+ pauseBeforeReject();
4078
4086
  throw error;
4079
4087
  }
4080
- if (nextRouted.kernel !== routed.kernel) throwPlayerError("E_METHOD_NOT_SUPPORTED", `换源需要从 ${routed.kernel} 内核切到 ${nextRouted.kernel},运行时无法切换内核。请销毁当前 player 并用新的 source 重建。`);
4088
+ if (nextRouted.kernel !== routed.kernel) {
4089
+ pauseBeforeReject();
4090
+ throwPlayerError("E_METHOD_NOT_SUPPORTED", `换源需要从 ${routed.kernel} 内核切到 ${nextRouted.kernel},运行时无法切换内核。请销毁当前 player 并用新的 source 重建。`);
4091
+ }
4081
4092
  const constructionChanges = sourceConstructionChanges(normalized, nextNormalized);
4082
- if (constructionChanges.length > 0) throwPlayerError("E_METHOD_NOT_SUPPORTED", `换源不能改变构造期 source 配置(${constructionChanges.join("、")})。播放器仍使用创建时的直播、HLS 与字幕插件配置。请销毁当前 player 并用新的 source 重建。`);
4093
+ if (constructionChanges.length > 0) {
4094
+ pauseBeforeReject();
4095
+ throwPlayerError("E_METHOD_NOT_SUPPORTED", `换源不能改变构造期 source 配置(${constructionChanges.join("、")})。播放器仍使用创建时的直播、HLS 与字幕插件配置。请销毁当前 player 并用新的 source 重建。`);
4096
+ }
4083
4097
  const revision = ++loadRevision;
4084
4098
  naturalProof?.abort();
4085
4099
  recovery?.setSession(nextSessionId);
package/dist/index.d.cts CHANGED
@@ -162,7 +162,8 @@ interface PlayerCoreHandle {
162
162
  *
163
163
  * 返回的 Promise 在这次换源有结论时 resolve(ADR-136):新源起播、当前会话的源故障已经通过
164
164
  * `error` 事件报出、被更新的 `load()` 取代或播放器销毁。resolve 不代表新源可播放;
165
- * 新源加载失败只经 `error` 事件报告一次,不会让 `load()` reject。只有上面的校验失败才 reject。
165
+ * 新源加载失败只经 `error` 事件报告一次,不会让 `load()` reject。只有上面的校验失败才 reject,
166
+ * 且 reject 前会暂停旧源(ADR-137),避免它在错误层下继续播放。
166
167
  */
167
168
  load(source: MediaSource): Promise<void>;
168
169
  /**
package/dist/index.d.mts CHANGED
@@ -162,7 +162,8 @@ interface PlayerCoreHandle {
162
162
  *
163
163
  * 返回的 Promise 在这次换源有结论时 resolve(ADR-136):新源起播、当前会话的源故障已经通过
164
164
  * `error` 事件报出、被更新的 `load()` 取代或播放器销毁。resolve 不代表新源可播放;
165
- * 新源加载失败只经 `error` 事件报告一次,不会让 `load()` reject。只有上面的校验失败才 reject。
165
+ * 新源加载失败只经 `error` 事件报告一次,不会让 `load()` reject。只有上面的校验失败才 reject,
166
+ * 且 reject 前会暂停旧源(ADR-137),避免它在错误层下继续播放。
166
167
  */
167
168
  load(source: MediaSource): Promise<void>;
168
169
  /**
package/dist/index.mjs CHANGED
@@ -4037,8 +4037,15 @@ function createPlayer(options) {
4037
4037
  },
4038
4038
  async load(source) {
4039
4039
  if (destroyed) return;
4040
+ const pauseBeforeReject = () => {
4041
+ setPlayingIntent(false);
4042
+ player.pause();
4043
+ };
4040
4044
  const parsedSource = MediaSourceSchema.safeParse(source);
4041
- if (!parsedSource.success) throwPlayerError("E_METHOD_NOT_SUPPORTED", `非法换源:${parsedSource.error.issues.map((i) => `${i.path.join(".") || "(根)"} ${i.message}`).join("; ")}`);
4045
+ if (!parsedSource.success) {
4046
+ pauseBeforeReject();
4047
+ throwPlayerError("E_METHOD_NOT_SUPPORTED", `非法换源:${parsedSource.error.issues.map((i) => `${i.path.join(".") || "(根)"} ${i.message}`).join("; ")}`);
4048
+ }
4042
4049
  const nextNormalized = normalizeSource(source);
4043
4050
  const nextSessionId = newSessionId();
4044
4051
  let nextRouted;
@@ -4049,11 +4056,18 @@ function createPlayer(options) {
4049
4056
  event: "sourceroute",
4050
4057
  payload: unsupportedRoutePayload(nextSessionId, nextNormalized, env)
4051
4058
  });
4059
+ pauseBeforeReject();
4052
4060
  throw error;
4053
4061
  }
4054
- if (nextRouted.kernel !== routed.kernel) throwPlayerError("E_METHOD_NOT_SUPPORTED", `换源需要从 ${routed.kernel} 内核切到 ${nextRouted.kernel},运行时无法切换内核。请销毁当前 player 并用新的 source 重建。`);
4062
+ if (nextRouted.kernel !== routed.kernel) {
4063
+ pauseBeforeReject();
4064
+ throwPlayerError("E_METHOD_NOT_SUPPORTED", `换源需要从 ${routed.kernel} 内核切到 ${nextRouted.kernel},运行时无法切换内核。请销毁当前 player 并用新的 source 重建。`);
4065
+ }
4055
4066
  const constructionChanges = sourceConstructionChanges(normalized, nextNormalized);
4056
- if (constructionChanges.length > 0) throwPlayerError("E_METHOD_NOT_SUPPORTED", `换源不能改变构造期 source 配置(${constructionChanges.join("、")})。播放器仍使用创建时的直播、HLS 与字幕插件配置。请销毁当前 player 并用新的 source 重建。`);
4067
+ if (constructionChanges.length > 0) {
4068
+ pauseBeforeReject();
4069
+ throwPlayerError("E_METHOD_NOT_SUPPORTED", `换源不能改变构造期 source 配置(${constructionChanges.join("、")})。播放器仍使用创建时的直播、HLS 与字幕插件配置。请销毁当前 player 并用新的 source 重建。`);
4070
+ }
4057
4071
  const revision = ++loadRevision;
4058
4072
  naturalProof?.abort();
4059
4073
  recovery?.setSession(nextSessionId);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@video-lab/player-core",
3
- "version": "4.1.2",
3
+ "version": "4.1.3",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./dist/index.cjs",
@@ -33,7 +33,7 @@
33
33
  "xgplayer": "3.0.26",
34
34
  "hls.js": "1.6.19",
35
35
  "xgplayer-flv.js": "3.0.26",
36
- "@video-lab/protocol": "4.1.2"
36
+ "@video-lab/protocol": "4.1.3"
37
37
  },
38
38
  "devDependencies": {
39
39
  "jsdom": "^24.0.0",