ckplayer-plus 1.1.9 → 1.1.11

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
@@ -1,176 +1,178 @@
1
- # ckplayer-plus
2
-
3
- 基于 [ckplayer](https://www.ckplayer.com) X3 的工程化封装:支持 **npm / ESM**,并提供 **Vue 2.7+/3** 与 **React** 组件。
4
-
5
- > **免责声明**:本包为社区/工程化封装,**非 ckplayer 官方包**。播放内核来自 ckplayer(MIT)。完整能力与参数请同时参考 [官方手册](https://www.ckplayer.com/manual/)。npm 上的官方包名为 [`ckplayer`](https://www.npmjs.com/package/ckplayer),请勿混淆。
6
-
7
- ## 安装(只需这一步)
8
-
9
- ```bash
10
- npm i ckplayer-plus
11
- ```
12
-
13
- **不必再单独安装** `hls.js` / `flv.js` / `mpegts.js`。
14
- 包内已附带对应脚本;播放时会按视频地址**自动选择插件并按需加载**。
15
-
16
- ## 自动识别规则(默认开启)
17
-
18
- | 地址特征 | 行为 |
19
- |----------|------|
20
- | `.mp4` 等浏览器可直接播的格式 | 原生 `<video>`,不加载流媒体脚本 |
21
- | `.m3u8` | 自动使用 `hls.js`(Safari 若原生支持则仍走原生) |
22
- | `.flv` | 自动使用 `flv.js` |
23
- | `.ts` / `.m2ts` / `.mts` | 自动使用 `mpegts.js` |
24
-
25
- 关闭自动识别:`autoPlug: false`,并自行传 `plug`。
26
-
27
- ## 引入样式(必做)
28
-
29
- ```js
30
- import 'ckplayer-plus/style.css'
31
- ```
32
-
33
- ## 最简用法(mp4 / m3u8 都这样写)
34
-
35
- ```js
36
- import ckplayer from 'ckplayer-plus'
37
- import 'ckplayer-plus/style.css'
38
-
39
- const player = new ckplayer({
40
- container: '#player',
41
- video: url // 可以是 mp4 或 m3u8,无需再写 plug
42
- })
43
- ```
44
-
45
- Vue:
46
-
47
- ```vue
48
- <CkPlayer :video="url" height="400px" />
49
- ```
50
-
51
- React:
52
-
53
- ```jsx
54
- <CkPlayer video={url} height="400px" />
55
- ```
56
-
57
- ## 配置说明(哪些要写、哪些不用写)
58
-
59
- ### 常用且推荐
60
-
61
- | 配置 | 是否必须 | 默认 | 说明 |
62
- |------|----------|------|------|
63
- | `container` | 核心 API 必须;组件不用 | — | 播放器挂载节点。Vue/React 组件内部自动创建,**不要传** |
64
- | `video` | 必须 | — | 视频地址或清晰度数组 |
65
- | `poster` | 可选 | `''` | 封面图 |
66
- | `autoplay` | 可选 | `false` | 自动播放。**课程/断点续播请保持 `false`**:有 `seek` 时组件会强制关闭自动播,只定位进度,需用户点击播放 |
67
- | `volume` | 可选 | `0.8` | 音量 0–1 |
68
- | `live` | 可选 | `false` | 直播相关 |
69
- | `width` / `height` | 组件可选 | `100%` / `400px` | 仅 Vue/React 组件样式 |
70
-
71
- ### 一般不用写(已内置默认行为)
72
-
73
- | 配置 | 默认 | 说明 |
74
- |------|------|------|
75
- | `autoPlug` | `true` | 按地址自动选插件;通常保持默认即可 |
76
- | `plug` | 自动 | 仅在要强制指定或 `autoPlug: false` 时填写:`hls.js` / `flv.js` / `mpegts.js` |
77
- | `preferBuiltinPlug` | `true` | 优先加载本包内置脚本,避免复用页面上其它全局 `Hls` |
78
- | `cdnFallback` | `true` | `getPath` 失败时回退 jsDelivr;内网无外网请设 `false` 并配 `pluginPath` |
79
- | `pluginPath` | 自动 | 插件脚本根路径。默认:`window.ckplayerBasePath` → 本包 `dist/` → jsDelivr CDN |
80
- | `seek` | `0` | 续播秒数。HLS 对齐分片起点缓冲后再定位;**只 seek 不自动 play**,避免 Network 出现 canceled `.ts` |
81
- | `loaded` | — | **只支持函数**;字符串形式已禁用(防 XSS) |
82
-
83
- ### 进阶(按需)
84
-
85
- | 配置 | 说明 |
86
- |------|------|
87
- | `timeScheduleAdjust` | `5` 时只能在已看进度内拖动;续播请同时传数字 `seek` |
88
- | `crossOrigin` | 跨域视频 / 截图等场景 |
89
- | `cookie` | 进度记忆;组件默认使用实例唯一名,避免多实例冲突 |
90
- | `language` | 语言包名,如 `en`、`zh.hk`(需能加载到 `language/*.js`) |
91
- | `loop` / `controls` 等 | 与官方 ckplayer 一致,见[手册](https://www.ckplayer.com/manual/) |
92
- | `window.ckplayerBasePath` | 全局指定插件根目录(以 `/` 结尾),优先于 CDN |
93
- | `window.ckplayerPlusCdn` | 自定义 CDN 根地址(覆盖默认 jsDelivr) |
94
-
95
- ### 插件加载优先级
96
-
97
- 1. `preferBuiltinPlug: false` 且页面已有全局 `Hls` / `flvjs` / `mpegts` → 直接复用
98
- 2. 否则加载本包脚本:`pluginPath` 或可信的 `window.ckplayerBasePath`(仅 dist / npm 包路径会自动设置;Vite/Webpack chunk 目录会忽略)
99
- 3. 传统 `<script src=".../ckplayer.min.js">` 同级目录推导
100
- 4. `cdnFallback !== false` 时回退:`https://cdn.jsdelivr.net/npm/ckplayer-plus@x.y.z/dist/`;若本地路径 404 会再自动重试一次 CDN
101
-
102
- > 内网离线:把 `node_modules/ckplayer-plus/dist/` 里的 `hls.js/` 等目录放到可访问静态路径,并设置 `pluginPath` `window.ckplayerBasePath`,建议同时 `cdnFallback: false`。
103
- > 样式请使用 `import 'ckplayer-plus/style.css'`,保证 `./images/` 图标能被打包工具解析。
104
-
105
- ## Vue 2.7 / Vue 3
106
-
107
- 支持 **Vue 2.7+** **Vue 3**(需从 `vue` 解析 `h`,与 peerDependencies 一致)。
108
-
109
- ```vue
110
- <template>
111
- <CkPlayer :video="url" :seek="16" poster="/poster.png" height="400px" @play="onPlay" />
112
- </template>
113
-
114
- <script>
115
- import { CkPlayer } from 'ckplayer-plus/vue'
116
- import 'ckplayer-plus/style.css'
117
-
118
- export default {
119
- components: { CkPlayer },
120
- data() {
121
- return { url: 'https://example.com/a.m3u8' } // 或 .mp4
122
- },
123
- methods: { onPlay() {} }
124
- }
125
- </script>
126
- ```
127
-
128
- 断点续播:`seek` 用 `:seek` 或 `options.seek` 在创建时传入;**不要**在 `@ready` 里再 `player.seek(16)`,否则会重复加载 HLS、取消 `.ts` 分片导致卡住。有 `seek` 时不会自动播放,定位完成后点中央播放按钮即可。切集/切换清晰度同样不强制自动播。
129
-
130
- SSR(Nuxt 等)请用 `<ClientOnly>`,仅在浏览器初始化。
131
-
132
- ## React
133
-
134
- ```jsx
135
- import { CkPlayer } from 'ckplayer-plus/react'
136
- import 'ckplayer-plus/style.css'
137
-
138
- <CkPlayer video={url} height="400px" onPlay={() => {}} />
139
- ```
140
-
141
- Next.js 使用 Client Component 或 `dynamic(..., { ssr: false })`。
142
-
143
- ## 脚本标签
144
-
145
- ```html
146
- <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ckplayer-plus/dist/ckplayer.css" />
147
- <script src="https://cdn.jsdelivr.net/npm/ckplayer-plus/dist/ckplayer.min.js"></script>
148
- <div id="player" style="width:800px;height:450px;"></div>
149
- <script>
150
- new ckplayer({
151
- container: '#player',
152
- video: 'https://example.com/video.mp4'
153
- })
154
- </script>
155
- ```
156
-
157
- ## 重要说明
158
-
159
- | 主题 | 说明 |
160
- |------|------|
161
- | SSR | 依赖 `document`,必须客户端初始化 |
162
- | 移动端自动播 | 常需 `volume: 0` 或用户手势 |
163
- | dash.js | 未实现 |
164
- | 体积 | 主包含流媒体 min 脚本以便「只装一个包」;运行时仍按需加载 |
165
-
166
- ## 开发与发布
167
-
168
- ```bash
169
- npm install
170
- npm run build
171
- npm publish --access public
172
- ```
173
-
174
- ## License
175
-
176
- MIT。内置的 hls.js / flv.js / mpegts.js 遵循各自许可证(多为 Apache-2.0)。
1
+ # ckplayer-plus
2
+
3
+ 基于 [ckplayer](https://www.ckplayer.com) X3 的工程化封装:支持 **npm / ESM**,并提供 **Vue 2.7+/3** 与 **React** 组件。
4
+
5
+ > **免责声明**:本包为社区/工程化封装,**非 ckplayer 官方包**。播放内核来自 ckplayer(MIT)。完整能力与参数请同时参考 [官方手册](https://www.ckplayer.com/manual/)。npm 上的官方包名为 [`ckplayer`](https://www.npmjs.com/package/ckplayer),请勿混淆。
6
+
7
+ ## 安装(只需这一步)
8
+
9
+ ```bash
10
+ npm i ckplayer-plus
11
+ ```
12
+
13
+ **不必再单独安装** `hls.js` / `flv.js` / `mpegts.js`。
14
+ 包内已附带对应脚本;播放时会按视频地址**自动选择插件并按需加载**。
15
+
16
+ ## 自动识别规则(默认开启)
17
+
18
+ | 地址特征 | 行为 |
19
+ |----------|------|
20
+ | `.mp4` 等浏览器可直接播的格式 | 原生 `<video>`,不加载流媒体脚本 |
21
+ | `.m3u8` | 自动使用 `hls.js`(Safari 若原生支持则仍走原生) |
22
+ | `.flv` | 自动使用 `flv.js` |
23
+ | `.ts` / `.m2ts` / `.mts` | 自动使用 `mpegts.js` |
24
+
25
+ 关闭自动识别:`autoPlug: false`,并自行传 `plug`。
26
+
27
+ ## 引入样式(必做)
28
+
29
+ ```js
30
+ import 'ckplayer-plus/style.css'
31
+ ```
32
+
33
+ ## 最简用法(mp4 / m3u8 都这样写)
34
+
35
+ ```js
36
+ import ckplayer from 'ckplayer-plus'
37
+ import 'ckplayer-plus/style.css'
38
+
39
+ const player = new ckplayer({
40
+ container: '#player',
41
+ video: url // 可以是 mp4 或 m3u8,无需再写 plug
42
+ })
43
+ ```
44
+
45
+ Vue:
46
+
47
+ ```vue
48
+ <CkPlayer :video="url" height="400px" />
49
+ ```
50
+
51
+ React:
52
+
53
+ ```jsx
54
+ <CkPlayer video={url} height="400px" />
55
+ ```
56
+
57
+ ## 配置说明(哪些要写、哪些不用写)
58
+
59
+ ### 常用且推荐
60
+
61
+ | 配置 | 是否必须 | 默认 | 说明 |
62
+ |------|----------|------|------|
63
+ | `container` | 核心 API 必须;组件不用 | — | 播放器挂载节点。Vue/React 组件内部自动创建,**不要传** |
64
+ | `video` | 必须 | — | 视频地址或清晰度数组 |
65
+ | `poster` | 可选 | `''` | 封面图 |
66
+ | `autoplay` | 可选 | `false` | 自动播放。**课程/断点续播请保持 `false`**:有 `seek` 时组件会强制关闭自动播,只定位进度,需用户点击播放 |
67
+ | `volume` | 可选 | `0.8` | 音量 0–1 |
68
+ | `live` | 可选 | `false` | 直播相关 |
69
+ | `width` / `height` | 组件可选 | `100%` / `400px` | 仅 Vue/React 组件样式 |
70
+
71
+ ### 一般不用写(已内置默认行为)
72
+
73
+ | 配置 | 默认 | 说明 |
74
+ |------|------|------|
75
+ | `autoPlug` | `true` | 按地址自动选插件;通常保持默认即可 |
76
+ | `plug` | 自动 | 仅在要强制指定或 `autoPlug: false` 时填写:`hls.js` / `flv.js` / `mpegts.js` |
77
+ | `preferBuiltinPlug` | `true` | 优先加载本包内置脚本,避免复用页面上其它全局 `Hls` |
78
+ | `cdnFallback` | `true` | `getPath` 失败时回退 jsDelivr;内网无外网请设 `false` 并配 `pluginPath` |
79
+ | `pluginPath` | 自动 | 插件脚本根路径。默认:`window.ckplayerBasePath` → 可信 script/`dist` → jsDelivr CDN。**Vue/React + Vite 一般不用配**,勿设成 `/src/` |
80
+ | `seek` | `0` | 续播秒数。HLS 对齐分片起点缓冲后再定位;**只 seek 不自动 play**,避免 Network 出现 canceled `.ts` |
81
+ | `loaded` | — | **只支持函数**;字符串形式已禁用(防 XSS) |
82
+
83
+ ### 进阶(按需)
84
+
85
+ | 配置 | 说明 |
86
+ |------|------|
87
+ | `timeScheduleAdjust` | `5` 时只能在已看进度内拖动;续播请同时传数字 `seek` |
88
+ | `crossOrigin` | 跨域视频 / 截图等场景 |
89
+ | `cookie` | 进度记忆;组件默认使用实例唯一名,避免多实例冲突 |
90
+ | `language` | 语言包名,如 `en`、`zh.hk`(需能加载到 `language/*.js`) |
91
+ | `loop` / `controls` 等 | 与官方 ckplayer 一致,见[手册](https://www.ckplayer.com/manual/) |
92
+ | `window.ckplayerBasePath` | 全局指定插件根目录(以 `/` 结尾),优先于 CDN |
93
+ | `window.ckplayerPlusCdn` | 自定义 CDN 根地址(覆盖默认 jsDelivr) |
94
+
95
+ ### 插件加载优先级
96
+
97
+ 1. `preferBuiltinPlug: false` 且页面已有全局 `Hls` / `flvjs` / `mpegts` → 直接复用
98
+ 2. 否则加载本包脚本:`pluginPath` 或可信的 `window.ckplayerBasePath`(仅 dist / npm 包路径会自动设置;`/src`、`assets`、`.vite/deps`、chunk 目录会忽略)
99
+ 3. 传统 `<script src=".../ckplayer.min.js">` 同级目录推导(**不会**再用页面最后一个无关 script,避免 Vite 指到 `/src/main.js`)
100
+ 4. `cdnFallback !== false` 时回退:`https://cdn.jsdelivr.net/npm/ckplayer-plus@x.y.z/dist/`;若本地路径 404 会再自动重试一次 CDN
101
+
102
+ > **Vue 2.7 / Vue 3 / React(Vite/Webpack)**:直接 `import { CkPlayer } from 'ckplayer-plus/vue'`(或 `/react`)即可,hls/flv 会走 CDN 或你配置的 `pluginPath`。不要把 `pluginPath` 设成业务的 `/src/`。
103
+ > 内网离线:把 `node_modules/ckplayer-plus/dist/` 里的 `hls.js/` 等目录拷到可访问静态路径(也可用 `public/ckplayer-plus/`),并设置 `pluginPath` 或 `window.ckplayerBasePath`,建议同时 `cdnFallback: false`。
104
+ > 本地调试本仓库 demo:先 `npm run build`,再用静态服务打开 `examples/demo.html`(`dist/` 被 gitignore,不重建会跑到旧逻辑)。
105
+ > 样式请使用 `import 'ckplayer-plus/style.css'`,保证 `./images/` 图标能被打包工具解析。
106
+
107
+ ## Vue 2.7 / Vue 3
108
+
109
+ 支持 **Vue 2.7+** 与 **Vue 3**(需从 `vue` 解析 `h`,与 peerDependencies 一致)。
110
+
111
+ ```vue
112
+ <template>
113
+ <CkPlayer :video="url" :seek="16" poster="/poster.png" height="400px" @play="onPlay" />
114
+ </template>
115
+
116
+ <script>
117
+ import { CkPlayer } from 'ckplayer-plus/vue'
118
+ import 'ckplayer-plus/style.css'
119
+
120
+ export default {
121
+ components: { CkPlayer },
122
+ data() {
123
+ return { url: 'https://example.com/a.m3u8' } // 或 .mp4
124
+ },
125
+ methods: { onPlay() {} }
126
+ }
127
+ </script>
128
+ ```
129
+
130
+ 断点续播:`seek` `:seek` 或 `options.seek` 在创建时传入;**不要**在 `@ready` 里再 `player.seek(16)`,否则会重复加载 HLS、取消 `.ts` 分片导致卡住。有 `seek` 时不会自动播放,定位完成后点中央播放按钮即可。切集/切换清晰度同样不强制自动播。
131
+
132
+ SSR(Nuxt 等)请用 `<ClientOnly>`,仅在浏览器初始化。
133
+
134
+ ## React
135
+
136
+ ```jsx
137
+ import { CkPlayer } from 'ckplayer-plus/react'
138
+ import 'ckplayer-plus/style.css'
139
+
140
+ <CkPlayer video={url} height="400px" onPlay={() => {}} />
141
+ ```
142
+
143
+ Next.js 使用 Client Component 或 `dynamic(..., { ssr: false })`。
144
+
145
+ ## 脚本标签
146
+
147
+ ```html
148
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ckplayer-plus/dist/ckplayer.css" />
149
+ <script src="https://cdn.jsdelivr.net/npm/ckplayer-plus/dist/ckplayer.min.js"></script>
150
+ <div id="player" style="width:800px;height:450px;"></div>
151
+ <script>
152
+ new ckplayer({
153
+ container: '#player',
154
+ video: 'https://example.com/video.mp4'
155
+ })
156
+ </script>
157
+ ```
158
+
159
+ ## 重要说明
160
+
161
+ | 主题 | 说明 |
162
+ |------|------|
163
+ | SSR | 依赖 `document`,必须客户端初始化 |
164
+ | 移动端自动播 | 常需 `volume: 0` 或用户手势 |
165
+ | dash.js | 未实现 |
166
+ | 体积 | 主包含流媒体 min 脚本以便「只装一个包」;运行时仍按需加载 |
167
+
168
+ ## 开发与发布
169
+
170
+ ```bash
171
+ npm install
172
+ npm run build
173
+ npm publish --access public
174
+ ```
175
+
176
+ ## License
177
+
178
+ MIT。内置的 hls.js / flv.js / mpegts.js 遵循各自许可证(多为 Apache-2.0)。
package/dist/ckplayer.js CHANGED
@@ -141,7 +141,7 @@
141
141
  cdnFallback:true// getPath 失败时是否回退到 jsDelivr(内网可设 false,并配置 pluginPath)
142
142
  };
143
143
  // 打包时替换为真实版本;用于 bundler 下 getPath 失效时的 CDN 回退
144
- var ckplayerPlusDefaultCdn='https://cdn.jsdelivr.net/npm/ckplayer-plus@1.1.9/dist/';
144
+ var ckplayerPlusDefaultCdn='https://cdn.jsdelivr.net/npm/ckplayer-plus@1.1.11/dist/';
145
145
  function ckplayerEmbed(videoObj){
146
146
  /*
147
147
  * rightMenu
@@ -411,16 +411,6 @@
411
411
  return embed(obj);
412
412
  }
413
413
  },
414
- /*
415
- * isUnreliablePluginBase
416
- * 功能:识别 bundler chunk 目录(不含 hls.js 等插件),避免短路 CDN 回退
417
- */
418
- isUnreliablePluginBase=function(base){
419
- if(!base || valType(base)!='string'){
420
- return true;
421
- }
422
- return /\/(?:assets|\.vite\/deps|_next\/static|chunks?)\/?$/i.test(base);
423
- },
424
414
  /*
425
415
  * resolveAssetPath
426
416
  * 功能:解析插件/语言包路径
@@ -443,13 +433,14 @@
443
433
  }
444
434
  return base+folder+'/'+file;
445
435
  }
446
- var fromScript=getPath(folder)+file;
447
- if(fromScript && fromScript.indexOf(folder+'/')>-1 && fromScript.indexOf('undefined')===-1 && !isUnreliablePluginBase(getPath())){
436
+ var scriptBase=getPath();
437
+ var fromScript=scriptBase ? (getPath(folder)+file) : '';
438
+ if(fromScript && fromScript.indexOf(folder+'/')>-1 && fromScript.indexOf('undefined')===-1 && !isUnreliablePluginBase(scriptBase)){
448
439
  return fromScript;
449
440
  }
450
441
  var allowCdn=!vars || vars['cdnFallback']!==false;
451
442
  var cdn=(typeof window!=='undefined' && window.ckplayerPlusCdn) ? window.ckplayerPlusCdn : ckplayerPlusDefaultCdn;
452
- if(!allowCdn || !cdn || cdn.indexOf('1.1.9')>-1){
443
+ if(!allowCdn || !cdn || cdn.indexOf('1.1.11')>-1){
453
444
  // 避免占位版本或显式关闭 CDN 时请求坏地址;交给相对路径或业务 pluginPath
454
445
  return folder+'/'+file;
455
446
  }
@@ -804,9 +795,9 @@
804
795
  }
805
796
  // 目标已在缓冲但缺少前片连续区 → 继续按对齐点预热,勿 noop
806
797
  }
807
- // 首次续播直接加载包含目标时间的分片。暂停状态下 hls.js 通常只预载一片,
808
- // 若从前一片开始会停在前片末尾,目标时间永远无法进入 buffered。
809
- var loadAt=hlsFragStartTime(target);
798
+ // 续播加载起点:前一片(确保解码管线有关键帧),hls.js 会自动向前加载覆盖目标。
799
+ // finishResumeSeek 会调 startLoad(-1) 恢复正常加载,此处无需担心只加载一片。
800
+ var loadAt=hlsPriorLoadTime(target);
810
801
  if(!force){
811
802
  // 短时间内已对同一对齐点发起加载 → 跳过(防止 onReady 再 seek 取消分片)
812
803
  if(hlsLoadAt>=0 && Math.abs(hlsLoadAt-loadAt)<1.5 && (Date.now()-hlsLoadTs)<4000){
@@ -1094,10 +1085,12 @@
1094
1085
  if(!resumeAt){
1095
1086
  resumeAt=parseResumeSeekFromVars();
1096
1087
  }
1097
- // 断点续播:关闭 autoStartLoad,清单解析后从目标前一片 startLoad,缓冲就绪再定位。
1098
- // 与拖动路径分离(拖动只改 currentTime,不手动 startLoad)。
1088
+ // 断点续播:保持 hls.js 默认加载(autoStartLoad=true / 自身 startLoad(-1))。
1089
+ // 不可用 autoStartLoad=false + startLoad(target) 或 config.startPosition 从中段起播:
1090
+ // 该路径会让 stream-controller 在首片后卡死在 PARSED,分片能下载却不再 append 进
1091
+ // SourceBuffer(表现为黑屏、拖动转圈)。定位统一走 currentTime,由 hls.js 的
1092
+ // seeking 路径拉片,代价仅为起播时多拉 1~2 片片头。
1099
1093
  if(resumeAt && resumeAt>0 && (isUndefined(vars['live']) || !vars['live'])){
1100
- hlsConf.autoStartLoad=false;
1101
1094
  maxSeeTime=Math.max(maxSeeTime,resumeAt);
1102
1095
  if(firstSeekTime<0){
1103
1096
  firstSeekTime=resumeAt;
@@ -1114,17 +1107,32 @@
1114
1107
  hls.on(Hls.Events.MANIFEST_PARSED, function(){
1115
1108
  if(seekTime>0 && hlsResumeSettling){
1116
1109
  hlsStartPositionUsed=true;
1117
- hlsSeekTo(seekTime,true);
1118
1110
  if(C['buffer']){
1119
1111
  C['buffer'].show();
1120
1112
  }
1121
- // 超时兜底:若 10s 后续播仍未完成,强制定位到片起点避免永久转圈
1113
+ // 尽早把 currentTime 推到目标:MediaSource 的 duration 一就绪即可 seek,
1114
+ // 越早越少拉片头分片。之后由 hls.js 的 seeking 路径接管拉片。
1115
+ var doResumeSeek=function(){
1116
+ if(!hlsResumeSettling || !seekTime){return;}
1117
+ var t=seekTime;
1118
+ if(video && video.seekable && video.seekable.length>0 && video.seekable.end(0)>=t){
1119
+ finishResumeSeek(t);
1120
+ return;
1121
+ }
1122
+ seekRetryCount++;
1123
+ if(seekRetryCount<=100){
1124
+ if(seekRetryTimer){clearTimeout(seekRetryTimer);}
1125
+ seekRetryTimer=setTimeout(doResumeSeek,50);
1126
+ }
1127
+ else{
1128
+ finishResumeSeek(t);
1129
+ }
1130
+ };
1131
+ doResumeSeek();
1132
+ // 超时兜底
1122
1133
  setTimeout(function(){
1123
- if(hlsResumeSettling){
1124
- var t=seekTime>0?seekTime:hlsResumeTarget;
1125
- if(t>0){
1126
- finishResumeSeek(t);
1127
- }
1134
+ if(hlsResumeSettling && seekTime>0){
1135
+ finishResumeSeek(seekTime);
1128
1136
  }
1129
1137
  },10000);
1130
1138
  return;
@@ -1189,9 +1197,12 @@
1189
1197
  }catch(errRecover){}
1190
1198
  }
1191
1199
  }
1192
- CT.error={code:code,message:message};
1193
- eventTarget('error',CT.error);//注册监听error
1200
+ // 只有致命错误才向业务抛 error 事件并显示错误覆盖。
1201
+ // bufferStalledError / fragParsingError 等非致命错误由 hls.js 内部恢复,
1202
+ // 不应导致 UI 报 "加载失败" 遮挡正常播放。
1194
1203
  if(fatal){
1204
+ CT.error={code:code,message:message};
1205
+ eventTarget('error',CT.error);
1195
1206
  showError();
1196
1207
  }
1197
1208
  });
@@ -2088,17 +2099,18 @@
2088
2099
  },
2089
2100
  /*
2090
2101
  * tryCompleteResumeSeek
2091
- * 功能:续播预热完成后,缓冲已覆盖前片→目标时再定位
2102
+ * 功能:续播预热完成后,目标时间已在 buffered 则定位;否则定位到片起点(保证有画面)
2092
2103
  */
2093
2104
  tryCompleteResumeSeek=function(t){
2094
2105
  if(!hlsResumeSettling || isNaN(t) || t<=0 || !video){
2095
2106
  return false;
2096
2107
  }
2097
- if(hlsCanSafelySeekTo(t)){
2098
- finishResumeSeek(t);
2099
- return true;
2108
+ // 严格检查:目标时间必须在 buffered 区间内部(不含边缘)才算就绪
2109
+ if(!timeInBuffered(t)){
2110
+ return false;
2100
2111
  }
2101
- return false;
2112
+ finishResumeSeek(t);
2113
+ return true;
2102
2114
  },
2103
2115
  /*
2104
2116
  * finishResumeSeek
@@ -2107,8 +2119,10 @@
2107
2119
  finishResumeSeek=function(t){
2108
2120
  hlsResumeWarmup=false;
2109
2121
  hlsResumeSettling=false;
2110
- // 续播场景取消挂起的自动播放,统一改为点击播放
2111
2122
  autoplayPending=false;
2123
+ // 注意:此处不可再调 hls.startLoad()。MANIFEST_PARSED 里的 startLoad(target)
2124
+ // 已进入正常加载循环,二次 startLoad 会在首片 append 途中重置 BufferController,
2125
+ // 使 SourceBuffer 操作队列永久阻塞(stream-controller 卡在 PARSED,分片下载但不入 MSE)。
2112
2126
  applySeekToMedia(t);
2113
2127
  setTimeout(function(){
2114
2128
  if(!video){return;}
@@ -2176,6 +2190,11 @@
2176
2190
  if(!seekTime || !video || seekApplyLock){
2177
2191
  return;
2178
2192
  }
2193
+ // 续播期间由 FRAG_BUFFERED + tryCompleteResumeSeek 处理定位,不在此处发起
2194
+ // 避免 canPlay/loadedMetaData 调用 applyPendingSeek → hlsSeekTo → startLoad 打断正在进行的加载
2195
+ if(hlsResumeSettling && hls){
2196
+ return;
2197
+ }
2179
2198
  if(!isUndefined(vars['live']) && ((valType(vars['live'])=='boolean' && vars['live']) || valType(vars['live'])=='number')){
2180
2199
  return;
2181
2200
  }
@@ -2555,20 +2574,11 @@
2555
2574
  // 这不是续播完成,不能清除 settling;等待目标点真正进入 buffered。
2556
2575
  var resumePending=false;
2557
2576
  if(hlsResumeSettling && hlsResumeTarget>0){
2558
- if(!timeInBuffered(hlsResumeTarget)){
2559
- resumePending=true;
2560
- }
2561
- else if(Math.abs(this.currentTime-hlsResumeTarget)>0.5){
2562
- // FRAG_BUFFERED 可能先把目标设为 120,随后 MSE 又自动回拨到首个 buffered 起点。
2563
- // 等本轮 seeked 结束后再次应用目标,下一次 seeked 才是真正完成。
2564
- resumePending=true;
2565
- var resumeTarget=hlsResumeTarget;
2566
- setTimeout(function(){
2567
- if(hlsResumeSettling && timeInBuffered(resumeTarget)){
2568
- finishResumeSeek(resumeTarget);
2569
- }
2570
- },0);
2571
- }
2577
+ // 续播期间的 seeked 分两种情况:
2578
+ // 1) MSE 首次追加非零时间轴分片时自动跳到片起点(中间 seeked,不是最终定位)
2579
+ // 2) finishResumeSeek 后的最终 seeked(此时 hlsResumeSettling 已被清除,不会进入此分支)
2580
+ // 只要续播标志还在,就保持 pending,让 tryCompleteResumeSeek/超时兜底来完成
2581
+ resumePending=true;
2572
2582
  }
2573
2583
  if(!resumePending){
2574
2584
  hlsResumeSettling=false;
@@ -7492,11 +7502,11 @@
7492
7502
  removeListener(script, 'load', w3c);
7493
7503
  removeListener(script, 'error', w3cError);
7494
7504
  removeScript();
7495
- // bundler 下错误 base 路径 404 时,回退 jsDelivr 再试一次
7505
+ // bundler 下错误 base 路径 404 时,回退 jsDelivr 再试一次(兼容相对路径 hls.js/xxx)
7496
7506
  if(!isRetry && (!vars || vars['cdnFallback']!==false)){
7497
7507
  var cdn=(typeof window!=='undefined' && window.ckplayerPlusCdn) ? window.ckplayerPlusCdn : ckplayerPlusDefaultCdn;
7498
- var m=String(file).match(/\/(hls\.js|flv\.js|mpegts\.js|language)\/([^/?#]+)(?:[?#].*)?$/i);
7499
- if(cdn && cdn.indexOf('1.1.9')===-1 && m){
7508
+ var m=String(file).match(/(?:^|\/)(hls\.js|flv\.js|mpegts\.js|language)\/([^/?#]+)(?:[?#].*)?$/i);
7509
+ if(cdn && cdn.indexOf('1.1.11')===-1 && m){
7500
7510
  if(cdn.slice(-1)!=='/'){
7501
7511
  cdn+='/';
7502
7512
  }
@@ -7791,18 +7801,38 @@
7791
7801
  }
7792
7802
 
7793
7803
  }
7804
+ /*
7805
+ * isUnreliablePluginBase
7806
+ * 功能:识别不会托管 hls.js/flv.js 的目录,避免 Vite/Webpack 下请求 /src/hls.js 等 404
7807
+ */
7808
+ function isUnreliablePluginBase(base) {
7809
+ if (!base || typeof base !== 'string') {
7810
+ return true;
7811
+ }
7812
+ var b = base.replace(/\\/g, '/');
7813
+ // bundler 产物 / 依赖预构建目录
7814
+ if (/\/(?:assets|\.vite\/deps|_next\/static|chunks?|static\/js|webpack|@fs|@id|@vite)\/?$/i.test(b)) {
7815
+ return true;
7816
+ }
7817
+ // 应用源码根(Vite 常见:…/src/main.js → 误推 …/src/hls.js/…)
7818
+ if (/\/(?:src|app|pages|views|components)\/?$/i.test(b)) {
7819
+ return true;
7820
+ }
7821
+ // 仅站点根路径,不含插件文件
7822
+ if (/^https?:\/\/[^/?#]+\/?$/i.test(b)) {
7823
+ return true;
7824
+ }
7825
+ return false;
7826
+ }
7794
7827
  /*
7795
7828
  * getPath
7796
7829
  * 功能:获取该js文件所在路径
7830
+ * 仅信任 ckplayer 脚本或可信的 ckplayerBasePath;勿回退到页面最后一个 script(Vite 常为 /src/main.js)
7797
7831
  */
7798
7832
  function getPath(siz) {
7799
7833
  if (typeof window !== 'undefined' && window.ckplayerBasePath) {
7800
7834
  var base = window.ckplayerBasePath;
7801
- // bundler chunk 目录不含插件文件,忽略并继续 script/CDN 推导
7802
- if (/\/(?:assets|\.vite\/deps|_next\/static|chunks?)\/?$/i.test(base)) {
7803
- base = '';
7804
- }
7805
- if (base) {
7835
+ if (!isUnreliablePluginBase(base)) {
7806
7836
  if (base.slice(-1) !== '/') {
7807
7837
  base += '/';
7808
7838
  }
@@ -7812,13 +7842,17 @@
7812
7842
  return base;
7813
7843
  }
7814
7844
  }
7815
- var scriptList = document.scripts || [],
7816
- thisPath = scriptList.length ? scriptList[scriptList.length - 1].src : '';
7845
+ var scriptList = document.scripts || [];
7846
+ var thisPath = '';
7817
7847
  for (var i = 0; i < scriptList.length; i++) {
7818
7848
  var scriptName = scriptList[i].getAttribute('name') || scriptList[i].getAttribute('data-name');
7819
- var src = scriptList[i].src.slice(scriptList[i].src.lastIndexOf('/') + 1, scriptList[i].src.lastIndexOf('.'));
7820
- if ((scriptName && (scriptName == 'ckplayer' || scriptName == 'ckplayer.min' || scriptName == 'ckplayer-plus')) || (scriptList[i].src && (src == 'ckplayer' || src == 'ckplayer.min' || src.indexOf('ckplayer') === 0))) {
7821
- thisPath = scriptList[i].src;
7849
+ var srcFull = scriptList[i].src || '';
7850
+ if (!srcFull) {
7851
+ continue;
7852
+ }
7853
+ var src = srcFull.slice(srcFull.lastIndexOf('/') + 1, srcFull.lastIndexOf('.'));
7854
+ if ((scriptName && (scriptName == 'ckplayer' || scriptName == 'ckplayer.min' || scriptName == 'ckplayer-plus')) || (src == 'ckplayer' || src == 'ckplayer.min' || src.indexOf('ckplayer') === 0)) {
7855
+ thisPath = srcFull;
7822
7856
  break;
7823
7857
  }
7824
7858
  }
@@ -7828,6 +7862,9 @@
7828
7862
  } else if (thisPath && thisPath.lastIndexOf('/') > -1) {
7829
7863
  path = thisPath.substring(0, thisPath.lastIndexOf('/') + 1);
7830
7864
  }
7865
+ if (!path || isUnreliablePluginBase(path)) {
7866
+ return '';
7867
+ }
7831
7868
  if (!isUndefined(siz)) {
7832
7869
  path += siz + '/';
7833
7870
  }