Skip to content

Commit

Permalink
Support alternate audio vizualizers
Browse files Browse the repository at this point in the history
  • Loading branch information
mbklein committed Mar 13, 2024
1 parent ed01ac9 commit 4b7f77f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/components/Viewer/Player/AudioVisualizerBase.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { ForwardRefExoticComponent, RefAttributes } from "react";
export type AudioVisualizerBase = ForwardRefExoticComponent<
RefAttributes<HTMLElement>
>;
11 changes: 9 additions & 2 deletions src/components/Viewer/Player/Player.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand All @@ -30,6 +30,9 @@ const Player: React.FC<PlayerProps> = ({

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
Expand Down Expand Up @@ -195,7 +198,11 @@ const Player: React.FC<PlayerProps> = ({
Sorry, your browser doesn&apos;t support embedded videos.
</video>

{isAudio && <AudioVisualizer ref={playerRef} />}
{isAudio &&
React.createElement(audioVisualizerComponent, {
...audioVisualizerProps,
ref: playerRef,
})}
</PlayerWrapper>
);
};
Expand Down
10 changes: 9 additions & 1 deletion src/context/viewer-context.tsx
Original file line number Diff line number Diff line change
@@ -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?: {
Expand All @@ -16,6 +17,10 @@ export type ViewerConfigOptions = {
renderOverlays?: boolean;
zoomLevel?: number;
};
audioVisualizer?: {
component?: AudioVisualizerBase;
props?: unknown;
};
background?: string;
canvasBackgroundColor?: string;
canvasHeight?: string;
Expand Down Expand Up @@ -44,6 +49,9 @@ const defaultConfigOptions = {
renderOverlays: true,
zoomLevel: 2,
},
audioVisualizer: {
component: AudioVisualizer,
},
background: "transparent",
canvasBackgroundColor: "#6662",
canvasHeight: "61.8vh",
Expand Down

0 comments on commit 4b7f77f

Please sign in to comment.