@@ -10,6 +10,7 @@ import { Drawer, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, D
10
10
import { Progress } from "./ui/progress" ;
11
11
12
12
import '@public/CSS/song-controls.css' ;
13
+ import { Tooltip , TooltipContent , TooltipProvider , TooltipTrigger } from "./ui/tooltip" ;
13
14
14
15
interface songControlsInterface {
15
16
songRef : any ;
@@ -57,18 +58,8 @@ export const SongControls = ({
57
58
const [ appearBar , setAppearBar ] = useState ( true ) ;
58
59
const [ optAppear , setOptAppear ] = useState ( optionalAppear ) ;
59
60
const [ mediumScreen , setMediumScreen ] = useState ( false ) ;
60
-
61
- useEffect ( ( ) => {
62
- const isScreenSmall = ( ) => {
63
- if ( window . innerWidth < 768 ) setMediumScreen ( true ) ;
64
- else setMediumScreen ( false ) ;
65
- } ;
66
- isScreenSmall ( ) ;
67
-
68
- window . addEventListener ( "resize" , isScreenSmall ) ;
69
-
70
- return ( ) => window . addEventListener ( "resize" , isScreenSmall ) ;
71
- } ) ;
61
+ const [ currentTimeVal , setCurrentTimeVal ] = useState ( 0 ) ;
62
+ const [ songTime , setSongtime ] = useState ( 0 ) ;
72
63
73
64
const pressedKeyOne = useEffect ( ( ) => {
74
65
const handleKeyDown = ( e : KeyboardEvent ) => {
@@ -117,10 +108,13 @@ export const SongControls = ({
117
108
118
109
const updateTime = ( ) => {
119
110
if ( song . duration ) {
120
- setSliderValue ( Number ( ( ( song . currentTime / song . duration ) * 100 ) . toFixed ( 0 ) ) ) ;
111
+ setSliderValue ( ( song . currentTime / song . duration ) * 100 ) ;
121
112
}
113
+ setCurrentTimeVal ( song . currentTime ) ;
122
114
} ;
123
115
116
+ setSongtime ( song . duration ) ;
117
+
124
118
song . addEventListener ( "timeupdate" , updateTime ) ;
125
119
126
120
return ( ) => {
@@ -136,6 +130,67 @@ export const SongControls = ({
136
130
useEffectConst ( ) ;
137
131
} , [ handleSkipSong ] ) ;
138
132
133
+ useEffect ( ( ) => {
134
+ const isScreenSmall = ( ) => {
135
+ if ( window . innerWidth < 768 ) setMediumScreen ( true ) ;
136
+ else setMediumScreen ( false ) ;
137
+ } ;
138
+ isScreenSmall ( ) ;
139
+
140
+ window . addEventListener ( "resize" , isScreenSmall ) ;
141
+
142
+ return ( ) => window . addEventListener ( "resize" , isScreenSmall ) ;
143
+ } ) ;
144
+
145
+ // this basically just adds support for stuff like media buttons and mobile media players in notification tray
146
+
147
+ // had never heard of this before but i guess better late than never
148
+ useEffect ( ( ) => {
149
+ const song = songRef . current ;
150
+ if ( ! song ) return ;
151
+
152
+ navigator . mediaSession . setActionHandler ( 'play' , ( ) => setIsPlaying ( true ) ) ;
153
+ navigator . mediaSession . setActionHandler ( 'pause' , ( ) => setIsPlaying ( false ) ) ;
154
+ navigator . mediaSession . setActionHandler ( 'previoustrack' , ( ) => handleSkipSong ( true ) ) ;
155
+ navigator . mediaSession . setActionHandler ( 'nexttrack' , ( ) => handleSkipSong ( false ) ) ;
156
+
157
+ if ( "mediaSession" in navigator ) {
158
+ navigator . mediaSession . metadata = new MediaMetadata ( {
159
+ title : songVal ,
160
+ artist : songCreator ,
161
+ album : "Yandhi" ,
162
+ artwork : [
163
+ {
164
+ src : image ,
165
+ sizes : "96x96" ,
166
+ type : "image/png" ,
167
+ } ,
168
+ ] ,
169
+ } ) ;
170
+ }
171
+
172
+ try {
173
+ const setPositionState = ( ) => {
174
+ if ( 'setPositionState' in navigator . mediaSession ) {
175
+ navigator . mediaSession . setPositionState ( {
176
+ duration : songTime || 0 , position : currentTimeVal || 0 ,
177
+ } ) ;
178
+ }
179
+ }
180
+
181
+ setPositionState ( ) ;
182
+
183
+ song . addEventListener ( "ended" , setPositionState ( ) ) ;
184
+
185
+ return ( ) => {
186
+ song . removeEventListener ( "ended" , setPositionState ( ) ) ;
187
+ }
188
+ } catch ( e ) {
189
+ console . log ( e ) ;
190
+ }
191
+
192
+ } , [ handleSkipSong , isPlaying , currentTimeVal , songTime ] ) ;
193
+
139
194
return (
140
195
< >
141
196
{ ! mediumScreen ? (
@@ -144,7 +199,7 @@ export const SongControls = ({
144
199
left-1/2 -translate-x-1/2 py-3 px-3 bg-primary-foreground/80 backdrop-blur-lg border-2 border-secondary
145
200
flex items-center transition-all duration-500 shadow-lg ${ appearBar ? "translate-y-0" : "translate-y-24"
146
201
} `}
147
- // onClick={hideControls}
202
+ onClick = { hideControls }
148
203
onKeyDown = { ( e ) => pressedKeyOne }
149
204
>
150
205
< DefaultSongControls
@@ -318,7 +373,7 @@ const DefaultSongControls = ({
318
373
</ div >
319
374
</ div >
320
375
321
- < div className = "flex flex-col justify-center gap-1 w-full" >
376
+ < div className = "flex flex-col justify-center gap-1 w-full" onClick = { ( e ) => e . stopPropagation ( ) } >
322
377
< div className = "flex justify-center gap-2 ml-2" >
323
378
< Button
324
379
size = "icon"
@@ -417,28 +472,27 @@ const SongControlsSmall = ({
417
472
418
473
return (
419
474
< >
420
- < div className = "flex flex-col" >
421
- < div className = "flex items-center py-3 px-3" >
422
- < div className = "flex items-center gap-2 flex-1 select-none" >
475
+ < div className = "flex flex-col w-full " >
476
+ < div className = "flex items-center py-3 px-3 justify-between " >
477
+ < div className = "flex items-center gap-2 flex-1 select-none max-w-[70%] shadowed-text relative " >
423
478
< Image
424
479
src = { image }
425
480
alt = { image }
426
481
width = { 60 }
427
482
height = { 60 }
428
483
className = "rounded-lg"
429
484
/>
430
- < div >
431
- < div className = "font-semibold overflow-hidden whitespace-nowrap text-ellipsis w-[40vw] " >
485
+ < div className = "overflow-hidden" >
486
+ < div className = "font-semibold overflow-hidden whitespace-pre text-ellipsis w-fit shadowed-text-div " >
432
487
{ songVal !== "" ? songVal : "No Track Found" }
433
488
</ div >
434
- < div className = "text-sm text-muted-foreground" > { songCreator } </ div >
489
+ < div className = "text-sm text-muted-foreground" >
490
+ { songCreator }
491
+ </ div >
435
492
</ div >
436
493
</ div >
437
494
438
- < div
439
- className = "flex justify-center gap-1"
440
- onClick = { ( e ) => e . stopPropagation ( ) }
441
- >
495
+ < div className = "flex justify-end gap-1" onClick = { ( e ) => e . stopPropagation ( ) } >
442
496
< Button
443
497
className = { `p-5 rounded-full ${ songVal !== "" ? "" : "opacity-50 cursor-not-allowed" } ` }
444
498
size = "icon"
@@ -516,9 +570,7 @@ const MiniPlayer = ({
516
570
} , [ handleSkipSong ] ) ;
517
571
518
572
return (
519
- < div
520
- className = { `p-8 flex flex-col gap-2 transition-all bg-primary-foreground` }
521
- >
573
+ < div className = { `p-8 flex flex-col gap-2 transition-all bg-primary-foreground w-full` } >
522
574
{ /* <Button variant='outline' size='icon' onClick={() => setAppear(false)} className="bg-transparent border-none cursor-pointer absolute top-3 left-3 rounded-full">
523
575
<ChevronDown />
524
576
</Button> */ }
@@ -534,7 +586,16 @@ const MiniPlayer = ({
534
586
/>
535
587
</ div >
536
588
< div className = "flex flex-col overflow-hidden" >
537
- < div className = "text-2xl font-semibold w-full overflow-hidden whitespace-pre scrolling-text relative" > { songVal || "Unknown" } </ div >
589
+ < TooltipProvider >
590
+ < Tooltip delayDuration = { 0 } >
591
+ < TooltipTrigger asChild >
592
+ < div className = "text-2xl font-semibold w-full overflow-hidden whitespace-pre scrolling-text relative select-none" > { songVal || "Unknown" } </ div >
593
+ </ TooltipTrigger >
594
+ < TooltipContent className = "bg-secondary px-2 py-1 rounded-full" align = "start" >
595
+ < div className = "z-50" > { songVal } </ div >
596
+ </ TooltipContent >
597
+ </ Tooltip >
598
+ </ TooltipProvider >
538
599
< div className = "text-md text-muted-foreground -translate-y-1" >
539
600
{ songCreator || "Unknown" }
540
601
</ div >
0 commit comments