-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
Showing
11 changed files
with
286 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
//@flow | ||
class TimedMetadata { | ||
static TYPE: {[type: string]: string}; | ||
|
||
startTime: number; | ||
endTime: number; | ||
id: string; | ||
type: string; | ||
metadata: string | Object; | ||
/** | ||
* @constructor | ||
* @param {number} startTime - start time. | ||
* @param {number} endTime - end time. | ||
* @param {string} id - id. | ||
* @param {string} type - type. | ||
* @param {any} metadata - metadata. | ||
*/ | ||
constructor(startTime: number, endTime: number, id: string, type: string, metadata: any) { | ||
this.startTime = startTime; | ||
this.endTime = endTime; | ||
this.id = id; | ||
this.type = type; | ||
this.metadata = metadata; | ||
} | ||
} | ||
|
||
TimedMetadata.TYPE = { | ||
ID3: 'id3', | ||
EMSG: 'emsg', | ||
CUE_POINT: 'cuepoint', | ||
CUSTOM: 'custom' | ||
}; | ||
|
||
/** | ||
* Create a standard TextTrackCue. | ||
* @param {TimedMetadata} timedMetadata - timed metadata object. | ||
* @returns {TextTrackCue} - the created text track cue | ||
* @private | ||
*/ | ||
function createTextTrackCue(timedMetadata: TimedMetadata): TextTrackCue { | ||
const {startTime, endTime, id, type, metadata} = timedMetadata; | ||
let cue = {}; | ||
if (window.VTTCue) { | ||
cue = new window.VTTCue(startTime, endTime, ''); | ||
} else if (window.TextTrackCue) { | ||
// IE11 support | ||
cue = new window.TextTrackCue(startTime, endTime, ''); | ||
} | ||
const cueValue = {key: type, data: metadata}; | ||
cue.id = id; | ||
cue.value = cueValue; | ||
return cue; | ||
} | ||
|
||
/** | ||
* Create a timed metadata object from a standard TextTrackCue. | ||
* @param {TextTrackCue} cue - text track cue. | ||
* @returns {?TimedMetadata} - the created timed metadata object. | ||
* @private | ||
*/ | ||
function createTimedMetadata(cue: TextTrackCue): ?TimedMetadata { | ||
if (cue) { | ||
const {startTime, endTime, id} = cue; | ||
const {type, metadata} = _getTypeAndMetadata(cue); | ||
return new TimedMetadata(startTime, endTime, id, type, metadata); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* @param {TextTrackCue} cue - cue | ||
* @return {Object} - type and data | ||
* @private | ||
*/ | ||
function _getTypeAndMetadata(cue: TextTrackCue): Object { | ||
const { | ||
type, | ||
value, | ||
track: {label} | ||
} = cue; | ||
const {key, data} = value; | ||
const isId3 = type === 'org.id3' || label === 'id3'; | ||
let timedMetadataType = Object.values(TimedMetadata.TYPE).find(type => type === key); | ||
if (!timedMetadataType) { | ||
timedMetadataType = isId3 ? TimedMetadata.TYPE.ID3 : TimedMetadata.TYPE.CUSTOM; | ||
} | ||
return { | ||
type: timedMetadataType, | ||
metadata: isId3 ? value : data | ||
}; | ||
} | ||
|
||
export {TimedMetadata, createTextTrackCue, createTimedMetadata}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
//@flow | ||
/** | ||
* @param {Array<any>} list The array to search. | ||
* @param {Function} comparisonFn | ||
* Called and provided a candidate item as the first argument. | ||
* Should return: | ||
* > -1 if the item should be located at a lower index than the provided item. | ||
* > 1 if the item should be located at a higher index than the provided item. | ||
* > 0 if the item is the item you're looking for. | ||
* | ||
* @return {any} The object if it is found or null otherwise. | ||
*/ | ||
export function binarySearch(list: Array<any> = [], comparisonFn: Function = () => 1): any { | ||
if (list.length === 0 || (list.length === 1 && comparisonFn(list[0]) !== 0)) { | ||
return null; | ||
} | ||
const mid = Math.floor(list.length / 2); | ||
if (comparisonFn(list[mid]) === 0) { | ||
return list[mid]; | ||
} | ||
if (comparisonFn(list[mid]) > 0) { | ||
return binarySearch(list.slice(0, mid), comparisonFn); | ||
} else { | ||
return binarySearch(list.slice(mid + 1), comparisonFn); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export * from './util'; | ||
export {ResizeWatcher} from './resize-watcher'; | ||
export {MultiMap} from './multi-map'; | ||
export {binarySearch} from './binary-search'; |
Oops, something went wrong.