comparison js/core.js @ 2616:ac08e4a3a94b

#101.Mostly done. Loads up alternatives if one of them fails, until end of URL lists
author Nicholas Jillings <nicholas.jillings@mail.bcu.ac.uk>
date Tue, 15 Nov 2016 15:31:53 +0000
parents 8b8f3f3ce68e
children cce1fb4009f2
comparison
equal deleted inserted replaced
2615:8b8f3f3ce68e 2616:ac08e4a3a94b
1486 // Create store for new audioObjects 1486 // Create store for new audioObjects
1487 this.audioObjects = []; 1487 this.audioObjects = [];
1488 1488
1489 this.buffers = []; 1489 this.buffers = [];
1490 this.bufferObj = function () { 1490 this.bufferObj = function () {
1491 var currentUrlIndex = 0;
1492 this.urls = []; 1491 this.urls = [];
1493 this.buffer = null; 1492 this.buffer = null;
1494 this.users = []; 1493 this.users = [];
1495 this.progress = 0; 1494 this.progress = 0;
1496 this.status = 0; 1495 this.status = 0;
1505 } 1504 }
1506 } 1505 }
1507 }; 1506 };
1508 this.getMedia = function (urls) { 1507 this.getMedia = function (urls) {
1509 var self = this; 1508 var self = this;
1509 var currentUrlIndex = 0;
1510 1510
1511 function get(fqurl) { 1511 function get(fqurl) {
1512 return new Promise(function (resolve, reject) { 1512 return new Promise(function (resolve, reject) {
1513 var req = new XMLHttpRequest(); 1513 var req = new XMLHttpRequest();
1514 req.open('GET', fqurl, true); 1514 req.open('GET', fqurl, true);
1528 } 1528 }
1529 1529
1530 function getNextURL() { 1530 function getNextURL() {
1531 currentUrlIndex++; 1531 currentUrlIndex++;
1532 var self = this; 1532 var self = this;
1533 if (currentURLIndex == this.urls.length) { 1533 if (currentUrlIndex == this.urls.length) {
1534 processError(); 1534 processError();
1535 } else { 1535 } else {
1536 return get(this.urls[currentUrlIndex]).then(processAudio.bind(self)).catch(getNextURL.bind(self)); 1536 return get(this.urls[currentUrlIndex]).then(processAudio.bind(self)).catch(getNextURL.bind(self));
1537 } 1537 }
1538 } 1538 }
1591 } 1591 }
1592 } 1592 }
1593 }; 1593 };
1594 1594
1595 this.urls = urls; 1595 this.urls = urls;
1596 currentUrlIndex = 0;
1597 1596
1598 this.progress = 0; 1597 this.progress = 0;
1599 this.status = 1; 1598 this.status = 1;
1600 get(this.urls[currentUrlIndex]).then(processAudio.bind(self)).catch(getNextURL.bind(self)); 1599 get(this.urls[currentUrlIndex]).then(processAudio.bind(self)).catch(getNextURL.bind(self));
1601 }; 1600 };