1
+ local screenSize = Vector2 (guiGetScreenSize ())
2
+ local BOX_SIZE = Vector2 (300 , 100 )
3
+ local LINE_SIZE = Vector2 (BOX_SIZE .x , 10 )
4
+ local BOX_POSITION = screenSize / 2 - BOX_SIZE / 2
5
+ local TITLE_POSITION = BOX_POSITION + Vector2 (8 , 8 )
6
+ local ARTIST_POSITION = BOX_POSITION + Vector2 (8 , 32 )
7
+
8
+ local sound
9
+
10
+ addCommandHandler (" playsound" , function ()
11
+ if isElement (sound ) then
12
+ destroyElement (sound )
13
+ end
14
+ sound = playSound (" https://example.com/song.mp3" )
15
+ end )
16
+
17
+ addCommandHandler (" stopsound" , function ()
18
+ if isElement (sound ) then
19
+ destroyElement (sound )
20
+ end
21
+ end )
22
+
23
+ addEventHandler (" onClientRender" , root , function ()
24
+ if isElement (sound ) then
25
+ local soundLength = getSoundLength (sound )
26
+ local soundPosition = getSoundPosition (sound )
27
+ local soundBufferLength = getSoundBufferLength (sound )
28
+
29
+ local meta = getSoundMetaTags (sound )
30
+
31
+ dxDrawRectangle (BOX_POSITION , BOX_SIZE , tocolor (20 , 20 , 20 , 255 ), false , false )
32
+
33
+ if meta .title then
34
+ dxDrawText (meta .title , TITLE_POSITION , 0 , 0 , tocolor (255 , 255 , 255 , 255 ), 1.5 , 1.5 , " clear" )
35
+ end
36
+ if meta .artist then
37
+ dxDrawText (meta .artist , ARTIST_POSITION , 0 , 0 , tocolor (255 , 255 , 255 , 255 ), 1.0 , 1.0 , " clear" )
38
+ end
39
+
40
+ dxDrawText ((" %d:%02d" ):format (soundPosition / 60 , soundPosition % 60 ), BOX_POSITION + Vector2 (8 , BOX_SIZE .y - 32 ), BOX_POSITION + BOX_SIZE - Vector2 (8 , 0 ), tocolor (255 , 255 , 255 , 255 ), 1.0 , 1.0 , " clear" , " left" , " top" )
41
+ dxDrawText ((" %d:%02d" ):format (soundLength / 60 , soundLength % 60 ), BOX_POSITION + Vector2 (8 , BOX_SIZE .y - 32 ), BOX_POSITION + BOX_SIZE - Vector2 (8 , 0 ), tocolor (255 , 255 , 255 , 255 ), 1.0 , 1.0 , " clear" , " right" , " top" )
42
+
43
+ -- draw seek bar
44
+ local linePosition = Vector2 (BOX_POSITION .x , BOX_POSITION .y + BOX_SIZE .y - LINE_SIZE .y )
45
+ dxDrawRectangle (linePosition , LINE_SIZE , tocolor (255 , 255 , 255 , 128 ), false , false )
46
+
47
+ -- draw buffer length
48
+ if soundBufferLength then
49
+ dxDrawRectangle (linePosition , Vector2 (LINE_SIZE .x * (soundBufferLength / soundLength ), LINE_SIZE .y ), tocolor (255 , 255 , 255 , 96 ), false , false )
50
+ end
51
+ -- draw current position
52
+ dxDrawRectangle (linePosition , Vector2 (LINE_SIZE .x * (soundPosition / soundLength ), LINE_SIZE .y ), tocolor (255 , 255 , 255 , 255 ), false , false )
53
+ end
54
+ end )
0 commit comments