Skip to content

Commit 86562fe

Browse files
committed
fix music to not redownload and attempt to loop on Wasm
1 parent aed96b1 commit 86562fe

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

src/media/MusicManager.cpp

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,28 @@ void MusicManager::playMusic(const QString &musicFile)
118118
}
119119

120120
if constexpr (CURRENT_PLATFORM == PlatformEnum::Wasm) {
121-
m_library.fetchAsync(musicFile, [this, musicFile](const QByteArray &data) {
122-
playFromData(data, musicFile);
123-
});
121+
const int inactiveChannelIndex = (m_activeChannel + 1) % 2;
122+
if (musicFile == m_channels[m_activeChannel].file) {
123+
if (m_channels[m_activeChannel].player->playbackState() != QMediaPlayer::PlayingState) {
124+
m_channels[m_activeChannel].player->play();
125+
}
126+
} else if (musicFile == m_channels[inactiveChannelIndex].file) {
127+
// Found the track in the inactive channel; swap to it
128+
m_activeChannel = inactiveChannelIndex;
129+
auto &active = m_channels[m_activeChannel];
130+
if (active.player->playbackState() != QMediaPlayer::PlayingState) {
131+
if (qint64 *pos = m_cachedPositions.object(musicFile)) {
132+
active.pendingPosition = *pos;
133+
}
134+
active.player->play();
135+
applyPendingPosition(m_activeChannel);
136+
}
137+
startFade(false);
138+
} else {
139+
m_library.fetchAsync(musicFile, [this, musicFile](const QByteArray &data) {
140+
playFromData(data, musicFile);
141+
});
142+
}
124143
} else {
125144
#ifndef MMAPPER_NO_AUDIO
126145
const int ch = prepareChannel(musicFile);

0 commit comments

Comments
 (0)