@volcengine/veplayer 1.15.1 → 1.15.2-rc.1

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.

Potentially problematic release.


This version of @volcengine/veplayer might be problematic. Click here for more details.

Files changed (245) hide show
  1. package/.changeset/config.json +11 -0
  2. package/.changeset/curvy-yaks-smoke.md +5 -0
  3. package/.changeset/neat-eyes-search.md +5 -0
  4. package/.codebase/pipelines/create-api-doc.yaml +16 -0
  5. package/.eslintignore +5 -0
  6. package/.eslintrc.json +53 -0
  7. package/.stylelintrc.js +51 -0
  8. package/CHANGELOG.md +5665 -0
  9. package/DEV_README.md +39 -0
  10. package/LICENSE +20 -0
  11. package/README_EN.md +46 -0
  12. package/build.sh +44 -0
  13. package/docg.config.js +65 -0
  14. package/env/byteplus.js +30 -0
  15. package/env/volcengine.js +50 -0
  16. package/fixtures/favicon.ico +0 -0
  17. package/fixtures/index.base.js +59 -0
  18. package/fixtures/index.html +41 -0
  19. package/fixtures/index.js +185 -0
  20. package/libd.config.js +147 -0
  21. package/localhost+2-key.pem +28 -0
  22. package/localhost+2.pem +26 -0
  23. package/lux.config.mjs +37 -0
  24. package/package.json +123 -4
  25. package/sdkhub.config.json +10 -0
  26. package/src/@types/global.d.ts +35 -0
  27. package/src/assets/common/error.svg +3 -0
  28. package/src/assets/common/errorImg.png +0 -0
  29. package/src/assets/common/errorImg.svg +12 -0
  30. package/src/assets/icons/mobile/definition.svg +3 -0
  31. package/src/assets/icons/mobile/line.svg +3 -0
  32. package/src/assets/icons/mobile/mobileDanmu.svg +1 -0
  33. package/src/assets/icons/mobile/mobileDanmuAcitive.svg +1 -0
  34. package/src/assets/icons/mobile/mobileDanmuSetting.svg +1 -0
  35. package/src/assets/icons/mobile/mobileExitFullscreen.svg +1 -0
  36. package/src/assets/icons/mobile/mobileFullscreen.svg +1 -0
  37. package/src/assets/icons/mobile/mobilePause.svg +4 -0
  38. package/src/assets/icons/mobile/mobilePlay.svg +4 -0
  39. package/src/assets/icons/mobile/mobilePlaynext.svg +1 -0
  40. package/src/assets/icons/mobile/mobileRefresh.svg +1 -0
  41. package/src/assets/icons/mobile/more.svg +3 -0
  42. package/src/assets/icons/mobile/muted.svg +22 -0
  43. package/src/assets/icons/mobile/playbackrate.svg +3 -0
  44. package/src/assets/icons/pc/danmu.svg +1 -0
  45. package/src/assets/icons/pc/danmuActive.svg +1 -0
  46. package/src/assets/icons/pc/danmuSettings.svg +1 -0
  47. package/src/assets/icons/pc/download.svg +14 -0
  48. package/src/assets/icons/pc/exitFullscreen.svg +1 -0
  49. package/src/assets/icons/pc/exitMirror.svg +10 -0
  50. package/src/assets/icons/pc/extend.svg +1 -0
  51. package/src/assets/icons/pc/fullscreen.svg +1 -0
  52. package/src/assets/icons/pc/getMirror.svg +10 -0
  53. package/src/assets/icons/pc/list.svg +20 -0
  54. package/src/assets/icons/pc/noPoster.svg +119 -0
  55. package/src/assets/icons/pc/pause.svg +1 -0
  56. package/src/assets/icons/pc/pip.svg +1 -0
  57. package/src/assets/icons/pc/pipExit.svg +1 -0
  58. package/src/assets/icons/pc/play-next-btn.svg +4 -0
  59. package/src/assets/icons/pc/play.svg +1 -0
  60. package/src/assets/icons/pc/playNext.svg +1 -0
  61. package/src/assets/icons/pc/playerLoading.svg +1 -0
  62. package/src/assets/icons/pc/refresh.svg +1 -0
  63. package/src/assets/icons/pc/replay.svg +1 -0
  64. package/src/assets/icons/pc/reset.svg +6 -0
  65. package/src/assets/icons/pc/startPlay.svg +1 -0
  66. package/src/assets/icons/pc/subtitleclose.svg +5 -0
  67. package/src/assets/icons/pc/subtitleopen.svg +3 -0
  68. package/src/assets/icons/pc/theaterEnter.svg +1 -0
  69. package/src/assets/icons/pc/theaterExit.svg +1 -0
  70. package/src/assets/icons/pc/volumeLarge.svg +1 -0
  71. package/src/assets/icons/pc/volumeMuted.svg +1 -0
  72. package/src/assets/icons/pc/volumeSmall.svg +1 -0
  73. package/src/config/defaultPreset.ts +110 -0
  74. package/src/config/playerOptionMobile.ts +166 -0
  75. package/src/config/playerOptionPc.ts +147 -0
  76. package/src/config/playerPreset.ts +242 -0
  77. package/src/constants/api.ts +13 -0
  78. package/src/constants/event.ts +577 -0
  79. package/src/constants/player.ts +84 -0
  80. package/src/constants/plugin.ts +19 -0
  81. package/src/constants/umdMap.ts +137 -0
  82. package/src/constants/umdPlugins.json +68 -0
  83. package/src/core/index.ts +7 -0
  84. package/src/core/player.ts +2713 -0
  85. package/src/core/playerData.ts +812 -0
  86. package/src/env.d.ts +47 -0
  87. package/src/index.ts +24 -0
  88. package/src/index.umd.ts +54 -0
  89. package/src/interface/adaptRange.d.ts +33 -0
  90. package/src/interface/api.ts +132 -0
  91. package/src/interface/autoBitrate.d.ts +41 -0
  92. package/src/interface/index.ts +1685 -0
  93. package/src/interface/rtm.ts +56 -0
  94. package/src/interface/sdkErrorPlugin.ts +145 -0
  95. package/src/interface/subtitle.ts +381 -0
  96. package/src/interface/video.ts +107 -0
  97. package/src/interface/xgplayer.ts +748 -0
  98. package/src/lang/constants.ts +69 -0
  99. package/src/lang/en.ts +98 -0
  100. package/src/lang/index.ts +33 -0
  101. package/src/lang/jp.ts +100 -0
  102. package/src/lang/zh-hk.ts +80 -0
  103. package/src/lang/zh.ts +79 -0
  104. package/src/license/index.ts +315 -0
  105. package/src/license/ttlicense2.js +15 -0
  106. package/src/license/ttlicense2.wasm +0 -0
  107. package/src/music/icons/back.svg +3 -0
  108. package/src/music/icons/forward.svg +3 -0
  109. package/src/music/icons/loop.svg +10 -0
  110. package/src/music/icons/order.svg +10 -0
  111. package/src/music/icons/pause-circle.svg +23 -0
  112. package/src/music/icons/play-circle.svg +22 -0
  113. package/src/music/icons/random.svg +10 -0
  114. package/src/music/icons/sloop.svg +10 -0
  115. package/src/music/index.ts +5 -0
  116. package/src/music/music.ts +550 -0
  117. package/src/music/plugins/index.less +185 -0
  118. package/src/music/plugins/index.ts +6 -0
  119. package/src/music/plugins/musicBackward.ts +82 -0
  120. package/src/music/plugins/musicCover.ts +45 -0
  121. package/src/music/plugins/musicForward.ts +82 -0
  122. package/src/music/plugins/musicMeta.ts +32 -0
  123. package/src/music/plugins/musicMode.ts +152 -0
  124. package/src/music/plugins/musicNext.ts +93 -0
  125. package/src/music/plugins/musicPrev.ts +94 -0
  126. package/src/music/preset.ts +69 -0
  127. package/src/music/xhr.ts +37 -0
  128. package/src/plugins/common/extendPluginFactory.ts +132 -0
  129. package/src/plugins/common/mobilePlayerPanel.ts +253 -0
  130. package/src/plugins/external/LiveInfoPanel.ts +340 -0
  131. package/src/plugins/external/ad/adsPlugin.ts +1 -0
  132. package/src/plugins/external/aiSubtitleIconPlugin.ts +270 -0
  133. package/src/plugins/external/aiSubtitlePlugin.ts +452 -0
  134. package/src/plugins/external/definitionDemotePlugin.ts +591 -0
  135. package/src/plugins/external/memoryPlay.ts +247 -0
  136. package/src/plugins/external/mirrorPlugin.ts +141 -0
  137. package/src/plugins/external/playList/OptionList.ts +204 -0
  138. package/src/plugins/external/playList/index.ts +743 -0
  139. package/src/plugins/external/subtitle/index.ts +672 -0
  140. package/src/plugins/external/subtitle/nativeSubTitle.ts +115 -0
  141. package/src/plugins/external/timeShiftPlugin.ts +484 -0
  142. package/src/plugins/external/watermark/dynamicWatermark.less +13 -0
  143. package/src/plugins/external/watermark/dynamicWatermark.ts +449 -0
  144. package/src/plugins/external/watermark/dynamicWatermarkPlugin.ts +185 -0
  145. package/src/plugins/inner/common/autoplayPlugin.ts +435 -0
  146. package/src/plugins/inner/common/danmu/container.ts +120 -0
  147. package/src/plugins/inner/common/danmu/index.ts +683 -0
  148. package/src/plugins/inner/common/danmu/lang.ts +139 -0
  149. package/src/plugins/inner/common/danmu/panel.ts +20 -0
  150. package/src/plugins/inner/common/danmu/slider.ts +210 -0
  151. package/src/plugins/inner/common/danmu/state.ts +118 -0
  152. package/src/plugins/inner/common/danmu/switch.ts +74 -0
  153. package/src/plugins/inner/common/definitionBasePlugin.ts +353 -0
  154. package/src/plugins/inner/common/errorPlugin.ts +544 -0
  155. package/src/plugins/inner/common/liveLogger.ts +137 -0
  156. package/src/plugins/inner/common/poster/index.less +66 -0
  157. package/src/plugins/inner/common/poster/index.ts +178 -0
  158. package/src/plugins/inner/common/refreshPlugin.ts +88 -0
  159. package/src/plugins/inner/common/rtmPlugin.ts +62 -0
  160. package/src/plugins/inner/common/toastPlugin.ts +90 -0
  161. package/src/plugins/inner/common/unmutePlugin.ts +133 -0
  162. package/src/plugins/inner/common/vodLogger.ts +80 -0
  163. package/src/plugins/inner/mobile/DefinitionMobilePlugin.ts +217 -0
  164. package/src/plugins/inner/mobile/LineMobilePlugins.ts +169 -0
  165. package/src/plugins/inner/mobile/MoreButtonPlugin.ts +176 -0
  166. package/src/plugins/inner/mobile/PlaybackRatePlugin.ts +199 -0
  167. package/src/plugins/inner/pc/definitionPlugin.ts +203 -0
  168. package/src/plugins/inner/pc/multilinePlugin.ts +93 -0
  169. package/src/sdkPlugin/abr.ts +67 -0
  170. package/src/sdkPlugin/adaptRange.ts +49 -0
  171. package/src/sdkPlugin/authToken.ts +557 -0
  172. package/src/sdkPlugin/sdkPlugin.ts +125 -0
  173. package/src/sdkPlugin/sdkPluginManager.ts +157 -0
  174. package/src/sdkPlugin/strategy.ts +47 -0
  175. package/src/strategy/index.ts +740 -0
  176. package/src/strategy/vestrategy-h265-wrapper.ts +34 -0
  177. package/src/strategy/vestrategy-preload-wrapper.ts +414 -0
  178. package/src/streamAdapters/base.ts +89 -0
  179. package/src/streamAdapters/dash.ts +230 -0
  180. package/src/streamAdapters/default.ts +53 -0
  181. package/src/streamAdapters/hls.ts +278 -0
  182. package/src/streamAdapters/index.ts +40 -0
  183. package/src/streamAdapters/mp4.ts +214 -0
  184. package/src/style/bytelive/danmu.less +293 -0
  185. package/src/style/bytelive/definitionIcon.less +80 -0
  186. package/src/style/bytelive/error.less +165 -0
  187. package/src/style/bytelive/index.less +62 -0
  188. package/src/style/bytelive/loading.less +5 -0
  189. package/src/style/bytelive/mobiePlugin.less +2 -0
  190. package/src/style/bytelive/mobile.less +76 -0
  191. package/src/style/bytelive/moreButton.less +79 -0
  192. package/src/style/bytelive/panel.less +259 -0
  193. package/src/style/bytelive/pc.less +161 -0
  194. package/src/style/bytelive/refresh.less +3 -0
  195. package/src/style/bytelive/reset.less +4 -0
  196. package/src/style/bytelive/toast.less +61 -0
  197. package/src/style/bytelive/unmute.less +65 -0
  198. package/src/style/external/LiveInfoPanel.less +41 -0
  199. package/src/style/external/aisub.less +139 -0
  200. package/src/style/external/aisubIcon.less +25 -0
  201. package/src/style/external/index.less +5 -0
  202. package/src/style/external/larkWindow.less +36 -0
  203. package/src/style/external/mirror.less +27 -0
  204. package/src/style/external/playList.less +258 -0
  205. package/src/style/external/timeShift.less +102 -0
  206. package/src/style/external/vttSubtitle.less +25 -0
  207. package/src/utils/debug.ts +62 -0
  208. package/src/utils/definition.ts +61 -0
  209. package/src/utils/escapeHtml.ts +93 -0
  210. package/src/utils/eventMiddleWare.ts +108 -0
  211. package/src/utils/index.ts +621 -0
  212. package/src/utils/intervalTimer.ts +38 -0
  213. package/src/utils/isHijackBrowser.ts +71 -0
  214. package/src/utils/proxy.ts +139 -0
  215. package/src/utils/storage.ts +34 -0
  216. package/src/utils/time.ts +19 -0
  217. package/src/utils/toast/index.less +20 -0
  218. package/src/utils/toast/index.ts +21 -0
  219. package/src/utils/token.ts +395 -0
  220. package/src/utils/u8a.ts +4 -0
  221. package/src/utils/umdLoader.ts +193 -0
  222. package/src/utils/video.ts +43 -0
  223. package/src/utils/xhr.ts +160 -0
  224. package/src/veError/error.ts +301 -0
  225. package/src/veError/index.ts +681 -0
  226. package/src/veError/playerProxy.ts +69 -0
  227. package/tsconfig.json +27 -0
  228. package/index.d.ts +0 -6874
  229. package/index.min.css +0 -1
  230. package/index.min.js +0 -2
  231. package/plugin/DashAbralgo.js +0 -2
  232. package/plugin/XGVideo.js +0 -2
  233. package/plugin/danmuMask.js +0 -2
  234. package/plugin/danmujs.js +0 -3
  235. package/plugin/dash.js +0 -2
  236. package/plugin/flv.js +0 -2
  237. package/plugin/hls.js +0 -2
  238. package/plugin/hlsEncrypt.js +0 -2
  239. package/plugin/mp4Encrypt.js +0 -2
  240. package/plugin/preloader.js +0 -2
  241. package/plugin/streamprobe.js +0 -2
  242. package/plugin/vestrategy.js +0 -1
  243. package/plugin/vestrategy_adapt_range.js +0 -1
  244. package/plugin/vestrategy_h265.js +0 -1
  245. package/plugin/vestrategy_preload.js +0 -1
