MCPcopy
hub / github.com/iChochy/NCE / prefetchUnit

Method prefetchUnit

js/ReadingSystem.js:862–881  ·  view source on GitHub ↗

* 预加载单元资源 * @param {number} unitIndex - 单元索引

(unitIndex)

Source from the content-addressed store, hash-verified

860 * @param {number} unitIndex - 单元索引
861 */
862 prefetchUnit(unitIndex) {
863 const unit = this.state.units[unitIndex];
864 if (!unit) return;
865
866 // 预加载 LRC
867 if (unit.lrc && !this.lrcCache.has(unit.lrc)) {
868 fetch(unit.lrc)
869 .then((response) => response.text())
870 .then((text) => this.lrcCache.set(unit.lrc, text))
871 .catch(() => {});
872 }
873
874 // 预加载音频
875 if (unit.audio && !this.audioPreload.has(unit.audio)) {
876 const audio = new Audio();
877 audio.preload = 'auto';
878 audio.src = unit.audio;
879 this.audioPreload.set(unit.audio, audio);
880 }
881 }
882
883 // =========================================================================
884 // 事件绑定

Callers 1

loadUnitByIndexMethod · 0.95

Calls 2

hasMethod · 0.80
setMethod · 0.80

Tested by

no test coverage detected