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

feat: Allow for multiple mic recordings #2012

Draft
wants to merge 16 commits into
base: main
Choose a base branch
from
Draft
2 changes: 2 additions & 0 deletions fern/apis/fdr/definition/api/v1/read/type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ types:
minLength: optional<integer>
maxLength: optional<integer>
default: optional<string>
mimeType: optional<string>

LongType:
properties:
Expand All @@ -111,6 +112,7 @@ types:
Base64Type:
properties:
default: optional<base64>
mimeType: optional<string>

DateType:
properties:
Expand Down
2 changes: 2 additions & 0 deletions fern/apis/fdr/definition/api/v1/register/type.yml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ types:
minLength: optional<integer>
maxLength: optional<integer>
default: optional<string>
mimeType: optional<string>

LongType:
properties:
Expand All @@ -111,6 +112,7 @@ types:
Base64Type:
properties:
default: optional<base64>
mimeType: optional<string>

DateType:
properties:
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/fern-docs/bundle/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.vercel
1 change: 1 addition & 0 deletions packages/fern-docs/ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@
"unist-util-visit": "^5.0.0",
"url-join": "5.0.0",
"use-memo-one": "^1.1.3",
"webm-duration-fix": "^1.0.4",
"zod": "^3.23.8"
},
"devDependencies": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import { FernButton, FernButtonGroup } from "@fern-docs/components";
import { Download, Play, Pause } from "iconoir-react";
import { useEffect, useRef, useState } from "react";

interface PlaygroundAudioControlsProps {
audioUrl: string | null;
fileName?: string;
}

export function PlaygroundAudioControls({
audioUrl,
fileName = "recording.webm",
}: PlaygroundAudioControlsProps) {
const [isPlaying, setIsPlaying] = useState(false);
const [currentTime, setCurrentTime] = useState(0);
const [duration, setDuration] = useState(0);
const [isLoaded, setIsLoaded] = useState(false);
const audioRef = useRef<HTMLAudioElement | null>(null);

useEffect(() => {
if (audioRef.current) {
audioRef.current.onended = () => setIsPlaying(false);
audioRef.current.onloadedmetadata = () => {
const audioDuration = audioRef.current?.duration;
if (audioDuration && !isNaN(audioDuration) && isFinite(audioDuration)) {
setDuration(Math.round(audioDuration));
setIsLoaded(true);
}
};
audioRef.current.ontimeupdate = () => {
const currentTime = audioRef.current?.currentTime;
if (currentTime && !isNaN(currentTime) && isFinite(currentTime)) {
setCurrentTime(Math.round(currentTime));
}
};
}
}, []);

const formatTime = (seconds: number) => {
const mins = Math.floor(seconds / 60)
.toString()
.padStart(2, "0");
const secs = (seconds % 60).toString().padStart(2, "0");
return mins === "00" ? `${secs}s` : `${mins}:${secs}`;
};

const handlePlayPause = async () => {
if (!audioRef.current || !audioUrl) return;

if (isPlaying) {
audioRef.current.pause();
} else {
await audioRef.current.play();
}
setIsPlaying(!isPlaying);
};

const handleDownload = () => {
if (!audioUrl) return;
const a = document.createElement("a");
a.href = audioUrl;
a.download = fileName;
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
};

if (!audioUrl) return null;

return (
<div className="flex items-center gap-2">
<audio ref={audioRef} src={audioUrl} preload="metadata" />
{isLoaded && (
<span className="font-mono text-xs">
{`${formatTime(currentTime)}/${formatTime(duration)}`}
</span>
)}
<FernButtonGroup>
<FernButton
icon={isPlaying ? <Pause /> : <Play />}
onClick={handlePlayPause}
size="small"
variant="minimal"
disabled={!audioUrl}
/>
<FernButton
icon={<Download />}
onClick={handleDownload}
size="small"
variant="minimal"
disabled={!audioUrl}
/>
</FernButtonGroup>
</div>
);
}
Loading
Loading