@@ -0,0 +1,550 @@
1
+ import { BasePlugin, Util, Events } from 'xgplayer';
2
+ import { PluginEvents } from '@/constants/event';
3
+ import type {
4
+ PlayModeType,
5
+ IMusicListItem,
6
+ IABCycle,
7
+ IMusicConfig,
8
+ } from '@/interface';
9
+ import Xhr from './xhr';
10
+ import { VE_DEBUG } from '@/utils';
11
+
12
+ export const PLAY_MODES: Record<string, PlayModeType> = {
13
+ ORDER: 'order',
14
+ SLOOP: 'sloop',
15
+ LOOP: 'loop',
16
+ RANDOM: 'random',
17
+ };
18
+
19
+ const CLASS_NAME = 'xgplayer-music';
20
+
21
+ // 获取随机数,保证随机出的数字不与当前重复
22
+ function _randomIndex(min, max, index) {
23
+ const i = Math.floor(Math.random() * (max - min) + min);
24
+ if (i === index) {
25
+ if (i > max / 2) {
26
+ max = max / 2;
27
+ } else {
28
+ min = max / 2;
29
+ }
30
+ return max - min > 2 ? _randomIndex(min, max, index) : i;
31
+ } else {
32
+ return i;
33
+ }
34
+ }
35
+
36
+ export default class Music extends BasePlugin {
37
+ private halfPass: boolean;
38
+ public list: any;
39
+ public nextIndex: number;
40
+ public prevIndex: number;
41
+ public history: any[];
42
+ public disable: boolean;
43
+ private _curInfo: IMusicListItem;
44
+ public index: number;
45
+ static get pluginName() {
46
+ return 'music';
47
+ }
48
+
49
+ /**
50
+ * @type { IMusicConfig }
51
+ */
52
+ static get defaultConfig(): IMusicConfig {
53
+ return {
54
+ offline: false, // Whether to support offline playback
55
+ preloadNext: true,
56
+ abCycle: null, // ab loop playback configuration
57
+ timeScale: 15, // Each time span when forward or backward
58
+ mode: PLAY_MODES.ORDER, // Play mode, the default value id 'order'
59
+ list: [], // Initial Playlist
60
+ };
61
+ }
62
+
63
+ /**
64
+ * @desc
65
+ * @type {Array<string>}}
66
+ */
67
+ static get ModeType() {
68
+ return Object.keys(PLAY_MODES).map(key => PLAY_MODES[key]);
69
+ }
70
+
71
+ afterCreate() {
72
+ const { player, playerConfig } = this;
73
+ Util.addClass(player.root, CLASS_NAME);
74
+ this.halfPass = false;
75
+ this.list = this.config.list || [];
76
+ this.emit(PluginEvents.MUSIC_LIST_CHANGE, this.list);
77
+ this.nextIndex = -1;
78
+ this.prevIndex = -1;
79
+ this.history = [];
80
+ this.disable = !(this.list.length > 0);
81
+ if (!playerConfig.url && this.list.length > 0) {
82
+ playerConfig.url = this.list?.[0]?.src;
83
+ }
84
+
85
+ if (!playerConfig.poster) {
86
+ playerConfig.poster = this.list?.[0]?.poster;
87
+ }
88
+
89
+ if (!playerConfig.title) {
90
+ playerConfig.title = this.list?.[0]?.title ?? '';
91
+ }
92
+
93
+ if (!playerConfig.vid) {
94
+ playerConfig.vid = this.list?.[0]?.vid ?? '';
95
+ }
96
+
97
+ this._curInfo = {
98
+ src: playerConfig.url as string,
99
+ poster: playerConfig.poster as string,
100
+ title: playerConfig.title,
101
+ vid: playerConfig.vid,
102
+ };
103
+
104
+ this.index = 0;
105
+
106
+ this.on(Events.TIME_UPDATE, this._onTimeUpdate);
107
+
108
+ this.on(Events.ENDED, this._onEnded);
109
+
110
+ this.on(Events.DURATION_CHANGE, this._onDurationChange);
111
+
112
+ if (this.config.offline) {
113
+ this.checkOffline(this._curInfo.src, this._curInfo.vid)
114
+ .then(data => {
115
+ if (data.code === 0) {
116
+ playerConfig.url = data.url;
117
+ if (player.state >= 4) {
118
+ player.src = data.url;
119
+ }
120
+ }
121
+ })
122
+ .catch(e => {
123
+ VE_DEBUG.error(e);
124
+ });
125
+ }
126
+ }
127
+
128
+ destroy() {
129
+ Util.removeClass(this.player.root, CLASS_NAME);
130
+ }
131
+
132
+ _onEnded = () => {
133
+ if (this.mode === 'order' && this.index + 1 >= this.list.length) {
134
+ this.player.pause();
135
+ this.player.currentTime = 0;
136
+ return;
137
+ }
138
+ switch (this.mode) {
139
+ case PLAY_MODES.SLOOP:
140
+ this.change();
141
+ break;
142
+ case PLAY_MODES.ORDER:
143
+ case PLAY_MODES.LOOP:
144
+ default:
145
+ this.next();
146
+ break;
147
+ }
148
+ };
149
+
150
+ _onDurationChange = () => {
151
+ const { abCycle } = this.config;
152
+ this._initABCycle(abCycle, this.player);
153
+ };
154
+
155
+ _onTimeUpdate = () => {
156
+ const { config, player } = this;
157
+ if (!this.halfPass && player.currentTime > player.duration / 2) {
158
+ this.confirmOrder();
159
+ }
160
+ if (config.abCycle) {
161
+ const c = config.abCycle;
162
+ const _end = c.end > player.duration ? player.duration : c.end;
163
+ if (player.currentTime >= _end) {
164
+ if (!c.loop) {
165
+ player.pause();
166
+ this.emit('abCycle_ended');
167
+ }
168
+ player.currentTime = c.start || 0;
169
+ } else if (player.currentTime < c.start) {
170
+ player.currentTime = c.start || 0;
171
+ }
172
+ }
173
+ };
174
+
175
+ _nextCompute() {
176
+ if (this.disable) {
177
+ return;
178
+ }
179
+ switch (this.mode) {
180
+ case PLAY_MODES.SLOOP:
181
+ this.nextIndex = this.index;
182
+ break;
183
+ case PLAY_MODES.ORDER:
184
+ case PLAY_MODES.LOOP:
185
+ if (this.index + 1 < this.list.length) {
186
+ this.nextIndex = this.index + 1;
187
+ } else {
188
+ this.nextIndex = 0;
189
+ }
190
+ break;
191
+ default:
192
+ this.nextIndex = _randomIndex(0, this.list.length, this.index);
193
+ break;
194
+ }
195
+ }
196
+
197
+ _prevCompute() {
198
+ if (this.disable) {
199
+ return;
200
+ }
201
+ switch (this.mode) {
202
+ case PLAY_MODES.SLOOP:
203
+ this.nextIndex = this.index;
204
+ break;
205
+ case PLAY_MODES.ORDER:
206
+ case PLAY_MODES.LOOP:
207
+ if (this.index - 1 >= 0) {
208
+ this.prevIndex = this.index - 1;
209
+ } else {
210
+ this.prevIndex = this.list.length - 1;
211
+ }
212
+ break;
213
+ default:
214
+ this.prevIndex = _randomIndex(0, this.list.length, this.index);
215
+ break;
216
+ }
217
+ }
218
+
219
+ _emitChange() {
220
+ this.emit(PluginEvents.MUSIC_CHANGE, this._curInfo);
221
+ }
222
+
223
+ _initABCycle(abCycle, player) {
224
+ const _p = player.plugins.progresspreview;
225
+ if (abCycle && player) {
226
+ const _end =
227
+ abCycle.end > this.player.duration ? this.player.duration : abCycle.end;
228
+ const _start = abCycle.start > this.player.duration ? 0 : abCycle.start;
229
+ const dot = {
230
+ id: player.playerId, // 标记唯一标识,用于删除的时候索引
231
+ time: abCycle.start, // 进度条在此时间戳打点 单位为s
232
+ duration: _end - _start, // 进度条标识点的时长 默认1s【可选】单位为s
233
+ text: abCycle.text, // 打点处的自定义文案
234
+ color: abCycle.color, // 进度条标识点的显示颜色【可选】
235
+ };
236
+ _p.findDot(dot.id) ? _p.updateDot(dot) : _p.createDot(dot);
237
+ } else {
238
+ _p.findDot(player.playerId) ? _p.deleteDot(player.playerId) : '';
239
+ }
240
+ }
241
+
242
+ /**
243
+ * @desc Get a random one from the playlist
244
+ * @returns { IMusicListItem | null }
245
+ */
246
+ random() {
247
+ if (this.list.length < 0) {
248
+ return null;
249
+ }
250
+ const _i = _randomIndex(0, this.list.length, this.index);
251
+ return this.list[_i];
252
+ }
253
+
254
+ /**
255
+ * @desc play next item in playlist
256
+ * @returns
257
+ */
258
+ next() {
259
+ if (this.disable) {
260
+ return;
261
+ }
262
+ if (!this.halfPass) {
263
+ this.halfPass = true;
264
+ this._nextCompute();
265
+ }
266
+ this.index = this.nextIndex;
267
+ this.change();
268
+ }
269
+
270
+ /**
271
+ * @desc play previous item in playlist
272
+ * @returns
273
+ */
274
+ prev() {
275
+ if (this.disable) {
276
+ return;
277
+ }
278
+ if (!this.halfPass) {
279
+ this.halfPass = true;
280
+ this._prevCompute();
281
+ }
282
+ this.index = this.prevIndex;
283
+ this.change();
284
+ }
285
+
286
+ /**
287
+ * @desc fast forward play,
288
+ */
289
+ forward() {
290
+ const { player } = this;
291
+ const { timeScale } = this.config;
292
+ player.currentTime =
293
+ player.currentTime + timeScale < player.duration
294
+ ? player.currentTime + timeScale
295
+ : player.duration - 0.1;
296
+ }
297
+
298
+ /**
299
+ * @desc rewind playback
300
+ */
301
+ backward() {
302
+ const { player } = this;
303
+ const { timeScale } = this.config;
304
+ player.currentTime =
305
+ player.currentTime - timeScale > 0 ? player.currentTime - timeScale : 0;
306
+ }
307
+
308
+ /**
309
+ * @desc Add list item to the list
310
+ * @param { IMusicListItem } meta
311
+ */
312
+ add(meta) {
313
+ this.list.push({
314
+ src: meta.src,
315
+ title: meta.title,
316
+ vid: meta.vid,
317
+ poster: meta.poster,
318
+ });
319
+ this.disable = !(this.list.length > 0);
320
+ this.emit(PluginEvents.MUSIC_LIST_CHANGE, this.list);
321
+ }
322
+
323
+ /**
324
+ * @desc Remove list item from the list
325
+ * @param { string } vid
326
+ */
327
+ remove(vid) {
328
+ let idx = -1;
329
+ this.list.every((item, index) => {
330
+ if (item.vid === vid) {
331
+ idx = index;
332
+ return false;
333
+ } else {
334
+ return true;
335
+ }
336
+ });
337
+ if (idx > -1) {
338
+ this.list.splice(idx, 1);
339
+ this.emit(PluginEvents.MUSIC_LIST_CHANGE, this.list);
340
+ }
341
+ this.disable = !(this.list.length > 0);
342
+ }
343
+
344
+ /**
345
+ * @desc set abCycle config
346
+ * @param { number | IABCycle } start
347
+ * @param { number } [end]
348
+ * @param { boolean } [loop]
349
+ * @param {{ [propName: string]: any }} [ext]
350
+ */
351
+ setAbCycle(
352
+ start: number | IABCycle,
353
+ end: number,
354
+ loop: boolean,
355
+ ext: { [propName: string]: any } = {},
356
+ ) {
357
+ if (start && Util.typeOf(start) === 'Object') {
358
+ this.config.abCycle = {
359
+ ...(start as IABCycle),
360
+ };
361
+ } else {
362
+ this.config.abCycle = {
363
+ start: start || 0,
364
+ end: end || this.player.duration,
365
+ loop,
366
+ ...ext,
367
+ };
368
+ }
369
+ this._initABCycle(this.config.abCycle, this.player);
370
+ }
371
+
372
+ /**
373
+ * @desc remove abCycle config
374
+ */
375
+ removeAbCycle() {
376
+ this.config.abCycle = null;
377
+ this._initABCycle(null, this.player);
378
+ }
379
+
380
+ /**
381
+ * @desc update the playList
382
+ * @param { Array<IMusicListItem> } list
383
+ */
384
+ updateList(list = []) {
385
+ this.removeAbCycle();
386
+ this.player.pause();
387
+ this.player.currentTime = 0;
388
+ this.list = list;
389
+ this.nextIndex = 0;
390
+ this.index = 0;
391
+ this.change();
392
+ this.disable = !(this.list.length > 0);
393
+ this.emit(PluginEvents.MUSIC_LIST_CHANGE, this.list);
394
+ }
395
+
396
+ /**
397
+ * @desc set play index
398
+ * @param { number } index
399
+ */
400
+ setIndex(index = 0) {
401
+ if (index < 0 || index >= this.list.length) {
402
+ return;
403
+ }
404
+ this.nextIndex = index;
405
+ this.index = index;
406
+ this.change();
407
+ }
408
+
409
+ change() {
410
+ if (this.disable) {
411
+ return;
412
+ }
413
+ const { player, list, index } = this;
414
+ const offlineVid = list[index].vid;
415
+ this.halfPass = false;
416
+ this.checkOffline(list[index].src, offlineVid).then(data => {
417
+ this._curInfo = {
418
+ title: this.list[this.index].title || '',
419
+ vid: this.list[this.index].vid,
420
+ poster: this.list[this.index].poster || '',
421
+ src: data.url,
422
+ };
423
+
424
+ player.playNext({
425
+ url: data.url,
426
+ vid: this.list[this.index].vid || 0,
427
+ poster: this.list[this.index].poster || '',
428
+ autoplay: true,
429
+ });
430
+ player.off('timeupdate', this._emitChange.bind(this));
431
+ player.once('timeupdate', this._emitChange.bind(this));
432
+ player.play();
433
+ });
434
+ }
435
+
436
+ /**
437
+ * 检查当前播放音频是否有本地缓存
438
+ * @param { string } url
439
+ * @param { string | number } offlineVid
440
+ * @returns
441
+ */
442
+ checkOffline(
443
+ url,
444
+ offlineVid,
445
+ ): Promise<{
446
+ url: string;
447
+ code: number;
448
+ vid: string | number;
449
+ }> {
450
+ return new Promise((resolve, reject) => {
451
+ if (!this.config.offline || this.disable) {
452
+ return resolve({
453
+ url,
454
+ code: -1,
455
+ vid: offlineVid,
456
+ });
457
+ }
458
+ const { database } = this.player;
459
+ database.openDB(() => {
460
+ database.getDataByKey(
461
+ database.myDB.ojstore.name,
462
+ offlineVid,
463
+ result => {
464
+ setTimeout(() => {
465
+ database.closeDB();
466
+ }, 5000);
467
+ if (result) {
468
+ resolve({
469
+ url: URL.createObjectURL(result.blob),
470
+ code: 0,
471
+ vid: result.vid,
472
+ });
473
+ } else {
474
+ resolve({
475
+ url,
476
+ code: -2,
477
+ vid: offlineVid,
478
+ });
479
+ }
480
+ },
481
+ );
482
+ });
483
+ });
484
+ }
485
+
486
+ confirmOrder() {
487
+ this.halfPass = true;
488
+ this._nextCompute();
489
+ this._prevCompute();
490
+ if (this.config.preloadNext) {
491
+ this.preload(this.nextIndex);
492
+ }
493
+ }
494
+
495
+ preload(index) {
496
+ if (index < 0 || index >= this.list.length) {
497
+ return;
498
+ }
499
+ const _item = this.list[index];
500
+ const { player } = this;
501
+ this.checkOffline(_item.src, _item.vid).then(data => {
502
+ if (data.code === -2) {
503
+ const offlineVid = _item.vid;
504
+ new Xhr(_item.src, res => {
505
+ player.database.openDB(() => {
506
+ player.database.addData(player.database.myDB.ojstore.name, [
507
+ {
508
+ vid: offlineVid,
509
+ blob: new Blob([res], {
510
+ type: 'audio/mp4; codecs="mp4a.40.5"',
511
+ }),
512
+ },
513
+ ]);
514
+ setTimeout(() => {
515
+ player.database.closeDB();
516
+ }, 5000);
517
+ });
518
+ });
519
+ }
520
+ });
521
+ }
522
+
523
+ /**
524
+ * @type { number }
525
+ * @description forward or backward time scale
526
+ */
527
+ get timeScale(): number {
528
+ return this.config.timeScale || 15;
529
+ }
530
+
531
+ set timeScale(scale: number) {
532
+ this.config.timeScale = scale;
533
+ this.emit(PluginEvents.TIME_SCALE_CHANGE, scale);
534
+ }
535
+
536
+ /**
537
+ * @type { 'order' | 'sloop' | 'loop' | 'random' }
538
+ * @description set current play mode
539
+ */
540
+ get mode(): PlayModeType {
541
+ return this.config.mode || PLAY_MODES.RANDOM;
542
+ }
543
+
544
+ set mode(val: PlayModeType) {
545
+ if (Object.values(PLAY_MODES).includes(val)) {
546
+ this.config.mode = val;
547
+ this.emit(PluginEvents.MUSIC_MODE_CHANGE, val);
548
+ }
549
+ }
550
+ }
@@ -0,0 +1,185 @@
1
+ .xgplayer-music,
2
+ .xgplayer-controls {
3
+ border-radius: 4px;
4
+ }
5
+
6
+ .xgplayer.xgplayer-music {
7
+ overflow: visible;
8
+
9
+ .xg-video-container {
10
+ width: 0;
11
+ height: 0;
12
+ }
13
+
14
+ .xgplayer-controls {
15
+ height: 100%;
16
+ background: none;
17
+
18
+ .xgplayer-time {
19
+ &.xg-time-left {
20
+ margin-left: 16px;
21
+ }
22
+
23
+ &.xg-time-right {
24
+ margin-right: 16px;
25
+ }
26
+ }
27
+
28
+ .xgplayer-mobile {
29
+ .xgplayer-time {
30
+ &.xg-time-left {
31
+ margin-left: 8px;
32
+ }
33
+
34
+ &.xg-time-right {
35
+ margin-right: 8px;
36
+ }
37
+ }
38
+ }
39
+ }
40
+
41
+ xg-icon .xg-tips {
42
+ display: none;
43
+ }
44
+
45
+ .xgplayer-progress {
46
+ top: 0;
47
+ transform: none;
48
+ min-width: 80px;
49
+
50
+ .xgplayer-progress-point {
51
+ opacity: 0;
52
+ }
53
+ }
54
+
55
+ xg-bar {
56
+ display: none;
57
+ }
58
+ }
59
+
60
+ .xgplayer-music.xgplayer {
61
+ background: #1d2129;
62
+
63
+ .flex-controls .xg-inner-controls {
64
+ bottom: 14px;
65
+ }
66
+
67
+ .xg-pos {
68
+ left: 22px;
69
+ right: 22px;
70
+ }
71
+
72
+ xg-icon {
73
+ .xg-tips {
74
+ top: -20px;
75
+ }
76
+ }
77
+
78
+ .xgplayer-cover,
79
+ .xgplayer-time {
80
+ cursor: unset;
81
+ }
82
+
83
+ .xgplayer-name {
84
+ top: -26px;
85
+ position: absolute;
86
+ color: #ddd;
87
+ display: block;
88
+ text-align: left;
89
+ white-space: nowrap;
90
+ cursor: unset;
91
+ }
92
+
93
+ .xgplayer-backward,
94
+ .xgplayer-forward {
95
+ .xgplayer-timescale {
96
+ position: absolute;
97
+ top: 50%;
98
+ left: 50%;
99
+ transform: translate(-50%, -50%);
100
+ font-weight: bold;
101
+ color: #fff;
102
+ font-size: 12px;
103
+ }
104
+ }
105
+
106
+ .xgplayer-play {
107
+ .xgplayer-icon {
108
+ svg {
109
+ font-size: 20px;
110
+ }
111
+ }
112
+ }
113
+
114
+ .xgplayer-music-mode {
115
+ .xg-icon-order {
116
+ display: block;
117
+ }
118
+
119
+ .xg-icon-loop {
120
+ display: none;
121
+ }
122
+
123
+ .xg-icon-sloop {
124
+ display: none;
125
+ }
126
+
127
+ .xg-icon-random {
128
+ display: none;
129
+ }
130
+
131
+ &[data-state='loop'] {
132
+ .xg-icon-order {
133
+ display: none;
134
+ }
135
+
136
+ .xg-icon-loop {
137
+ display: block;
138
+ }
139
+
140
+ .xg-icon-sloop {
141
+ display: none;
142
+ }
143
+
144
+ .xg-icon-random {
145
+ display: none;
146
+ }
147
+ }
148
+
149
+ &[data-state='sloop'] {
150
+ .xg-icon-order {
151
+ display: none;
152
+ }
153
+
154
+ .xg-icon-loop {
155
+ display: none;
156
+ }
157
+
158
+ .xg-icon-sloop {
159
+ display: block;
160
+ }
161
+
162
+ .xg-icon-random {
163
+ display: none;
164
+ }
165
+ }
166
+
167
+ &[data-state='random'] {
168
+ .xg-icon-order {
169
+ display: none;
170
+ }
171
+
172
+ .xg-icon-loop {
173
+ display: none;
174
+ }
175
+
176
+ .xg-icon-sloop {
177
+ display: none;
178
+ }
179
+
180
+ .xg-icon-random {
181
+ display: block;
182
+ }
183
+ }
184
+ }
185
+ }