diff --git a/src/nitro/sound/music/JukeboxPlaylistController.ts b/src/nitro/sound/music/JukeboxPlaylistController.ts index 4d310dfd..e1044840 100644 --- a/src/nitro/sound/music/JukeboxPlaylistController.ts +++ b/src/nitro/sound/music/JukeboxPlaylistController.ts @@ -106,7 +106,7 @@ export class JukeboxPlaylistController implements IPlaylistController for(let i = 0; i < this.length; i++) { const songData = this._entries[i]; - if(songData.id == songInfoEvent.id) + if(songData.id === songInfoEvent.id) { const diskId = songData.diskId; const updatedSongData = Nitro.instance.soundManager.musicController.getSongInfo(songInfoEvent.id); diff --git a/src/nitro/sound/music/MusicController.ts b/src/nitro/sound/music/MusicController.ts index 8fde79eb..2f3fc60d 100644 --- a/src/nitro/sound/music/MusicController.ts +++ b/src/nitro/sound/music/MusicController.ts @@ -120,9 +120,9 @@ export class MusicController implements IMusicController return _local_2; } - public getSongIdPlayingAtPriority(k: number): number + public getSongIdPlayingAtPriority(priority: number): number { - if(k != this._priorityPlaying) + if(priority !== this._priorityPlaying) { return -1; } @@ -232,9 +232,9 @@ export class MusicController implements IMusicController protected onTraxSongComplete(k:SoundManagerEvent):void { console.log((('Song ' + k.id) + ' finished playing')); - if(this.getSongIdPlayingAtPriority(this._priorityPlaying) == k.id) + if(this.getSongIdPlayingAtPriority(this._priorityPlaying) === k.id) { - if(((this.getTopRequestPriority() == this._priorityPlaying) && (this.getSongRequestCountAtPriority(this._priorityPlaying) == this._requestNumberPlaying))) + if(((this.getTopRequestPriority() === this._priorityPlaying) && (this.getSongRequestCountAtPriority(this._priorityPlaying) == this._requestNumberPlaying))) { this.resetSongStartRequest(this._priorityPlaying); } @@ -382,7 +382,7 @@ export class MusicController implements IMusicController private playSongObject(priority:number, songId:number):boolean { - if((((songId == -1) || (priority < 0)) || (priority >= MusicPriorities.PRIORITY_COUNT))) + if((((songId === -1) || (priority < 0)) || (priority >= MusicPriorities.PRIORITY_COUNT))) { return false; } @@ -400,7 +400,7 @@ export class MusicController implements IMusicController if(_local_3) { console.log(('Waiting previous song to stop before playing song ' + songId)); - //return true; + return true; } this._musicPlayer.setVolume(Nitro.instance.soundManager.traxVolume); let startPos = MusicController.SKIP_POSITION_SET; @@ -421,7 +421,6 @@ export class MusicController implements IMusicController } if(startPos >= (songData.length / 1000)) { - console.log('start position is too far'); return false; } if(startPos <= MusicController.SKIP_POSITION_SET) @@ -549,7 +548,7 @@ export class MusicController implements IMusicController private stopSongAtPriority(priority:number):boolean { - if(((priority == this._priorityPlaying) && (this._priorityPlaying >= 0))) + if(((priority === this._priorityPlaying) && (this._priorityPlaying >= 0))) { const songIdAtPriority = this.getSongIdPlayingAtPriority(priority); if(songIdAtPriority >= 0) @@ -558,7 +557,6 @@ export class MusicController implements IMusicController //this.stopSongDataEntry(_local_3); console.log('stopping song ' + songIdAtPriority); this._musicPlayer.stop(); - this._priorityPlaying = -1; // TODO: remove this; hack to fix blocking return true; } } diff --git a/src/nitro/sound/music/MusicPlayer.ts b/src/nitro/sound/music/MusicPlayer.ts index 64053bf9..862e560a 100644 --- a/src/nitro/sound/music/MusicPlayer.ts +++ b/src/nitro/sound/music/MusicPlayer.ts @@ -45,6 +45,21 @@ export class MusicPlayer this._tickerInterval = window.setInterval(() => this.tick(), 1000); } + private reset(): void + { + this._isPlaying = false; + window.clearInterval(this._tickerInterval); + + Howler.stop(); + this._currentSongId = -1; + this._currentSong = undefined; + this._tickerInterval = undefined; + this._startPos = 0; + this._playLength = 0; + this._sequence = []; + this._currentPos = 0; + } + public pause(): void { this._isPlaying = false; @@ -61,24 +76,12 @@ export class MusicPlayer public stop(): void { + const songId = this._currentSongId; this.reset(); + Nitro.instance.soundManager.events.dispatchEvent(new SoundManagerEvent(SoundManagerEvent.TRAX_SONG_COMPLETE, songId)); //this.emit('stopped'); } - private reset(): void - { - this._isPlaying = false; - clearInterval(this._tickerInterval); - - Howler.stop(); - - this._currentSong = undefined; - this._startPos = 0; - this._playLength = 0; - this._sequence = []; - this._currentPos = 0; - } - /** * Sets global howler volume for all sounds * @param volume value from 0.0 to 1.0 @@ -176,7 +179,6 @@ export class MusicPlayer { if(this._currentPos > this._playLength - 1) { - Nitro.instance.soundManager.events.dispatchEvent(new SoundManagerEvent(SoundManagerEvent.TRAX_SONG_COMPLETE, this._currentSongId)); this.stop(); }