fix priority playing and songend event

This commit is contained in:
dank074 2022-11-12 23:15:49 -06:00
parent 3086a8446f
commit 2dd8d9d399
3 changed files with 25 additions and 25 deletions

View File

@ -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);

View File

@ -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;
}
}

View File

@ -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();
}