Seamless audio transition from file to file?

I have 2 exactly same bgm files, the only difference is that one is muffled, and the other is not. I set one in the main room where bgs is played, and muffled one in another, so you can hear bgm played from afar. The problem i face that if i move between locations, bgm starts from the beginning. Is there a way to make it start from the same spot, considering that both files have identical timings?
Which is it, bgm or bgs?

If you set an autoplay bgm on one map and leave the next map's bgm entry blank, the music will simply continue when you go between them.
BGM.

I know it will continue, but i want it to switch to different track, at the same timing as it was when you leave first map.

So like i leave first map with track1 2:13, and on second map it starts track2, 2:13
Maybe this will work? Run this script call below your map transfer command:
JavaScript:
AudioManager._currentBgm.name = 'fileName';

I have a feeling it might not work as intended since it has to buffer the audio, but it doesn't hurt to try.

You might be able use "AudioManager._currentBgm.pos" to get the position of the first BGM playing and then use this script call (Also at the end of your transfer player event command):
JavaScript:
let p = AudioManager._currentBgm.pos;
AudioManager.playBgm({
    name: 'fileName',
    volume: 50,
    pitch: 100,
    pan: 0,
    pos: p
});

Haven't tested it so check and change as necessary. You may need to put a wait command after the transfer player but it should be okay, I think.

Possible issues:
My guess at the moment is possible buffering issues that may arise.

I haven't tested the AudioManager.bgmbuffer() function to know what is really does so you may want to check that out as well.

Edit: you might be able to find a plugin that can lower the volume and filter your audio to make it muffled and distant. Otherwise, you can look into the WebAudio API and derive something useful there using the filter commands.
Maybe this will work? Run this script call below your map transfer command:
JavaScript:
AudioManager._currentBgm.name = 'fileName';

I have a feeling it might not work as intended since it has to buffer the audio, but it doesn't hurt to try.

You might be able use "AudioManager._currentBgm.pos" to get the position of the first BGM playing and then use this script call (Also at the end of your transfer player event command):
JavaScript:
let p = AudioManager._currentBgm.pos;
AudioManager.playBgm({
    name: 'fileName',
    volume: 50,
    pitch: 100,
    pan: 0,
    pos: p
});

Haven't tested it so check and change as necessary. You may need to put a wait command after the transfer player but it should be okay, I think.

Possible issues:
My guess at the moment is possible buffering issues that may arise.

I haven't tested the AudioManager.bgmbuffer() function to know what is really does so you may want to check that out as well.

Edit: you might be able to find a plugin that can lower the volume and filter your audio to make it muffled and distant. Otherwise, you can look into the WebAudio API and derive something useful there using the filter commands.
First script not doing anything, second - block-scoped declarations (left, const, functions, class) not yet supported outside strict mode

And sadly i don't know plugins that would apply good muffling, especially on already playing track.
First script not doing anything, second - block-scoped declarations (left, const, functions, class) not yet supported outside strict mode

And sadly i don't know plugins that would apply good muffling, especially on already playing track.
Just to rule this out, you changed 'fileName' to your actual file name, correct?

JavaScript:
AudioManager._currentBgm.name = 'track2'

As for other second one, try a game variable instead (I use 1 here but you can use which ever game variable you want):
JavaScript:
$gameVariables.setValue(1, AudioManager._currentBgm.pos);
AudioManager.playBgm({
    name: 'track2',
    volume: 50,
    pitch: 100,
    pan: 0,
    pos: $gameVariables.value(1)
});
Just to rule this out, you changed 'fileName' to your actual file name, correct?

JavaScript:
AudioManager._currentBgm.name = 'track2'

As for other second one, try a game variable instead (I use 1 here but you can use which ever game variable you want):
JavaScript:
$gameVariables.setValue(1, AudioManager._currentBgm.pos);
AudioManager.playBgm({
    name: 'track2',
    volume: 50,
    pitch: 100,
    pan: 0,
    pos: $gameVariables.value(1)
});
Yes, i did. I only was not sure if i have to include file format.
This option changes the track, but it starts from the beginning.
Yes, i did. I only was not sure if i have to include file format.
This option changes the track, but it starts from the beginning.
It might be too fast loading it all at once (and I think there is a buffer delay). Could you separate the last script into two script calls?
JavaScript:
$gameVariables.setValue(1, AudioManager._currentBgm.pos);
Then:
JavaScript:
AudioManager.playBgm({
    name: 'track2',
    volume: 50,
    pitch: 100,
    pan: 0,
    pos: $gameVariables.value(1)
});
Still starts track from the beginning in new zone.
Still starts track from the beginning in new zone.
Is it at least assigning a value other than 0 in game variable 1?

Edit:
One more attempt:

JavaScript:
$gameVariables.setValue(1, AudioManager._currentBgm.pos);

Then:

JavaScript:
AudioManager.playBgm({
    name: 'track2',
    volume: 50,
    pitch: 100,
    pan: 0
}, $gameVariables.value(1));
Edit:
One more attempt:
You don't need to start using game variables - you just had the wrong format for the function arguments in your first post.

You corrected the format here, you don't also need to use up game variables (not that you need any variable).

Code:
AudioManager.playBgm({
    name: 'filename',
    volume: 50,
    pitch: 100,
    pan: 0},
    AudioManager._currentBgm.pos);
You don't need to start using game variables - you just had the wrong format for the function arguments in your first post.

You corrected the format here, you don't also need to use up game variables (not that you need any variable).

Code:
AudioManager.playBgm({
    name: 'filename',
    volume: 50,
    pitch: 100,
    pan: 0},
    AudioManager._currentBgm.pos);
Thanks @ATT_Turan for clearing it up! I really need to get a laptop while I'm out of town haha. It makes sense - I wasn't sure if it was updating too fast or if ._currentBgm would immediately take the new bgm being played so I used the variable - you are correct.
I wasn't sure if it was updating too fast or if ._currentBgm would immediately take the new bgm being played.
You're passing it in as an argument, there's no way it could be supplying values that don't exist until after the function you're passing it into has run.

The problem with the first post was simply that you'd included the pos as a part of the bgm struct, when it's the second discrete argument for the playBgm() method.
That makes sense now, just couldnt wrap my head around it at the moment haha!

Yeah, I checked it again and realized later that the playBgm() function had two parameters (bgm, pos).
Sadly even this starts the song anew. I included the screenshot in case that i might do something wrong.
d.jpg
Hmmm, do you have to put the line

AudioManager._bgmBuffer.seek()

there? That's what it uses to save the bgm pos.
Hmmm, do you have to put the line

AudioManager._bgmBuffer.seek()

there? That's what it uses to save the bgm pos.
Where exactly should i put it? Before the code on screenshot above, after, or add it to that code (if so, where?)?
JavaScript:
AudioManager.playBgm({
    name: 'disco11',
    volume: 50,
    pitch: 100,
    pan: 0
}, AudioManager._bgmBuffer.seek());
Looks like it's finally working! Amazing, thanks so much everyone! Your knowledge allows me to implement cool things that i could not make on my own.
Hey! I started using this script however I wanna ask if its common to have that in the start of the song or the transition, there is a couple seconds of nothing and then starts late. For example the script call will be called but the song will start a couple seconds after but it starts not from the very start, but from the equivalent of seconds that passed since the call.

Same with the transition, sometimes it goes fully silent for some seconds and then goes back. I checked if maybe it was my pc being slow but no, its not making my pc go slower or anything, nor is the game itself freezing. Why could this be?

Original thread: https://forums.rpgmakerweb.com/threads/seamless-audio-transition-from-file-to-file.165784/