Skip to content

Commit

Permalink
Texttrack cue start and end times are now based on ID3 tag pts values
Browse files Browse the repository at this point in the history
  • Loading branch information
tdaines committed May 26, 2017
1 parent d5aeda4 commit 4fb5fe9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
17 changes: 9 additions & 8 deletions src/controller/id3-track-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,6 @@ class ID3TrackController extends EventHandler {
onFragParsingMetadata(data) {
const fragment = data.frag;
const samples = data.samples;
const startTime = fragment.start;
let endTime = fragment.start + fragment.duration;
// Give a slight bump to the endTime if it's equal to startTime to avoid a SyntaxError in IE
if (startTime === endTime) {
endTime += 0.0001;
}

// Attempt to recreate Safari functionality by creating
// WebKitDataCue objects when available and store the decoded
Expand All @@ -54,10 +48,17 @@ class ID3TrackController extends EventHandler {
for (let i = 0; i < samples.length; i++) {
const frames = ID3.getID3Frames(samples[i].data);
if (frames) {
const startTime = samples[i].pts;
let endTime = i < samples.length - 1 ? samples[i+1].pts : fragment.endPTS;

// Give a slight bump to the endTime if it's equal to startTime to avoid a SyntaxError in IE
if (startTime === endTime) {
endTime += 0.0001;
}

for(let j = 0; j < frames.length; j++) {
const frame = frames[j];
//Safari doesn't put the timestamp frame in the TextTrack
// so neither will we
// Safari doesn't put the timestamp frame in the TextTrack
if (!ID3.isTimeStampFrame(frame)) {
const cue = new Cue(startTime, endTime, '');
cue.value = frame;
Expand Down
4 changes: 2 additions & 2 deletions src/demux/id3.js
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ import {logger} from '../utils/logger';

/**
* Returns true if the ID3 frame is an Elementary Stream timestamp frame
* @param {ID3 frame} frame
* @param {ID3 frame} frame
*/
static isTimeStampFrame(frame) {
return (frame && frame.key === 'PRIV' && frame.info === 'com.apple.streaming.transportStreamTimestamp');
Expand All @@ -151,7 +151,7 @@ import {logger} from '../utils/logger';
/**
* Returns an array of ID3 frames found in all the ID3 tags in the id3Data
* @param {Uint8Array} id3Data - The ID3 data containing one or more ID3 tags
* @return {ID3 frame[]} - Array for ID3 frame objects
* @return {ID3 frame[]} - Array of ID3 frame objects
*/
static getID3Frames(id3Data) {
let offset = 0;
Expand Down

0 comments on commit 4fb5fe9

Please sign in to comment.