@ives_xxz/framework 2.1.7 → 2.1.8
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.
- package/manager/FWAudioManager.ts +23 -20
- package/package.json +1 -1
|
@@ -96,34 +96,37 @@ export default class FWAudioManager extends FWManager implements FW.AudioManager
|
|
|
96
96
|
): Promise<number>;
|
|
97
97
|
async play(): Promise<number> {
|
|
98
98
|
try {
|
|
99
|
-
|
|
100
|
-
this.clearFinishedAudio();
|
|
99
|
+
return new Promise<number>(async (resolve, reject) => {
|
|
101
100
|
if (this.audioPool.size >= this.maxConcurrentAudio) {
|
|
102
|
-
|
|
103
|
-
|
|
101
|
+
this.clearFinishedAudio();
|
|
102
|
+
if (this.audioPool.size >= this.maxConcurrentAudio) {
|
|
103
|
+
FW.Log.warn('音频池已满,无法播放新音频');
|
|
104
|
+
return -1;
|
|
105
|
+
}
|
|
104
106
|
}
|
|
105
|
-
}
|
|
106
107
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
108
|
+
const audioData = await this.processAudioArguments(
|
|
109
|
+
arguments,
|
|
110
|
+
FW.SystemDefine.FWAudioType.SOUND,
|
|
111
|
+
);
|
|
112
|
+
if (!audioData.clip) return -1;
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
114
|
+
const volume = (audioData.volume ?? this.soundVolume) * this.effectsVolume;
|
|
115
|
+
const loop = audioData.loop ?? false;
|
|
116
|
+
const tag = audioData.tag;
|
|
116
117
|
|
|
117
|
-
|
|
118
|
+
const id = cc.audioEngine.play(audioData.clip, loop, volume);
|
|
118
119
|
|
|
119
|
-
|
|
120
|
+
this.audioPool.set(id, new FWAudioPoolItem(id, Date.now(), tag));
|
|
120
121
|
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
122
|
+
cc.audioEngine.setFinishCallback(id, () => {
|
|
123
|
+
audioData.cb?.(id);
|
|
124
|
+
resolve(id);
|
|
125
|
+
this.audioPool.delete(id);
|
|
126
|
+
});
|
|
125
127
|
|
|
126
|
-
|
|
128
|
+
return id;
|
|
129
|
+
});
|
|
127
130
|
} catch (e) {
|
|
128
131
|
FW.Log.error('播放音效失败:', e);
|
|
129
132
|
return -1;
|