| 12345678910111213141516171819202122232425 |
- const videoContextCache = {}; // 使用普通对象作为缓存池
- /**
- * 获取缓存的 videoContext,如果没有则创建并缓存
- * @param {string} videoId 视频组件的 id
- * @returns {object} videoContext 对象
- */
- export function getVideoContext(videoId,currentComponent) {
- if (!videoContextCache[videoId]) {
- // 如果未缓存,则创建并缓存
- videoContextCache[videoId] = uni.createVideoContext(videoId,currentComponent);
- }
- return videoContextCache[videoId];
- }
- /**
- * 清理缓存的 videoContext
- * @param {string} videoId 视频的唯一标识符
- */
- export function clearCachedVideoContext(videoId) {
- if (videoContextCache[videoId]) {
- delete videoContextCache[videoId]; // 从 JSON 对象中删除
- }
- }
|