Skip to content

Commit

Permalink
Fix display order of cues with identical ranges
Browse files Browse the repository at this point in the history
Since the browser displays identical ranges from bottom up, we must
reverse the order before feeding them to the browser.  This way, the
first one parsed shows up on top.

Issue #848

Backported to v2.1.x
  • Loading branch information
joeyparrish committed Aug 7, 2017
1 parent f553b28 commit fb51fe4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/media/text_engine.js
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ shaka.media.TextEngine.prototype.appendBuffer =
// Parse the buffer and add the new cues.
var cues = this.parser_.parseMedia(buffer, time);

// Reverse the order so that display of line=auto is correct.
// https://github.com/google/shaka-player/issues/848
cues.reverse();

for (var i = 0; i < cues.length; ++i) {
if (cues[i].startTime >= this.appendWindowEnd_) break;
this.track_.addCue(cues[i]);
Expand Down
12 changes: 12 additions & 0 deletions test/media/text_engine_unit.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,18 @@ describe('TextEngine', function() {
}).catch(fail).then(done);
});

it('adds cues in reverse order', function(done) {
// Regression test for https://github.com/google/shaka-player/issues/848
mockParseMedia.and.returnValue([1, 2, 3]);
textEngine.appendBuffer(dummyData, 0, 3).then(function() {
expect(mockTrack.addCue.calls.count()).toBe(3);
var calls = mockTrack.addCue.calls;
expect(calls.argsFor(0)).toEqual([3]);
expect(calls.argsFor(1)).toEqual([2]);
expect(calls.argsFor(2)).toEqual([1]);
}).catch(fail).then(done);
});

it('does not throw if called right before destroy', function(done) {
mockParseMedia.and.returnValue([1, 2, 3]);
textEngine.appendBuffer(dummyData, 0, 3).catch(fail).then(done);
Expand Down

0 comments on commit fb51fe4

Please sign in to comment.