From 0cb042129b536ee31370c692e3d8b09fa0acb508 Mon Sep 17 00:00:00 2001 From: Dan Olson Date: Tue, 18 Jun 2024 20:36:47 -0400 Subject: [PATCH 1/2] Use and elements --- src/components/canvas-instance.ts | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/components/canvas-instance.ts b/src/components/canvas-instance.ts index 96dfa06..a327d90 100644 --- a/src/components/canvas-instance.ts +++ b/src/components/canvas-instance.ts @@ -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'; @@ -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; @@ -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 = 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, @@ -603,6 +620,7 @@ export class CanvasInstance extends BaseComponent { top: percentageTop, type: type, width: percentageWidth, + captions: captions }; this._renderMediaElement(itemData); @@ -1334,7 +1352,16 @@ export class CanvasInstance extends BaseComponent { //}); } } else { - $mediaElement.attr('src', data.source); + $mediaElement.append( + $(``) + ); + if (data.captions && data.captions.length) { + data.captions.forEach(subtitle => { + $mediaElement.append( + $(``) + ); + }) + } } $mediaElement From 7647f08bcc7389a61a24e64d5993bf46b0962d0a Mon Sep 17 00:00:00 2001 From: Dan Olson Date: Wed, 3 Jul 2024 20:27:47 -0400 Subject: [PATCH 2/2] Add caption support This provides support for rendering captions when the manifest's annotation items have a text type rendering of format 'text/vtt'. The implementation is modeled after that of MediaElement.js --- src/components/canvas-instance.ts | 153 ++++++++++++++++++++++++++++-- src/css/iiif-av-component.less | 108 ++++++++++++++++++++- src/css/img/cc.png | Bin 0 -> 915 bytes 3 files changed, 249 insertions(+), 12 deletions(-) create mode 100644 src/css/img/cc.png diff --git a/src/components/canvas-instance.ts b/src/components/canvas-instance.ts index a327d90..2a45095 100644 --- a/src/components/canvas-instance.ts +++ b/src/components/canvas-instance.ts @@ -50,6 +50,8 @@ export class CanvasInstance extends BaseComponent { private _$canvasTime: JQuery; private _$canvasTimelineContainer: JQuery; private _$controlsContainer: JQuery; + private _$captionsButton: JQuery; + private _$captionsContainer: JQuery; private _$durationHighlight: JQuery; private _$hoverPreviewTemplate: JQuery; private _$nextButton: JQuery; @@ -69,6 +71,7 @@ export class CanvasInstance extends BaseComponent { private _canvasClockTime: TimelineTime = 0 as TimelineTime; private _canvasHeight = 0; private _canvasWidth = 0; + private _captionsSelectedIndex = 0; // hide captions by default private _waveformPanel?: WaveformPanel; private _contentAnnotations: any[]; // todo: type as HTMLMediaElement? private _data: IAVCanvasInstanceData = this.data(); @@ -102,7 +105,6 @@ export class CanvasInstance extends BaseComponent { this._$element = $(this.options.target); this._data = this.options.data; this.$playerElement = $('
'); - this.$playerElement.hide(); } public loaded(): void { @@ -274,12 +276,19 @@ export class CanvasInstance extends BaseComponent { ${this._data.content.fastRewind || ''} `); + this._$captionsButton = $(` +