Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 3 additions & 6 deletions cocos/audio/AudioEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ void AudioEngine::remove(int audioID)
it->second.profileHelper->audioIDs.remove(audioID);
}
_audioPathIDMap[*it->second.filePath].remove(audioID);
_audioIDInfoMap.erase(audioID);
_audioIDInfoMap.erase(it);
}
}

Expand Down Expand Up @@ -394,16 +394,13 @@ void AudioEngine::uncache(const std::string &filePath)
{
itInfo->second.profileHelper->audioIDs.remove(audioID);
}
_audioIDInfoMap.erase(audioID);
_audioIDInfoMap.erase(itInfo);
}
}
_audioPathIDMap.erase(filePath);
}

if (_audioEngineImpl)
{
_audioEngineImpl->uncache(filePath);
}
_audioEngineImpl->uncache(filePath);
}

void AudioEngine::uncacheAll()
Expand Down
15 changes: 6 additions & 9 deletions cocos/audio/linux/AudioEngine-linux.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,6 @@ AudioEngineImpl::AudioEngineImpl()
AudioEngineImpl::~AudioEngineImpl()
{
FMOD_RESULT result;
result = pSystem->close();
ERRCHECKWITHEXIT(result);
result = pSystem->release();
ERRCHECKWITHEXIT(result);
}
Expand Down Expand Up @@ -109,7 +107,8 @@ int AudioEngineImpl::play2d(const std::string &fileFullPath, bool loop, float vo
int id = preload(fileFullPath, nullptr);
if (id >= 0) {
mapChannelInfo[id].loop=loop;
mapChannelInfo[id].channel->setPaused(true);
// channel is null here. Don't dereference it. It's only set in resume(id).
//mapChannelInfo[id].channel->setPaused(true);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a comment here

mapChannelInfo[id].volume = volume;
AudioEngine::_audioIDInfoMap[id].state = AudioEngine::AudioState::PAUSED;
resume(id);
Expand Down Expand Up @@ -287,8 +286,7 @@ void AudioEngineImpl::uncache(const std::string& path)
}
mapSound.erase(it);
}
if (mapId.find(path) != mapId.end())
mapId.erase(path);
mapId.erase(path);
}

void AudioEngineImpl::uncacheAll()
Expand Down Expand Up @@ -320,10 +318,9 @@ int AudioEngineImpl::preload(const std::string& filePath, std::function<void(boo
}

int id = static_cast<int>(mapChannelInfo.size()) + 1;
if (mapId.find(filePath) == mapId.end())
mapId.insert({filePath, id});
else
id = mapId.at(filePath);
// std::map::insert returns std::pair<iter, bool>
auto channelInfoIter = mapId.insert({filePath, id});
id = channelInfoIter.first->second;

auto& chanelInfo = mapChannelInfo[id];
chanelInfo.sound = sound;
Expand Down