diff --git a/src/components/Viewer/Player/AudioVisualizerBase.tsx b/src/components/Viewer/Player/AudioVisualizerBase.tsx new file mode 100644 index 00000000..1d51472d --- /dev/null +++ b/src/components/Viewer/Player/AudioVisualizerBase.tsx @@ -0,0 +1,4 @@ +import { ForwardRefExoticComponent, RefAttributes } from "react"; +export type AudioVisualizerBase = ForwardRefExoticComponent< + RefAttributes +>; diff --git a/src/components/Viewer/Player/Player.tsx b/src/components/Viewer/Player/Player.tsx index 82d51b01..7e40b597 100644 --- a/src/components/Viewer/Player/Player.tsx +++ b/src/components/Viewer/Player/Player.tsx @@ -4,7 +4,7 @@ import React, { useEffect } from "react"; import { ViewerContextStore, useViewerState } from "src/context/viewer-context"; import { AnnotationResources } from "src/types/annotations"; -import AudioVisualizer from "src/components/Viewer/Player/AudioVisualizer"; +import { AudioVisualizerBase } from "src/components/Viewer/Player/AudioVisualizerBase"; import { LabeledIIIFExternalWebResource } from "src/types/presentation-3"; import { PlayerWrapper } from "src/components/Viewer/Player/Player.styled"; import Track from "src/components/Viewer/Player/Track"; @@ -30,6 +30,9 @@ const Player: React.FC = ({ const viewerState: ViewerContextStore = useViewerState(); const { activeCanvas, configOptions, vault } = viewerState; + const audioVisualizerComponent = configOptions?.audioVisualizer + ?.component as AudioVisualizerBase; + const audioVisualizerProps = configOptions?.audioVisualizer?.props || {}; /** * HLS.js binding for .m3u8 files @@ -195,7 +198,11 @@ const Player: React.FC = ({ Sorry, your browser doesn't support embedded videos. - {isAudio && } + {isAudio && + React.createElement(audioVisualizerComponent, { + ...audioVisualizerProps, + ref: playerRef, + })} ); }; diff --git a/src/context/viewer-context.tsx b/src/context/viewer-context.tsx index b9c95bf0..1ed1d120 100644 --- a/src/context/viewer-context.tsx +++ b/src/context/viewer-context.tsx @@ -1,10 +1,11 @@ import React, { useReducer } from "react"; - import { CollectionNormalized } from "@iiif/presentation-3"; import { IncomingHttpHeaders } from "http"; import OpenSeadragon, { Options as OpenSeadragonOptions } from "openseadragon"; import { Vault } from "@iiif/vault"; import { deepMerge } from "src/lib/utils"; +import AudioVisualizer from "../components/Viewer/Player/AudioVisualizer"; +import { AudioVisualizerBase } from "../components/Viewer/Player/AudioVisualizerBase"; export type ViewerConfigOptions = { annotationOverlays?: { @@ -16,6 +17,10 @@ export type ViewerConfigOptions = { renderOverlays?: boolean; zoomLevel?: number; }; + audioVisualizer?: { + component?: AudioVisualizerBase; + props?: unknown; + }; background?: string; canvasBackgroundColor?: string; canvasHeight?: string; @@ -44,6 +49,9 @@ const defaultConfigOptions = { renderOverlays: true, zoomLevel: 2, }, + audioVisualizer: { + component: AudioVisualizer, + }, background: "transparent", canvasBackgroundColor: "#6662", canvasHeight: "61.8vh",