Skip to content

Commit 117216e

Browse files
committed
Add playpause on audio player thumbnail
1 parent 9b60d0e commit 117216e

File tree

2 files changed

+47
-23
lines changed

2 files changed

+47
-23
lines changed

src/components/downloaded/audio-player.tsx

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import { CustomAudioPlayer } from '@/components/ocodo-ui/custom-audio-component'
44
import { useEffect, type FC } from 'react';
55
import { UvxYtdlpIcon } from '@/components/branding/uvxytdlp-icon';
66
import { useAudioPlayerContext } from '@/contexts/audio-player-context-provider';
7+
import { PauseIcon, PlayIcon } from 'lucide-react';
8+
import { thinIconStyle } from '@/lib/icon-style';
79

810
interface AudioPlayerProps {
911
fileName: string;
@@ -13,9 +15,9 @@ const fileToTitle = (fileName: string): string => fileName.replace(/\.[^/.]+$/,
1315

1416
export const AudioPlayer: FC<AudioPlayerProps> = ({ fileName }) => {
1517
const title = fileToTitle(fileName)
16-
const ext = fileName.replace(`${title}.`,'')
18+
const ext = fileName.replace(`${title}.`, '')
1719
const { apiBase } = useApiBase()
18-
const { setSrc } = useAudioPlayerContext()
20+
const { setSrc, toggleAudioPlayPause, isPlaying } = useAudioPlayerContext()
1921

2022
useEffect(() => {
2123
if (apiBase && fileName) {
@@ -26,19 +28,41 @@ export const AudioPlayer: FC<AudioPlayerProps> = ({ fileName }) => {
2628

2729
return (
2830
<div className={`select-none grid grid-cols-1 md:grid-cols-[auto_1fr] gap-4 p-4
29-
justify-center items-center sm:border sm:rounded-xl`}>
30-
<div className='flex flex-row items-center justify-center'>
31-
<Img
32-
className="h-[15em] bg-background/20 rounded-xl object-cover"
33-
src={`${apiBase}/thumbnail/${fileName}`}
34-
unloader={<UvxYtdlpIcon
35-
size={301}
36-
colors={["#6004", "#0604", "#0064"]}
37-
strokeWidth={6}
38-
totalDuration={10000}
39-
fadeDuration={3000}
40-
/>}
41-
/>
31+
justify-center items-center sm:border sm:rounded-x relative`}>
32+
<div
33+
onClick={() => toggleAudioPlayPause()}
34+
className='group flex flex-row items-center justify-center'
35+
>
36+
<div
37+
className={`absolute cursor-pointer opacity-10
38+
group-hover:opacity-100
39+
transition-opacity duration-500
40+
rounded-full bg-background/30
41+
w-20 h-20 mb-[22px]
42+
flex flex-row items-center justify-center`}>
43+
{isPlaying
44+
? <PauseIcon
45+
style={{ stroke: '#fff', ...thinIconStyle }}
46+
className="w-12 h-12 ml-[3px]" />
47+
: <PlayIcon
48+
style={{ stroke: '#fff', ...thinIconStyle }}
49+
className="w-12 h-12 ml-[3px]" />
50+
}
51+
</div>
52+
<div className='flex flex-row items-center justify-center'>
53+
<Img
54+
className="h-[15em] bg-background/20 rounded-xl object-cover"
55+
src={`${apiBase}/thumbnail/${fileName}`}
56+
unloader={<UvxYtdlpIcon
57+
size={301}
58+
colors={["#6004", "#0604", "#0064"]}
59+
strokeWidth={6}
60+
totalDuration={10000}
61+
fadeDuration={3000}
62+
/>}
63+
/>
64+
</div>
65+
4266
</div>
4367
{/* Col 2 */}
4468
<div className="grid grid-rows-[1fr_auto] h-full gap-4">

src/components/downloaded/downloaded-file.tsx

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ export const DowloadedFile: React.FC<DowloadedFileProps> = (props) => {
2626
const { apiBase } = useApiBase()
2727
const { viewType } = useDownloaded()
2828

29-
const Image = () => (
29+
const image = () => (
3030
<div
3131
className="flex flex-col justify-center items-center relative gap-1 bg-black rounded-t-xl group"
3232
onClick={() => handlePlay(file.name)}>
@@ -58,7 +58,7 @@ export const DowloadedFile: React.FC<DowloadedFileProps> = (props) => {
5858
</div>
5959
)
6060

61-
const PlayButton = () => (
61+
const playButton = () => (
6262
<div className={roundButtonClasses}
6363
onClick={() => handlePlay(file.name)} >
6464
<PlayIcon
@@ -68,7 +68,7 @@ export const DowloadedFile: React.FC<DowloadedFileProps> = (props) => {
6868
</div>
6969
)
7070

71-
const DownloadButton = () => (
71+
const downloadButton = () => (
7272
<div className={roundButtonClasses}
7373
onClick={() => handleDownload(file.name)} >
7474
<DownloadIcon
@@ -78,7 +78,7 @@ export const DowloadedFile: React.FC<DowloadedFileProps> = (props) => {
7878
</div>
7979
)
8080

81-
const DeleteButton = () => (
81+
const deleteButton = () => (
8282
<LongPressButton
8383
onLongPress={() => handleDelete(file.name)}
8484
longPressDuration={1000}
@@ -103,16 +103,16 @@ export const DowloadedFile: React.FC<DowloadedFileProps> = (props) => {
103103

104104
return (
105105
<div className={isList ? listClasses : gridClasses}>
106-
{isGrid && <Image />}
106+
{isGrid && image()}
107107
<div
108108
className={isList ? listNameClasses : gridNameClasses}>
109109
{file.name}
110110
</div>
111111
<div
112112
className={isList ? listButtonClasses : gridButtonClasses}>
113-
<PlayButton />
114-
<DownloadButton />
115-
<DeleteButton />
113+
{playButton()}
114+
{downloadButton()}
115+
{deleteButton()}
116116
</div>
117117
</div>
118118
)

0 commit comments

Comments
 (0)