2024-02-21 17:48:18 +08:00
|
|
|
import moduleHelper from './module-helper';
|
|
|
|
|
import { formatJsonStr, getListObject, uid } from './utils';
|
|
|
|
|
const videoList = {};
|
|
|
|
|
const getObject = getListObject(videoList, 'video');
|
|
|
|
|
export default {
|
|
|
|
|
WXCreateVideo(conf) {
|
|
|
|
|
const id = uid();
|
|
|
|
|
const params = formatJsonStr(conf);
|
|
|
|
|
|
|
|
|
|
if (params.underGameView) {
|
|
|
|
|
GameGlobal.enableTransparentCanvas = true;
|
|
|
|
|
}
|
|
|
|
|
videoList[id] = wx.createVideo(params);
|
|
|
|
|
return id;
|
|
|
|
|
},
|
|
|
|
|
WXVideoSetProperty(id, key, value) {
|
|
|
|
|
const obj = getObject(id);
|
|
|
|
|
if (!obj) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2025-09-08 10:47:21 +08:00
|
|
|
if (key === 'x' || key === 'y' || key === 'width' || key === 'height' || key === 'initialTime' || key === 'playbackRate') {
|
2024-02-21 17:48:18 +08:00
|
|
|
obj[key] = +value;
|
|
|
|
|
}
|
2025-09-08 10:47:21 +08:00
|
|
|
else if (key === 'src' || key === 'poster' || key === 'objectFit' || key === 'backgroundColor') {
|
2024-02-21 17:48:18 +08:00
|
|
|
obj[key] = value;
|
|
|
|
|
}
|
2025-09-08 10:47:21 +08:00
|
|
|
else if (key === 'live' || key === 'controls' || key === 'showProgress' || key === 'showProgressInControlMode'
|
|
|
|
|
|| key === 'autoplay' || key === 'loop' || key === 'muted' || key === 'obeyMuteSwitch'
|
|
|
|
|
|| key === 'enableProgressGesture' || key === 'enablePlayGesture' || key === 'showCenterPlayBtn') {
|
|
|
|
|
obj[key] = value === 'True';
|
2024-02-21 17:48:18 +08:00
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
WXVideoAddListener(id, key) {
|
2025-09-08 10:47:21 +08:00
|
|
|
getObject(id)?.[key]((e) => {
|
2024-02-21 17:48:18 +08:00
|
|
|
moduleHelper.send('OnVideoCallback', JSON.stringify({
|
|
|
|
|
callbackId: id,
|
2025-09-08 10:47:21 +08:00
|
|
|
type: key,
|
|
|
|
|
position: e?.position,
|
|
|
|
|
buffered: e?.buffered ? Number(e.buffered) : undefined,
|
|
|
|
|
duration: e?.duration,
|
|
|
|
|
errMsg: e?.errMsg,
|
2024-02-21 17:48:18 +08:00
|
|
|
}));
|
|
|
|
|
if (key === 'onError') {
|
|
|
|
|
GameGlobal.enableTransparentCanvas = false;
|
|
|
|
|
console.error(e);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
2025-09-08 10:47:21 +08:00
|
|
|
WXVideoRemoveListener(id, key) {
|
|
|
|
|
getObject(id)?.[key]();
|
2024-02-21 17:48:18 +08:00
|
|
|
},
|
2025-09-08 10:47:21 +08:00
|
|
|
WXVideoDestroy(id, isLast) {
|
|
|
|
|
getObject(id)?.destroy();
|
|
|
|
|
if (isLast) {
|
|
|
|
|
GameGlobal.enableTransparentCanvas = false;
|
2024-02-21 17:48:18 +08:00
|
|
|
}
|
2025-09-08 10:47:21 +08:00
|
|
|
},
|
|
|
|
|
WXVideoPlay(id) {
|
|
|
|
|
getObject(id)?.play();
|
2024-02-21 17:48:18 +08:00
|
|
|
},
|
|
|
|
|
WXVideoPause(id) {
|
2025-09-08 10:47:21 +08:00
|
|
|
getObject(id)?.pause();
|
2024-02-21 17:48:18 +08:00
|
|
|
},
|
2025-09-08 10:47:21 +08:00
|
|
|
WXVideoStop(id) {
|
|
|
|
|
getObject(id)?.stop();
|
2024-02-21 17:48:18 +08:00
|
|
|
},
|
|
|
|
|
WXVideoSeek(id, time) {
|
2025-09-08 10:47:21 +08:00
|
|
|
getObject(id)?.seek(time);
|
2024-02-21 17:48:18 +08:00
|
|
|
},
|
2025-09-08 10:47:21 +08:00
|
|
|
WXVideoRequestFullScreen(id, direction) {
|
|
|
|
|
getObject(id)?.requestFullScreen(direction);
|
2024-02-21 17:48:18 +08:00
|
|
|
},
|
2025-09-08 10:47:21 +08:00
|
|
|
WXVideoExitFullScreen(id) {
|
|
|
|
|
getObject(id)?.exitFullScreen();
|
2024-02-21 17:48:18 +08:00
|
|
|
},
|
|
|
|
|
};
|