File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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);
You can’t perform that action at this time.
0 commit comments