@@ -265,17 +265,11 @@ WebAudio.prototype.clear = function() {
265
265
this . _sourceNode = null ;
266
266
this . _gainNode = null ;
267
267
this . _pannerNode = null ;
268
- this . _partialArray = null ;
269
- this . _wholeArray = null ;
270
- this . _chunkGainRate = 5 ;
271
- this . _chunkSize = 75 * 1024 ;
272
- this . _loadedSize = 0 ;
273
268
this . _totalTime = 0 ;
274
269
this . _sampleRate = 0 ;
275
270
this . _loopStart = 0 ;
276
271
this . _loopLength = 0 ;
277
272
this . _startTime = 0 ;
278
- this . _offset = 0 ;
279
273
this . _volume = 1 ;
280
274
this . _pitch = 1 ;
281
275
this . _pan = 0 ;
@@ -363,7 +357,7 @@ Object.defineProperty(WebAudio.prototype, 'pan', {
363
357
* @return {Boolean } True if the audio data is ready to play
364
358
*/
365
359
WebAudio . prototype . isReady = function ( ) {
366
- return ! ! this . _buffer && this . _buffer . duration >= this . _offset ;
360
+ return ! ! this . _buffer ;
367
361
} ;
368
362
369
363
/**
@@ -394,8 +388,8 @@ WebAudio.prototype.isPlaying = function() {
394
388
* @param {Number } offset The start position to play in seconds
395
389
*/
396
390
WebAudio . prototype . play = function ( loop , offset ) {
397
- this . _offset = offset = offset || 0 ;
398
391
if ( this . isReady ( ) ) {
392
+ offset = offset || 0 ;
399
393
this . _startPlaying ( loop , offset ) ;
400
394
} else if ( WebAudio . _context ) {
401
395
this . _autoPlay = true ;
@@ -510,9 +504,6 @@ WebAudio.prototype._load = function(url) {
510
504
var xhr = new XMLHttpRequest ( ) ;
511
505
if ( Decrypter . hasEncryptedAudio ) url = Decrypter . extToEncryptExt ( url ) ;
512
506
xhr . open ( 'GET' , url ) ;
513
- if ( typeof require === 'undefined' ) {
514
- xhr . setRequestHeader ( 'Range' , 'bytes=' + this . _loadedSize + '-' + ( this . _loadedSize + this . _chunkSize - 1 ) ) ;
515
- }
516
507
xhr . responseType = 'arraybuffer' ;
517
508
xhr . onload = function ( ) {
518
509
if ( xhr . status < 400 ) {
@@ -530,89 +521,21 @@ WebAudio.prototype._load = function(url) {
530
521
* @private
531
522
*/
532
523
WebAudio . prototype . _onXhrLoad = function ( xhr ) {
533
- if ( xhr . status === 206 ) {
534
- this . _onPartialLoad ( xhr ) ;
535
- } else {
536
- this . _onWholeLoad ( xhr . response ) ;
537
- }
538
- } ;
539
-
540
- /**
541
- * @method _onPartialLoad
542
- * @param {XMLHttpRequest } xhr
543
- * @private
544
- */
545
- WebAudio . prototype . _onPartialLoad = function ( xhr ) {
546
524
var array = xhr . response ;
547
- if ( ! this . _partialArray ) {
548
- this . _partialArray = new Uint8Array ( + xhr . getResponseHeader ( 'Content-Range' ) . split ( '/' ) . pop ( ) ) ;
549
- this . _chunkSize *= this . _chunkGainRate - 1 ;
550
- } else {
551
- this . _chunkSize = this . _partialArray . byteLength ;
552
- }
553
- this . _partialArray . set ( new Uint8Array ( array ) , this . _loadedSize ) ;
554
- this . _loadedSize += array . byteLength ;
555
- if ( this . _loadedSize < this . _partialArray . byteLength ) {
556
- array = this . _partialArray . buffer . slice ( 0 , this . _loadedSize ) ;
557
- this . _load ( this . _url ) ;
558
- } else {
559
- array = this . _partialArray . buffer ;
560
- this . _partialArray = null ;
561
- }
562
- if ( Decrypter . hasEncryptedAudio ) {
563
- array = Decrypter . decryptArrayBuffer ( array ) ;
564
- }
525
+ if ( Decrypter . hasEncryptedAudio ) array = Decrypter . decryptArrayBuffer ( array ) ;
565
526
this . _readLoopComments ( new Uint8Array ( array ) ) ;
566
- WebAudio . _context . decodeAudioData ( array , this . _onDecode . bind ( this ) ) ;
567
- } ;
568
-
569
- /**
570
- * @method _onWholeLoad
571
- * @param {ArrayBuffer } array
572
- * @private
573
- */
574
- WebAudio . prototype . _onWholeLoad = function ( array ) {
575
- if ( array ) {
576
- if ( Decrypter . hasEncryptedAudio ) {
577
- array = Decrypter . decryptArrayBuffer ( array ) ;
578
- }
579
- this . _readLoopComments ( new Uint8Array ( array ) ) ;
580
- if ( this . _chunkSize < array . byteLength ) {
581
- this . _wholeArray = array ;
582
- array = this . _wholeArray . slice ( 0 , this . _chunkSize ) ;
583
- this . _chunkSize *= this . _chunkGainRate ;
584
- }
585
- } else if ( this . _chunkSize < this . _wholeArray . byteLength ) {
586
- array = this . _wholeArray . slice ( 0 , this . _chunkSize ) ;
587
- this . _chunkSize = this . _wholeArray . byteLength ;
588
- } else {
589
- array = this . _wholeArray ;
590
- this . _wholeArray = null ;
591
- }
592
- WebAudio . _context . decodeAudioData ( array , this . _onDecode . bind ( this ) , function ( ) {
593
- this . _onWholeLoad ( ) ;
594
- } . bind ( this ) ) ;
595
- } ;
596
-
597
- /**
598
- * @method _onDecode
599
- * @param {AudioBuffer } buffer
600
- * @private
601
- */
602
- WebAudio . prototype . _onDecode = function ( buffer ) {
603
- if ( ! this . _buffer || this . _buffer . length < buffer . length ) {
527
+ WebAudio . _context . decodeAudioData ( array , function ( buffer ) {
604
528
this . _buffer = buffer ;
605
529
this . _totalTime = buffer . duration ;
606
- if ( this . isPlaying ( ) ) {
607
- this . _startPlaying ( this . _sourceNode . loop , this . seek ( ) ) ;
608
- }
609
- if ( this . isReady ( ) ) {
610
- this . _onLoad ( ) ;
611
- }
612
- if ( this . _wholeArray ) {
613
- this . _onWholeLoad ( ) ;
530
+ if ( this . _loopLength > 0 && this . _sampleRate > 0 ) {
531
+ this . _loopStart /= this . _sampleRate ;
532
+ this . _loopLength /= this . _sampleRate ;
533
+ } else {
534
+ this . _loopStart = 0 ;
535
+ this . _loopLength = this . _totalTime ;
614
536
}
615
- }
537
+ this . _onLoad ( ) ;
538
+ } . bind ( this ) ) ;
616
539
} ;
617
540
618
541
/**
@@ -645,10 +568,8 @@ WebAudio.prototype._createNodes = function() {
645
568
var context = WebAudio . _context ;
646
569
this . _sourceNode = context . createBufferSource ( ) ;
647
570
this . _sourceNode . buffer = this . _buffer ;
648
- if ( this . _buffer . duration > this . _loopStart ) {
649
- this . _sourceNode . loopStart = this . _loopStart ;
650
- this . _sourceNode . loopEnd = this . _loopStart + this . _loopLength ;
651
- }
571
+ this . _sourceNode . loopStart = this . _loopStart ;
572
+ this . _sourceNode . loopEnd = this . _loopStart + this . _loopLength ;
652
573
this . _sourceNode . playbackRate . setValueAtTime ( this . _pitch , context . currentTime ) ;
653
574
this . _gainNode = context . createGain ( ) ;
654
575
this . _gainNode . gain . setValueAtTime ( this . _volume , context . currentTime ) ;
@@ -734,14 +655,8 @@ WebAudio.prototype._onLoad = function() {
734
655
* @private
735
656
*/
736
657
WebAudio . prototype . _readLoopComments = function ( array ) {
737
- if ( this . _sampleRate === 0 ) {
738
- this . _readOgg ( array ) ;
739
- this . _readMp4 ( array ) ;
740
- if ( this . _loopLength > 0 && this . _sampleRate > 0 ) {
741
- this . _loopStart /= this . _sampleRate ;
742
- this . _loopLength /= this . _sampleRate ;
743
- }
744
- }
658
+ this . _readOgg ( array ) ;
659
+ this . _readMp4 ( array ) ;
745
660
} ;
746
661
747
662
/**
0 commit comments