-
Notifications
You must be signed in to change notification settings - Fork 536
Audio player initial impl #1552
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,12 +1,13 @@ | ||||||
| import { StickyNoteIcon } from "lucide-react"; | ||||||
| import { useMemo } from "react"; | ||||||
| import { useMemo, useState } from "react"; | ||||||
|
|
||||||
| import NoteEditor from "@hypr/tiptap/editor"; | ||||||
| import * as persisted from "../../../../store/tinybase/persisted"; | ||||||
| import { rowIdfromTab, type Tab } from "../../../../store/zustand/tabs"; | ||||||
| import { type TabItem, TabItemBase } from "../shared"; | ||||||
| import { InnerHeader } from "./inner-header"; | ||||||
| import { OuterHeader } from "./outer-header"; | ||||||
| import { AudioPlayer } from "./player"; | ||||||
| import { TitleInput } from "./title-input"; | ||||||
|
|
||||||
| export const TabItemNote: TabItem = ({ tab, handleClose, handleSelect }) => { | ||||||
|
|
@@ -26,6 +27,7 @@ export const TabItemNote: TabItem = ({ tab, handleClose, handleSelect }) => { | |||||
| export function TabContentNote({ tab }: { tab: Tab }) { | ||||||
| const sessionId = rowIdfromTab(tab); | ||||||
| const sessionRow = persisted.UI.useRow("sessions", sessionId, persisted.STORE_ID); | ||||||
| const [showAudioPlayer, setShowAudioPlayer] = useState(false); | ||||||
|
|
||||||
| const editorKey = useMemo( | ||||||
| () => `session-${sessionId}-raw`, | ||||||
|
|
@@ -51,7 +53,12 @@ export function TabContentNote({ tab }: { tab: Tab }) { | |||||
| return ( | ||||||
| <div className="flex flex-col px-4 py-1 rounded-lg border"> | ||||||
| <div className="py-1"> | ||||||
| <OuterHeader sessionRow={sessionRow} sessionId={sessionId} /> | ||||||
| <OuterHeader | ||||||
| sessionRow={sessionRow} | ||||||
| sessionId={sessionId} | ||||||
| onToggleAudioPlayer={() => setShowAudioPlayer(!showAudioPlayer)} | ||||||
| isAudioPlayerVisible={showAudioPlayer} | ||||||
| /> | ||||||
| </div> | ||||||
|
|
||||||
| <TitleInput | ||||||
|
|
@@ -78,6 +85,7 @@ export function TabContentNote({ tab }: { tab: Tab }) { | |||||
| }, | ||||||
| }} | ||||||
| /> | ||||||
| {showAudioPlayer && <AudioPlayer url="https://www2.cs.uic.edu/~i101/SoundFiles/gettysburg10.wav" />} | ||||||
yujonglee marked this conversation as resolved.
Show resolved
Hide resolved
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Replace hardcoded URL with dynamic session audio URL. The audio player uses a hardcoded URL instead of dynamically loading the audio file associated with the current session. This will prevent the player from working with actual session recordings. Ensure the Expected pattern: - {showAudioPlayer && <AudioPlayer url="https://www2.cs.uic.edu/~i101/SoundFiles/gettysburg10.wav" />}
+ {showAudioPlayer && sessionRow.audio_url && <AudioPlayer url={sessionRow.audio_url} />}Note: Adjust the property name based on your actual schema. 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| </div> | ||||||
| ); | ||||||
| } | ||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { useWavesurfer } from "@wavesurfer/react"; | ||
| import { Pause, Play } from "lucide-react"; | ||
| import { useCallback, useRef } from "react"; | ||
|
|
||
| export function AudioPlayer({ url }: { url: string }) { | ||
| const containerRef = useRef<HTMLDivElement>(null); | ||
|
|
||
| const { wavesurfer, isPlaying, currentTime } = useWavesurfer({ | ||
| container: containerRef, | ||
| height: 60, | ||
| waveColor: "#666666", | ||
| progressColor: "#333333", | ||
| cursorColor: "#ffffff", | ||
| cursorWidth: 2, | ||
| barWidth: 3, | ||
| barGap: 2, | ||
| barRadius: 3, | ||
| url, | ||
| dragToSeek: true, | ||
| hideScrollbar: true, | ||
| normalize: true, | ||
| }); | ||
|
|
||
| const onPlayPause = useCallback(() => { | ||
| wavesurfer?.playPause(); | ||
| }, [wavesurfer]); | ||
|
|
||
| const duration = wavesurfer?.getDuration() || 0; | ||
|
|
||
| return ( | ||
| <div className="w-full bg-black border-t border-gray-800"> | ||
| <div className="flex items-center gap-4 px-6 py-4 w-full max-w-full"> | ||
| <button | ||
| onClick={onPlayPause} | ||
| className="flex items-center justify-center w-12 h-12 rounded-full bg-gray-700 hover:bg-gray-600 transition-colors flex-shrink-0" | ||
| > | ||
| {isPlaying | ||
| ? <Pause className="w-6 h-6 text-white" fill="currentColor" /> | ||
| : <Play className="w-6 h-6 text-white" fill="currentColor" />} | ||
| </button> | ||
yujonglee marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| <div className="flex items-center gap-2 text-sm text-gray-400 flex-shrink-0 min-w-[100px]"> | ||
| <span>{formatTime(currentTime)}</span> | ||
| <span>/</span> | ||
| <span>{formatTime(duration)}</span> | ||
| </div> | ||
|
|
||
| <div ref={containerRef} className="flex-1 min-w-0" style={{ minHeight: "60px", width: "100%" }} /> | ||
| </div> | ||
| </div> | ||
| ); | ||
| } | ||
|
|
||
| const formatTime = (seconds: number) => | ||
| [Math.floor(seconds / 60), Math.floor(seconds % 60)] | ||
| .map((v) => String(v).padStart(2, "0")) | ||
| .join(":"); | ||
Uh oh!
There was an error while loading. Please reload this page.