Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support alternate audio vizualizers #186

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
>;
19 changes: 16 additions & 3 deletions src/components/Viewer/Player/Player.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { render, screen } from "@testing-library/react";

import { AnnotationResources } from "src/types/annotations";
import { LabeledIIIFExternalWebResource } from "src/types/presentation-3";
import AudioVisualizer from "src/components/Viewer/Player/AudioVisualizer";
import Player from "src/components/Viewer/Player/Player";
import React from "react";
import { Vault } from "@iiif/vault";
Expand Down Expand Up @@ -65,7 +66,11 @@ describe("Player component", () => {
activeManifest:
"https://dcapi.rdc-staging.library.northwestern.edu/api/v2/works/d2a423b1-6b5e-45cb-9956-46a99cd62cfd?as=iiif",
collection: {},
configOptions: {},
configOptions: {
audioVisualizer: {
component: AudioVisualizer,
},
},
customDisplays: [],
plugins: [],
isInformationOpen: false,
Expand Down Expand Up @@ -127,7 +132,11 @@ describe("Player component", () => {
activeManifest:
"https://dcapi.rdc-staging.library.northwestern.edu/api/v2/works/d2a423b1-6b5e-45cb-9956-46a99cd62cfd?as=iiif",
collection: {},
configOptions: {},
configOptions: {
audioVisualizer: {
component: AudioVisualizer,
},
},
customDisplays: [],
plugins: [],
isInformationOpen: false,
Expand Down Expand Up @@ -186,7 +195,11 @@ describe("Player component", () => {
activeManifest:
"https://iiif.io/api/cookbook/recipe/0002-mvm-audio/manifest.json",
collection: {},
configOptions: {},
configOptions: {
audioVisualizer: {
component: AudioVisualizer,
},
},
customDisplays: [],
plugins: [],
isInformationOpen: false,
Expand Down
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 @@ -31,6 +31,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 @@ -202,7 +205,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: 10 additions & 0 deletions src/context/viewer-context.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ import { Vault } from "@iiif/vault";
import { deepMerge } from "src/lib/utils";
import { v4 as uuidv4 } from "uuid";

import AudioVisualizer from "../components/Viewer/Player/AudioVisualizer";
import { AudioVisualizerBase } from "../components/Viewer/Player/AudioVisualizerBase";

export type AutoScrollSettings = {
behavior: string; // ScrollBehavior ("auto" | "instant" | "smooth")
block: string; // ScrollLogicalPosition ("center" | "end" | "nearest" | "start")
Expand All @@ -22,6 +25,10 @@ export type AutoScrollOptions = {

export type ViewerConfigOptions = {
annotationOverlays?: OverlayOptions;
audioVisualizer?: {
component?: AudioVisualizerBase;
props?: unknown;
};
background?: string;
canvasBackgroundColor?: string;
canvasHeight?: string;
Expand Down Expand Up @@ -84,6 +91,9 @@ const defaultConfigOptions = {
renderOverlays: true,
zoomLevel: 2,
},
audioVisualizer: {
component: AudioVisualizer,
},
background: "transparent",
canvasBackgroundColor: "#6662",
canvasHeight: "500px",
Expand Down
Loading