@@ -14,6 +14,7 @@ export interface ICoreOptions {
1414 playNextOnEnded ?: boolean ;
1515 audioGraph ?: IAudioGraph ;
1616 audioContext ?: IAudioContext ;
17+ stopOnReset ?: boolean ;
1718}
1819
1920export class PlayerCore {
@@ -42,6 +43,8 @@ export class PlayerCore {
4243 protected _customAudioGraph : IAudioGraph | null = null ;
4344 // a custom audio context created by the user
4445 protected _customAudioContext : IAudioContext | null = null ;
46+ // stop the song currently being played on (queue) reset
47+ protected _stopOnReset : boolean ;
4548
4649 // constants
4750 readonly WHERE_IN_QUEUE_AT_END : string = 'append' ;
@@ -60,7 +63,8 @@ export class PlayerCore {
6063 loopQueue : false ,
6164 soundsBaseUrl : '' ,
6265 playingProgressIntervalTime : 1000 ,
63- playNextOnEnded : true
66+ playNextOnEnded : true ,
67+ stopOnReset : true
6468 } ;
6569
6670 let options = Object . assign ( { } , defaultOptions , playerOptions ) ;
@@ -72,6 +76,7 @@ export class PlayerCore {
7276 this . _playingProgressIntervalTime = options . playingProgressIntervalTime ;
7377 this . _playNextOnEnded = options . playNextOnEnded ;
7478 this . _loopQueue = options . loopQueue ;
79+ this . _stopOnReset = options . stopOnReset ;
7580
7681 if ( typeof options . audioContext !== 'undefined' ) {
7782 this . _customAudioContext = options . audioContext ;
@@ -167,9 +172,22 @@ export class PlayerCore {
167172
168173 public resetQueue ( ) {
169174
175+ // check if a song is getting played and stop it
176+ if ( this . _stopOnReset ) {
177+
178+ this . stop ( ) ;
179+
180+ }
181+
182+ // TODO: destroy all the sounds or clear the cached buffers?
183+
170184 this . _queue = [ ] ;
171185
172- // TODO: check if a song is getting played and stop it?
186+ }
187+
188+ public reset ( ) {
189+
190+ this . resetQueue ( ) ;
173191
174192 }
175193
0 commit comments