Skip to content

Commit

Permalink
Use <source> and <track> elements
Browse files Browse the repository at this point in the history
  • Loading branch information
DanOlson committed Jun 19, 2024
1 parent b3af7ae commit 0cb0421
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions src/components/canvas-instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { convertToPercentage } from '../helpers/convert-to-percentage';

const $ = require('jquery');
import { Annotation, AnnotationBody, Canvas, Duration, Range, Utils } from 'manifesto.js';
import { Behavior, MediaType } from '@iiif/vocabulary/dist-commonjs';
import { Behavior, MediaType, RenderingFormat } from '@iiif/vocabulary/dist-commonjs';
import { BaseComponent, IBaseComponentOptions } from '@iiif/base-component';
import { IAVCanvasInstanceData } from '../interfaces/canvas-instance-data';
import { MediaElement } from '../elements/media-element';
Expand Down Expand Up @@ -35,6 +35,13 @@ import { getHls } from '../helpers/get-hls';
import 'waveform-panel';
import { WaveformPanel } from 'waveform-panel';

type AugmentedRenderingFormat = RenderingFormat | "text/vtt";
type TextTrackDescriptor = {
language?: string;
label?: string;
id: string;
};

export class CanvasInstance extends BaseComponent {
private _$canvasContainer: JQuery;
private _$canvasDuration: JQuery;
Expand Down Expand Up @@ -589,6 +596,16 @@ export class CanvasInstance extends BaseComponent {
const offsetStart = ot[0] ? parseInt(ot[0]) : ot[0],
offsetEnd = ot[1] ? parseInt(ot[1]) : ot[1];

const captions: Array<TextTrackDescriptor> = item
.getRenderings()
.filter(r => r.getFormat() as AugmentedRenderingFormat === "text/vtt")
.map(vttRendering => ({
label:
vttRendering.getLabel().getValue() ??
vttRendering.getFormat().toString(),
id: vttRendering.id,
}));

// todo: type this
const itemData: any = {
active: false,
Expand All @@ -603,6 +620,7 @@ export class CanvasInstance extends BaseComponent {
top: percentageTop,
type: type,
width: percentageWidth,
captions: captions
};

this._renderMediaElement(itemData);
Expand Down Expand Up @@ -1334,7 +1352,16 @@ export class CanvasInstance extends BaseComponent {
//});
}
} else {
$mediaElement.attr('src', data.source);
$mediaElement.append(
$(`<source src="${data.source}" type="${data.format}">`)
);
if (data.captions && data.captions.length) {
data.captions.forEach(subtitle => {
$mediaElement.append(
$(`<track label="${subtitle.label}" kind="subtitles" srclang="${subtitle.language}" src="${subtitle.id}" ${data.captions.indexOf(subtitle) === 0 ? "default" : ""}>`)
);
})
}
}

$mediaElement
Expand Down

0 comments on commit 0cb0421

Please sign in to comment.