this.ttsChunks = data;
this.ttsHilites = [];
- //deal with first page being blank
+ //deal with the page being blank
if (0 == data.length) {
console.log('first page is blank!');
if(this.ttsAdvance(true)) {
// ttsNextChunk()
//______________________________________________________________________________
+// I've split this function into two parts: ttsNextChunk and ttsNextChunkPhase2.
+// This is to make the 2-page flip behavior nicer, but makes the code much
+// more complicated.
+// If a page flip is necessary, ttsAdvance() will return false so Phase2 isn't
+// called. Instead, this.animationFinishedCallback is set, so that Phase2
+// continues after animation is finished.
+
BookReader.prototype.ttsNextChunk = function () {
console.log(this);
console.log(this.ttsPosition);
if (-1 != this.ttsPosition) {
soundManager.destroySound('chunk'+this.ttsIndex+'-'+this.ttsPosition);
}
-
-
+
+ //remove old hilights
+ $(this.ttsHilites).remove();
+ this.ttsHilites = [];
+
var moreToPlay = this.ttsAdvance();
- if (!moreToPlay) return;
+ if (moreToPlay) {
+ this.ttsNextChunkPhase2();
+ }
+
+ //This function is called again when ttsPlay() has finished playback.
+ //If the next chunk of text has not yet finished loading, ttsPlay()
+ //will start polling until the next chunk is ready.
+}
+
+// ttsNextChunkPhase2()
+//______________________________________________________________________________
+// page flip animation has now completed
+BookReader.prototype.ttsNextChunkPhase2 = function () {
+ if (0 == this.ttsChunks.length) {
+ console.log('ttsNextChunk2: ttsChunks.length is zero.. hacking...');
+ this.ttsStartCB(this.ttsChunks);
+ return;
+ }
console.log('next chunk is ');
console.log(this.ttsPosition);
this.ttsPrefetchAudio();
this.ttsPlay();
-
}
// ttsAdvance()
this.ttsChunks = this.ttsNextChunks;
this.ttsNextChunks = null;
if ((this.ttsIndex != this.twoPage.currentIndexL) && (this.ttsIndex != this.twoPage.currentIndexR)) {
+ this.animationFinishedCallback = this.ttsNextChunkPhase2;
this.next();
+ return false;
+ } else {
+ return true;
}
- return true;
} else {
- console.log('ttsNextChunks is null');
+ console.log('ttsAdvance: ttsNextChunks is null');
return false;
}
}
console.log('preloading chunk 0 from next page, index='+(this.ttsIndex+1))
if (null != this.ttsNextChunks) {
console.log(this.ttsNextChunks);
- this.ttsLoadChunk(this.ttsIndex+1, 0, this.ttsNextChunks[0][0]);
+ if (0 != this.ttsNextChunks.length) {
+ this.ttsLoadChunk(this.ttsIndex+1, 0, this.ttsNextChunks[0][0]);
+ } else {
+ console.log('prefetchAudio(): ttsNextChunks is zero length!');
+ }
} else {
console.log('ttsNextChunks is null, not preloading next page');
this.ttsBuffering = true;
console.log('chunk = ' + chunk);
console.log(this.ttsChunks);
- //remove old hilights
- $(this.ttsHilites).remove();
- this.ttsHilites = [];
-
//add new hilights
if (2 == this.mode) {
this.ttsHilite2UP(chunk);