Skip to content

Commit

Permalink
Merge pull request #461 from baconz/master
Browse files Browse the repository at this point in the history
Consider empty text cues buffered
  • Loading branch information
joeyparrish committed Jul 26, 2016
2 parents 1c4d7bb + 89e3548 commit 022226c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 5 deletions.
7 changes: 2 additions & 5 deletions lib/media/text_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,10 @@ shaka.media.TextEngine.prototype.appendBuffer =
// Parse the buffer and add the new cues.
var cues = this.parser_(buffer, startTime, endTime);

if (!cues.length) {
// Init segments have no cues and no times.
if (startTime == null || endTime == null) {
// Init segments will not have start/end times passed
return;
}
// If cues were parsed, startTime and endTime should be non-null.
goog.asserts.assert(startTime != null && endTime != null,
'start and end times should be non-null!');

for (var i = 0; i < cues.length; ++i) {
cues[i].startTime += offset;
Expand Down
16 changes: 16 additions & 0 deletions test/media/text_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ describe('TextEngine', function() {
expect(mockTrack.addCue).not.toHaveBeenCalled();
});

it('considers empty cues buffered', function(done) {
mockParser.and.returnValue([]);

textEngine.appendBuffer(dummyData, 0, 3).then(function() {
expect(mockParser).toHaveBeenCalledWith(dummyData, 0, 3);
expect(mockTrack.addCue).not.toHaveBeenCalled();
expect(mockTrack.removeCue).not.toHaveBeenCalled();

expect(textEngine.bufferStart()).toBe(0);
expect(textEngine.bufferEnd()).toBe(3);

mockTrack.addCue.calls.reset();
mockParser.calls.reset();
}).catch(fail).then(done);
});

it('adds cues to the track', function(done) {
mockParser.and.returnValue([1, 2, 3]);

Expand Down

0 comments on commit 022226c

Please sign in to comment.