mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-15 16:06:41 +03:00
feat(text): Add time context to modifyCueCallback (#6252)
This commit is contained in:
@@ -87,9 +87,11 @@ shaka.extern.TextParser.TimeContext;
|
||||
|
||||
/**
|
||||
* A callback used for editing cues before appending.
|
||||
* Provides the cue, and the URI of the captions file the cue was parsed from.
|
||||
* Provides the cue, the URI of the captions file the cue was parsed from, and
|
||||
* the time context that was used when generating that cue.
|
||||
* You can edit the cue object passed in.
|
||||
* @typedef {function(!shaka.text.Cue, ?string)}
|
||||
* @typedef {function(!shaka.text.Cue, ?string,
|
||||
* !shaka.extern.TextParser.TimeContext)}
|
||||
* @exportDoc
|
||||
*/
|
||||
shaka.extern.TextParser.ModifyCueCallback;
|
||||
|
||||
@@ -209,7 +209,7 @@ shaka.text.TextEngine = class {
|
||||
const allCues = this.parser_.parseMedia(
|
||||
shaka.util.BufferUtils.toUint8(buffer), time, uri);
|
||||
for (const cue of allCues) {
|
||||
this.modifyCueCallback_(cue, uri || null);
|
||||
this.modifyCueCallback_(cue, uri || null, time);
|
||||
}
|
||||
const cuesToAppend = allCues.filter((cue) => {
|
||||
return cue.startTime >= this.appendWindowStart_ &&
|
||||
|
||||
@@ -144,8 +144,10 @@ describe('TextEngine', () => {
|
||||
shaka.test.Util.spyFunc(modifyCueCallback));
|
||||
mockParseMedia.and.returnValue([cue1, cue2]);
|
||||
await textEngine.appendBuffer(dummyData, 0, 3, 'uri');
|
||||
expect(modifyCueCallback).toHaveBeenCalledWith(cue1, 'uri');
|
||||
expect(modifyCueCallback).toHaveBeenCalledWith(cue2, 'uri');
|
||||
expect(modifyCueCallback).toHaveBeenCalledWith(
|
||||
cue1, 'uri', jasmine.objectContaining({periodStart: 0}));
|
||||
expect(modifyCueCallback).toHaveBeenCalledWith(
|
||||
cue2, 'uri', jasmine.objectContaining({periodStart: 0}));
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user