diff --git a/cocos/audio/linux/AudioEngine-linux.cpp b/cocos/audio/linux/AudioEngine-linux.cpp index 63bad17ab0..b53c63f8a8 100644 --- a/cocos/audio/linux/AudioEngine-linux.cpp +++ b/cocos/audio/linux/AudioEngine-linux.cpp @@ -261,6 +261,8 @@ void AudioEngineImpl::uncache(const std::string& path) } mapSound.erase(it); } + if (mapId.find(path) != mapId.end()) + mapId.erase(path); } void AudioEngineImpl::uncacheAll() @@ -272,6 +274,7 @@ void AudioEngineImpl::uncacheAll() } } mapSound.clear(); + mapId.clear(); } int AudioEngineImpl::preload(const std::string& filePath, std::function callback) @@ -291,6 +294,11 @@ int AudioEngineImpl::preload(const std::string& filePath, std::function(mapChannelInfo.size()) + 1; + if (mapId.find(filePath) == mapId.end()) + mapId.insert({filePath, id}); + else + id = mapId.at(filePath); + auto& chanelInfo = mapChannelInfo[id]; chanelInfo.sound = sound; chanelInfo.id = id; diff --git a/cocos/audio/linux/AudioEngine-linux.h b/cocos/audio/linux/AudioEngine-linux.h index 548a95b578..a0a4865182 100644 --- a/cocos/audio/linux/AudioEngine-linux.h +++ b/cocos/audio/linux/AudioEngine-linux.h @@ -93,6 +93,8 @@ private: }; std::map mapChannelInfo; + + std::map mapId; std::map mapSound;