@@ -258,56 +258,56 @@ export class AudioService {
258258 }
259259
260260 processNextOperation ( ) {
261- if ( this . sourceBuffer . updating || this . pendingOperations . length === 0 ) {
262- return ;
263- }
264-
265- // Don't process if audio is in error state
266- if ( this . audio . error ) {
267- console . warn ( "Skipping operation due to audio error" ) ;
268- return ;
269- }
270-
271- const operation = this . pendingOperations . shift ( ) ;
272-
273- try {
274- this . sourceBuffer . appendBuffer ( operation . chunk ) ;
275-
276- // Set up event listeners
277- const onUpdateEnd = ( ) => {
278- operation . resolve ( ) ;
279- this . sourceBuffer . removeEventListener ( "updateend" , onUpdateEnd ) ;
280- this . sourceBuffer . removeEventListener (
281- "updateerror" ,
282- onUpdateError
283- ) ;
284- // Process the next operation
285- this . processNextOperation ( ) ;
286- } ;
287-
288- const onUpdateError = ( event ) => {
289- operation . reject ( event ) ;
290- this . sourceBuffer . removeEventListener ( "updateend" , onUpdateEnd ) ;
291- this . sourceBuffer . removeEventListener (
292- "updateerror" ,
293- onUpdateError
294- ) ;
295- // Decide whether to continue processing
296- if ( event . name !== "InvalidStateError" ) {
297- this . processNextOperation ( ) ;
298- }
299- } ;
300-
301- this . sourceBuffer . addEventListener ( "updateend" , onUpdateEnd ) ;
302- this . sourceBuffer . addEventListener ( "updateerror" , onUpdateError ) ;
303- } catch ( error ) {
304- operation . reject ( error ) ;
305- // Only continue processing if it's not a fatal error
306- if ( error . name !== "InvalidStateError" ) {
307- this . processNextOperation ( ) ;
308- }
309- }
310- }
261+ if ( this . sourceBuffer . updating || this . pendingOperations . length === 0 ) {
262+ return ;
263+ }
264+
265+ // Don't process if audio is in error state
266+ if ( this . audio . error ) {
267+ console . warn ( "Skipping operation due to audio error" ) ;
268+ return ;
269+ }
270+
271+ const operation = this . pendingOperations . shift ( ) ;
272+
273+ try {
274+ this . sourceBuffer . appendBuffer ( operation . chunk ) ;
275+
276+ // Set up event listeners
277+ const onUpdateEnd = ( ) => {
278+ operation . resolve ( ) ;
279+ this . sourceBuffer . removeEventListener ( "updateend" , onUpdateEnd ) ;
280+ this . sourceBuffer . removeEventListener (
281+ "updateerror" ,
282+ onUpdateError
283+ ) ;
284+ // Process the next operation
285+ this . processNextOperation ( ) ;
286+ } ;
287+
288+ const onUpdateError = ( event ) => {
289+ operation . reject ( event ) ;
290+ this . sourceBuffer . removeEventListener ( "updateend" , onUpdateEnd ) ;
291+ this . sourceBuffer . removeEventListener (
292+ "updateerror" ,
293+ onUpdateError
294+ ) ;
295+ // Decide whether to continue processing
296+ if ( event . name !== "InvalidStateError" ) {
297+ this . processNextOperation ( ) ;
298+ }
299+ } ;
300+
301+ this . sourceBuffer . addEventListener ( "updateend" , onUpdateEnd ) ;
302+ this . sourceBuffer . addEventListener ( "updateerror" , onUpdateError ) ;
303+ } catch ( error ) {
304+ operation . reject ( error ) ;
305+ // Only continue processing if it's not a fatal error
306+ if ( error . name !== "InvalidStateError" ) {
307+ this . processNextOperation ( ) ;
308+ }
309+ }
310+ }
311311
312312 play ( ) {
313313 if ( this . audio && this . audio . readyState >= 2 && ! this . audio . error ) {
@@ -387,64 +387,64 @@ export class AudioService {
387387 }
388388
389389 cancel ( ) {
390- if ( this . controller ) {
391- this . controller . abort ( ) ;
392- this . controller = null ;
393- }
394-
395- if ( this . audio ) {
396- this . audio . pause ( ) ;
397- this . audio . src = "" ;
398- this . audio = null ;
399- }
400-
401- if ( this . mediaSource && this . mediaSource . readyState === "open" ) {
402- try {
403- this . mediaSource . endOfStream ( ) ;
404- } catch ( e ) {
405- // Ignore errors during cleanup
406- }
407- }
408-
409- this . mediaSource = null ;
410- if ( this . sourceBuffer ) {
411- this . sourceBuffer . removeEventListener ( "updateend" , ( ) => { } ) ;
412- this . sourceBuffer . removeEventListener ( "updateerror" , ( ) => { } ) ;
413- this . sourceBuffer = null ;
414- }
415- this . serverDownloadPath = null ;
416- this . pendingOperations = [ ] ;
390+ if ( this . controller ) {
391+ this . controller . abort ( ) ;
392+ this . controller = null ;
393+ }
394+
395+ if ( this . audio ) {
396+ this . audio . pause ( ) ;
397+ this . audio . src = "" ;
398+ this . audio = null ;
399+ }
400+
401+ if ( this . mediaSource && this . mediaSource . readyState === "open" ) {
402+ try {
403+ this . mediaSource . endOfStream ( ) ;
404+ } catch ( e ) {
405+ // Ignore errors during cleanup
406+ }
407+ }
408+
409+ this . mediaSource = null ;
410+ if ( this . sourceBuffer ) {
411+ this . sourceBuffer . removeEventListener ( "updateend" , ( ) => { } ) ;
412+ this . sourceBuffer . removeEventListener ( "updateerror" , ( ) => { } ) ;
413+ this . sourceBuffer = null ;
414+ }
415+ this . serverDownloadPath = null ;
416+ this . pendingOperations = [ ] ;
417417 }
418418
419419 cleanup ( ) {
420- if ( this . audio ) {
421- this . eventListeners . forEach ( ( listeners , event ) => {
422- listeners . forEach ( ( callback ) => {
423- this . audio . removeEventListener ( event , callback ) ;
424- } ) ;
425- } ) ;
426-
427- this . audio . pause ( ) ;
428- this . audio . src = "" ;
429- this . audio = null ;
430- }
431-
432- if ( this . mediaSource && this . mediaSource . readyState === "open" ) {
433- try {
434- this . mediaSource . endOfStream ( ) ;
435- } catch ( e ) {
436- // Ignore errors during cleanup
437- }
438- }
439-
440- this . mediaSource = null ;
441- if ( this . sourceBuffer ) {
442- this . sourceBuffer . removeEventListener ( "updateend" , ( ) => { } ) ;
443- this . sourceBuffer . removeEventListener ( "updateerror" , ( ) => { } ) ;
444- this . sourceBuffer = null ;
445- }
446- this . serverDownloadPath = null ;
447- this . pendingOperations = [ ] ;
420+ if ( this . audio ) {
421+ this . eventListeners . forEach ( ( listeners , event ) => {
422+ listeners . forEach ( ( callback ) => {
423+ this . audio . removeEventListener ( event , callback ) ;
424+ } ) ;
425+ } ) ;
426+
427+ this . audio . pause ( ) ;
428+ this . audio . src = "" ;
429+ this . audio = null ;
430+ }
431+
432+ if ( this . mediaSource && this . mediaSource . readyState === "open" ) {
433+ try {
434+ this . mediaSource . endOfStream ( ) ;
435+ } catch ( e ) {
436+ // Ignore errors during cleanup
437+ }
438+ }
439+
440+ this . mediaSource = null ;
441+ if ( this . sourceBuffer ) {
442+ this . sourceBuffer . removeEventListener ( "updateend" , ( ) => { } ) ;
443+ this . sourceBuffer . removeEventListener ( "updateerror" , ( ) => { } ) ;
444+ this . sourceBuffer = null ;
445+ }
446+ this . serverDownloadPath = null ;
447+ this . pendingOperations = [ ] ;
448448 }
449449
450450 getDownloadUrl ( ) {
0 commit comments