-
Notifications
You must be signed in to change notification settings - Fork 155
player comps #1
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
Merged
Merged
player comps #1
Changes from all commits
Commits
Show all changes
18 commits
Select commit
Hold shift + click to select a range
361a50e
wip
malerba118 971509f
tweaks
malerba118 3e57038
stuff
malerba118 0cdb676
wip
malerba118 4102fc5
stuff
malerba118 dfadc7c
stuff
malerba118 c08b64a
stuff
malerba118 b8bfb19
perf
malerba118 946629c
tweaks
malerba118 e064600
stuff
malerba118 56c639d
tweaks
malerba118 9efb71a
stuff
malerba118 112e396
stuff
malerba118 a81faae
stuff
malerba118 9f7c932
tweaks
malerba118 d651a57
tweaks
malerba118 6cdbe81
remove framer-motion dep
malerba118 ceb0ac1
cleanup
malerba118 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
116 changes: 116 additions & 0 deletions
116
apps/playground/components/audio-components-demo/player-demo.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,116 @@ | ||
| import { | ||
| PlayerButton, | ||
| PlayerDuration, | ||
| PlayerProgress, | ||
| PlayerProvider, | ||
| PlayerTime, | ||
| usePlayer, | ||
| } from '@/registry/audio-components/ui/player'; | ||
| import { cn } from '@elevenlabs/ui/lib/utils'; | ||
|
|
||
| export const PlayerDemoWrapper = () => { | ||
| return ( | ||
| <PlayerProvider> | ||
| <PlayerDemo /> | ||
| </PlayerProvider> | ||
| ); | ||
| }; | ||
|
|
||
| const PlayerDemo = () => { | ||
| return ( | ||
| <div className="flex gap-2"> | ||
| <ul className="w-80 flex flex-col gap-2"> | ||
| {songs.map(song => ( | ||
| <SongListItem key={song.id} song={song} /> | ||
| ))} | ||
| </ul> | ||
| <Player /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const Player = () => { | ||
| const player = usePlayer(); | ||
|
|
||
| return ( | ||
| <div className="bg-foreground/5 p-2 rounded-xl flex-1 flex gap-2"> | ||
| <PlayerButton | ||
| variant="ghost" | ||
| className="h-full w-16 hover:!bg-foreground/5" | ||
| /> | ||
| <div className="flex flex-col justify-center w-full gap-1.5 pr-4"> | ||
| <p>{player.activeItem ? player.activeItem?.data.name : '-------'}</p> | ||
| <div className="flex items-center gap-4"> | ||
| <PlayerTime /> | ||
| <PlayerProgress className="flex-1" /> | ||
| <PlayerDuration /> | ||
| </div> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| type Song = { | ||
| id: string; | ||
| name: string; | ||
| url: string; | ||
| }; | ||
|
|
||
| const songs = [ | ||
| { | ||
| id: '1', | ||
| name: 'Rise up rap', | ||
| url: '/audio/rap.mp3', | ||
| }, | ||
| { | ||
| id: '2', | ||
| name: 'Midnight swing', | ||
| url: '/audio/jazz.mp3', | ||
| }, | ||
| ]; | ||
|
|
||
| const SongListItem = ({ song }: { song: Song }) => { | ||
| const player = usePlayer(); | ||
|
|
||
| return ( | ||
| <li | ||
| onClick={() => { | ||
| if (player.isPlaying && player.isItemActive(song.id)) { | ||
| player.pause(); | ||
| } else { | ||
| player.play({ | ||
| id: song.id, | ||
| src: song.url, | ||
| data: song, | ||
| }); | ||
| } | ||
| }} | ||
| className={cn( | ||
| 'group flex items-center justify-between rounded-xl p-2 hover:bg-foreground/5 cursor-pointer', | ||
| player.isItemActive(song.id) && 'bg-foreground/5', | ||
| )} | ||
| tabIndex={0} | ||
| > | ||
| <p className="pl-3">{song.name}</p> | ||
| <div | ||
| className={cn( | ||
| 'opacity-0 group-hover:opacity-100', | ||
| player.isItemActive(song.id) && 'opacity-100', | ||
| )} | ||
| > | ||
| <PlayerButton | ||
| variant="ghost" | ||
| className="hover:!bg-foreground/5 w-9" | ||
| item={{ | ||
| id: song.id, | ||
| src: song.url, | ||
| data: song, | ||
| }} | ||
| onClick={e => { | ||
| e.stopPropagation(); | ||
| }} | ||
| /> | ||
| </div> | ||
| </li> | ||
| ); | ||
| }; | ||
Binary file not shown.
Binary file not shown.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.