MCPcopy
hub / github.com/OpenWebGAL/WebGAL / playVideo

Function playVideo

packages/webgal/src/Core/gameScripts/playVideo.tsx:13–93  ·  view source on GitHub ↗
(sentence: ISentence)

Source from the content-addressed store, hash-verified

11 * 播放一段视频 * @param sentence
12 */
13export const playVideo = (sentence: ISentence): IPerform => {
14 const userDataState = webgalStore.getState().userData;
15 const mainVol = userDataState.optionData.volumeMain;
16 const vocalVol = mainVol * 0.01 * userDataState.optionData.vocalVolume * 0.01;
17 const bgmVol = mainVol * 0.01 * userDataState.optionData.bgmVolume * 0.01;
18 const performInitName: string = getRandomPerformName();
19
20 let blockingNextFlag = getBooleanArgByKey(sentence, 'skipOff') ?? false;
21 let isOver = false;
22 let skipVideo = () => {};
23 const restoreVolumeAndUnmount = () => {
24 WebGAL.events.fullscreenDbClick.off(skipVideo);
25 /**
26 * 恢复音量
27 */
28 const bgmElement: any = document.getElementById('currentBgm');
29 if (bgmElement) {
30 bgmElement.volume = bgmVol.toString();
31 }
32 const vocalElement: any = document.getElementById('currentVocal');
33 if (vocalElement) {
34 vocalElement.volume = vocalVol.toString();
35 }
36 // eslint-disable-next-line react/no-deprecated
37 ReactDOM.render(<div />, document.getElementById('videoContainer'));
38 };
39 const endPerform = () => {
40 isOver = true;
41 WebGAL.gameplay.performController.unmountPerform(performInitName);
42 };
43 skipVideo = () => {
44 endPerform();
45 };
46 return {
47 performName: performInitName,
48 duration: 1000 * 60 * 60,
49 isHoldOn: false,
50 startFunction: () => {
51 // eslint-disable-next-line react/no-deprecated
52 ReactDOM.render(
53 <div className={styles.videoContainer}>
54 <video className={styles.fullScreen_video} id="playVideoElement" src={sentence.content} autoPlay={true} />
55 </div>,
56 document.getElementById('videoContainer'),
57 );
58 /**
59 * 启动视频播放
60 */
61 setTimeout(() => {
62 let VocalControl: any = document.getElementById('playVideoElement');
63 if (VocalControl !== null) {
64 VocalControl.currentTime = 0;
65 VocalControl.volume = bgmVol;
66 // 双击可跳过视频
67 WebGAL.events.fullscreenDbClick.on(skipVideo);
68 /**
69 * 把bgm和语音的音量设为0
70 */

Callers

nothing calls this directly

Calls 4

getRandomPerformNameFunction · 0.90
getBooleanArgByKeyFunction · 0.90
endPerformFunction · 0.85
playMethod · 0.80

Tested by

no test coverage detected