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++) for(let i = 0; i < this.length; i++)
{ {
const songData = this._entries[i]; const songData = this._entries[i];
if(songData.id == songInfoEvent.id) if(songData.id === songInfoEvent.id)
{ {
const diskId = songData.diskId; const diskId = songData.diskId;
const updatedSongData = Nitro.instance.soundManager.musicController.getSongInfo(songInfoEvent.id); const updatedSongData = Nitro.instance.soundManager.musicController.getSongInfo(songInfoEvent.id);

View File

@ -120,9 +120,9 @@ export class MusicController implements IMusicController
return _local_2; return _local_2;
} }
public getSongIdPlayingAtPriority(k: number): number public getSongIdPlayingAtPriority(priority: number): number
{ {
if(k != this._priorityPlaying) if(priority !== this._priorityPlaying)
{ {
return -1; return -1;
} }
@ -232,9 +232,9 @@ export class MusicController implements IMusicController
protected onTraxSongComplete(k:SoundManagerEvent):void protected onTraxSongComplete(k:SoundManagerEvent):void
{ {
console.log((('Song ' + k.id) + ' finished playing')); 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); this.resetSongStartRequest(this._priorityPlaying);
} }
@ -382,7 +382,7 @@ export class MusicController implements IMusicController
private playSongObject(priority:number, songId:number):boolean 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; return false;
} }
@ -400,7 +400,7 @@ export class MusicController implements IMusicController
if(_local_3) if(_local_3)
{ {
console.log(('Waiting previous song to stop before playing song ' + songId)); console.log(('Waiting previous song to stop before playing song ' + songId));
//return true; return true;
} }
this._musicPlayer.setVolume(Nitro.instance.soundManager.traxVolume); this._musicPlayer.setVolume(Nitro.instance.soundManager.traxVolume);
let startPos = MusicController.SKIP_POSITION_SET; let startPos = MusicController.SKIP_POSITION_SET;
@ -421,7 +421,6 @@ export class MusicController implements IMusicController
} }
if(startPos >= (songData.length / 1000)) if(startPos >= (songData.length / 1000))
{ {
console.log('start position is too far');
return false; return false;
} }
if(startPos <= MusicController.SKIP_POSITION_SET) if(startPos <= MusicController.SKIP_POSITION_SET)
@ -549,7 +548,7 @@ export class MusicController implements IMusicController
private stopSongAtPriority(priority:number):boolean private stopSongAtPriority(priority:number):boolean
{ {
if(((priority == this._priorityPlaying) && (this._priorityPlaying >= 0))) if(((priority === this._priorityPlaying) && (this._priorityPlaying >= 0)))
{ {
const songIdAtPriority = this.getSongIdPlayingAtPriority(priority); const songIdAtPriority = this.getSongIdPlayingAtPriority(priority);
if(songIdAtPriority >= 0) if(songIdAtPriority >= 0)
@ -558,7 +557,6 @@ export class MusicController implements IMusicController
//this.stopSongDataEntry(_local_3); //this.stopSongDataEntry(_local_3);
console.log('stopping song ' + songIdAtPriority); console.log('stopping song ' + songIdAtPriority);
this._musicPlayer.stop(); this._musicPlayer.stop();
this._priorityPlaying = -1; // TODO: remove this; hack to fix blocking
return true; return true;
} }
} }

View File

@ -45,6 +45,21 @@ export class MusicPlayer
this._tickerInterval = window.setInterval(() => this.tick(), 1000); 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 public pause(): void
{ {
this._isPlaying = false; this._isPlaying = false;
@ -61,24 +76,12 @@ export class MusicPlayer
public stop(): void public stop(): void
{ {
const songId = this._currentSongId;
this.reset(); this.reset();
Nitro.instance.soundManager.events.dispatchEvent(new SoundManagerEvent(SoundManagerEvent.TRAX_SONG_COMPLETE, songId));
//this.emit('stopped'); //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 * Sets global howler volume for all sounds
* @param volume value from 0.0 to 1.0 * @param volume value from 0.0 to 1.0
@ -176,7 +179,6 @@ export class MusicPlayer
{ {
if(this._currentPos > this._playLength - 1) if(this._currentPos > this._playLength - 1)
{ {
Nitro.instance.soundManager.events.dispatchEvent(new SoundManagerEvent(SoundManagerEvent.TRAX_SONG_COMPLETE, this._currentSongId));
this.stop(); this.stop();
} }