MZ Music changes when region changes

Can someone with java knowledge help me with the functionality of this script? Currently it captures the assigned music for a region at the time and place a character enters the map, but I would like it to update - to switch to a new music track when a different designated region is entered. I am thinking a parallel process check (loop) with a wait time would work but not sure how to implement. Right now, it functions at the time of map entry only. A map properties note entry looks like:

<bgm12: Song1> .... where 12 is the region and Song1 is the filename of the BGM without extension

Code:
Game_Map.prototype.autoplay = function() {
    if($gamePlayer.regionId() && $dataMap.meta["bgm" + $gamePlayer.regionId()]) {
        var dataBgm = $dataMap.meta["bgm" + $gamePlayer.regionId()].trim().split(" ");
        var bgm = {
            name: (dataBgm[0] === "Null" ? "" : dataBgm[0]),
          volume: (dataBgm[1] === undefined ? $dataMap.bgm.volume : parseInt(dataBgm[1], 10)),
             pan: (dataBgm[2] === undefined ? $dataMap.bgm.pan : parseInt(dataBgm[2], 10)),
           pitch: (dataBgm[3] === undefined ? $dataMap.bgm.pitch : parseInt(dataBgm[3], 10))


        };
        AudioManager.playBgm(bgm);
    } else if($dataMap.autoplayBgm) {
        AudioManager.playBgm($dataMap.bgm);
 
    }
};
Hmmm, you could just have a parallel (common)event running with like (don't leave an empty space after colon in your notetag):

const meta = "bgm" + $gamePlayer.regionId().toString();
if ($dataMap.meta[meta]){
const song = $dataMap.meta[meta];
AudioManager.playBgm({ name: song, volume: 100, pitch: 100 });
} else {
AudioManager.playBgm($dataMap.bgm);
}

Original thread: https://forums.rpgmakerweb.com/threads/music-changes-when-region-changes.179962/