ckplayer-plus 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2020 niandeng
4
+ Copyright (c) 2026 ckplayer-plus contributors
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,173 @@
1
+ # ckplayer-plus
2
+
3
+ 基于 [ckplayer](https://www.ckplayer.com) X3 的工程化封装:支持 **npm / ESM**,并提供 **Vue 2/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` | 自动播放(移动端常需静音) |
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
+ | `pluginPath` | 自动 | 插件脚本根路径。默认:`window.ckplayerBasePath` → 本包 `dist/` → jsDelivr CDN |
78
+ | `loaded` | — | **只支持函数**;字符串形式已禁用(防 XSS) |
79
+
80
+ ### 进阶(按需)
81
+
82
+ | 配置 | 说明 |
83
+ |------|------|
84
+ | `crossOrigin` | 跨域视频 / 截图等场景 |
85
+ | `cookie` | 进度记忆;组件默认使用实例唯一名,避免多实例冲突 |
86
+ | `language` | 语言包名,如 `en`、`zh.hk`(需能加载到 `language/*.js`) |
87
+ | `seek` / `loop` / `controls` 等 | 与官方 ckplayer 一致,见[手册](https://www.ckplayer.com/manual/) |
88
+ | `window.ckplayerBasePath` | 全局指定插件根目录(以 `/` 结尾),优先于 CDN |
89
+ | `window.ckplayerPlusCdn` | 自定义 CDN 根地址(覆盖默认 jsDelivr) |
90
+
91
+ ### 插件加载优先级
92
+
93
+ 1. 页面上已有全局 `Hls` / `flvjs` / `mpegts` → 直接用,不再请求脚本
94
+ 2. `pluginPath` 或 `window.ckplayerBasePath`
95
+ 3. 传统 `<script src=".../ckplayer.min.js">` 同级目录推导
96
+ 4. 回退:`https://cdn.jsdelivr.net/npm/ckplayer-plus@x.y.z/dist/`(发布到 npm 后可用)
97
+
98
+ > 内网离线:把 `node_modules/ckplayer-plus/dist/` 里的 `hls.js/` 等目录放到可访问静态路径,并设置 `pluginPath` 或 `window.ckplayerBasePath`。
99
+
100
+ ## Vue 2 / Vue 3
101
+
102
+ ```vue
103
+ <template>
104
+ <CkPlayer :video="url" poster="/poster.png" height="400px" @play="onPlay" />
105
+ </template>
106
+
107
+ <script>
108
+ import { CkPlayer } from 'ckplayer-plus/vue'
109
+ import 'ckplayer-plus/style.css'
110
+
111
+ export default {
112
+ components: { CkPlayer },
113
+ data() {
114
+ return { url: 'https://example.com/a.m3u8' } // 或 .mp4
115
+ },
116
+ methods: { onPlay() {} }
117
+ }
118
+ </script>
119
+ ```
120
+
121
+ SSR(Nuxt 等)请用 `<ClientOnly>`,仅在浏览器初始化。
122
+
123
+ ## React
124
+
125
+ ```jsx
126
+ import { CkPlayer } from 'ckplayer-plus/react'
127
+ import 'ckplayer-plus/style.css'
128
+
129
+ <CkPlayer video={url} height="400px" onPlay={() => {}} />
130
+ ```
131
+
132
+ Next.js 使用 Client Component 或 `dynamic(..., { ssr: false })`。
133
+
134
+ ## 脚本标签
135
+
136
+ ```html
137
+ <link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/ckplayer-plus/dist/ckplayer.css" />
138
+ <script src="https://cdn.jsdelivr.net/npm/ckplayer-plus/dist/ckplayer.min.js"></script>
139
+ <div id="player" style="width:800px;height:450px;"></div>
140
+ <script>
141
+ new ckplayer({
142
+ container: '#player',
143
+ video: 'https://example.com/video.mp4'
144
+ })
145
+ </script>
146
+ ```
147
+
148
+ ## 重要说明
149
+
150
+ | 主题 | 说明 |
151
+ |------|------|
152
+ | SSR | 依赖 `document`,必须客户端初始化 |
153
+ | 移动端自动播 | 常需 `volume: 0` 或用户手势 |
154
+ | dash.js | 未实现 |
155
+ | 体积 | 主包含流媒体 min 脚本以便「只装一个包」;运行时仍按需加载 |
156
+
157
+ ## 开发与发布
158
+
159
+ ```bash
160
+ npm install
161
+ npm run build
162
+ npm publish --access public
163
+ ```
164
+
165
+ ## License
166
+
167
+ MIT。内置的 hls.js / flv.js / mpegts.js 遵循各自许可证(多为 Apache-2.0)。
168
+
169
+ ## 相关链接
170
+
171
+ - 官网:https://www.ckplayer.com
172
+ - 手册:https://www.ckplayer.com/manual/
173
+ - 官方 npm:https://www.npmjs.com/package/ckplayer