Fixed non-immediate visualizer update router.
This commit is contained in:
parent
97329f0202
commit
fda4b13268
@ -3,7 +3,7 @@ import VisUpdateRouter from "../visualization/VisUpdateRouter.js";
|
||||
import MusicPlayer from "./MusicPlayer.js";
|
||||
import MusicPlaylist from "./MusicPlaylist.js";
|
||||
|
||||
/**@module */
|
||||
|
||||
|
||||
/**
|
||||
* A music player that provides easier access to the current musics visualizer data.
|
||||
@ -25,14 +25,19 @@ export default class VisMusicPlayer extends MusicPlayer {
|
||||
super(playlist);
|
||||
playlist.addPositionChangeListener(this.#onMusicChange); // First time only: after setting the playlist, add the listener.
|
||||
this.#fftSize = fftSize;
|
||||
this.#visUpdateRouter = new VisUpdateRouter(fftSize);
|
||||
this.playlist.currentPosition = 0;
|
||||
}
|
||||
|
||||
#onMusicChange = () => {
|
||||
const visUpdateRouterListeners = this.#visUpdateRouter.retrieveListeners();
|
||||
let visUpdateRouterListeners = null;
|
||||
if (this.#visUpdateRouter) {
|
||||
visUpdateRouterListeners = this.#visUpdateRouter.retrieveListeners();
|
||||
this.#visUpdateRouter.unbindVisualizer();
|
||||
}
|
||||
this.#visUpdateRouter = new VisUpdateRouter(this.currentMusicVisualizer);
|
||||
if (visUpdateRouterListeners) {
|
||||
this.#visUpdateRouter.loadListeners(visUpdateRouterListeners);
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -109,7 +109,7 @@ export default class Visualizer {
|
||||
* @returns {number} The number of bins based on the size of the FFT window.
|
||||
*/
|
||||
get numberOfBins() {
|
||||
return this.#buffer.length;
|
||||
return this.#fftSize / 2;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user