convert segmentXHR to use xhr helper
Showing
1 changed file
with
10 additions
and
16 deletions
... | @@ -639,31 +639,24 @@ var | ... | @@ -639,31 +639,24 @@ var |
639 | } | 639 | } |
640 | 640 | ||
641 | // request the next segment | 641 | // request the next segment |
642 | segmentXhr = new window.XMLHttpRequest(); | 642 | segmentXhr = xhr({ |
643 | segmentXhr.open('GET', segmentUri); | 643 | url: segmentUri, |
644 | segmentXhr.responseType = 'arraybuffer'; | 644 | responseType: 'arraybuffer' |
645 | segmentXhr.onreadystatechange = function() { | 645 | }, function(error, url) { |
646 | // wait until the request completes | ||
647 | if (this.readyState !== 4) { | ||
648 | return; | ||
649 | } | ||
650 | |||
651 | // the segment request is no longer outstanding | 646 | // the segment request is no longer outstanding |
652 | segmentXhr = null; | 647 | segmentXhr = null; |
653 | 648 | ||
654 | // trigger an error if the request was not successful | 649 | if (error) { |
655 | if (this.status >= 400) { | ||
656 | player.hls.error = { | 650 | player.hls.error = { |
657 | status: this.status, | 651 | status: this.status, |
658 | message: 'HLS segment request error at URL: ' + segmentUri, | 652 | message: 'HLS segment request error at URL: ' + url, |
659 | code: (this.status >= 500) ? 4 : 2 | 653 | code: (this.status >= 500) ? 4 : 2 |
660 | }; | 654 | }; |
661 | 655 | ||
662 | // try moving on to the next segment | 656 | // try moving on to the next segment |
663 | player.hls.mediaIndex++; | 657 | player.hls.mediaIndex++; |
664 | return; | 658 | return; |
665 | } | 659 | } else { |
666 | |||
667 | // stop processing if the request was aborted | 660 | // stop processing if the request was aborted |
668 | if (!this.response) { | 661 | if (!this.response) { |
669 | return; | 662 | return; |
... | @@ -698,9 +691,10 @@ var | ... | @@ -698,9 +691,10 @@ var |
698 | // figure out what stream the next segment should be downloaded from | 691 | // figure out what stream the next segment should be downloaded from |
699 | // with the updated bandwidth information | 692 | // with the updated bandwidth information |
700 | updateCurrentPlaylist(); | 693 | updateCurrentPlaylist(); |
701 | }; | 694 | } |
695 | }); | ||
696 | |||
702 | startTime = +new Date(); | 697 | startTime = +new Date(); |
703 | segmentXhr.send(null); | ||
704 | }; | 698 | }; |
705 | 699 | ||
706 | // load the MediaSource into the player | 700 | // load the MediaSource into the player | ... | ... |
-
Please register or sign in to post a comment