| @@ -7,86 +7,136 @@ |
| 7 |
int |
7 |
int |
| 8 |
main (int argc, char **argv) |
8 |
main (int argc, char **argv) |
| 9 |
{ |
9 |
{ |
|
|
10 |
+ |
| 10 |
const int width = 1280; |
11 |
const int width = 1280; |
| 11 |
const int height = 720; |
12 |
const int height = 720; |
| 12 |
|
13 |
|
| 13 |
InitWindow (width, height, "moosic palyer"); |
14 |
InitWindow (width, height, "moosic palyer"); |
| 14 |
SetTargetFPS (60); |
15 |
SetTargetFPS (60); |
| 15 |
- InitAudioDevice(); |
16 |
+ InitAudioDevice (); |
|
|
17 |
+ |
|
|
18 |
+ Font font = LoadFont ("resources/IBMPlexSans-Bold.ttf"); |
| 16 |
|
19 |
|
| 17 |
Music song; |
20 |
Music song; |
|
|
21 |
+ char song_path[1024]; |
| 18 |
if (argc > 1) |
22 |
if (argc > 1) |
| 19 |
{ |
23 |
{ |
| 20 |
- song = LoadMusicStream(argv[1]); |
24 |
+ strncpy (song_path, argv[1], sizeof (song_path) - 1); |
| 21 |
- PlayMusicStream(song); |
25 |
+ song_path[sizeof (song_path) - 1] = 0; |
|
|
26 |
+ song = LoadMusicStream (song_path); |
|
|
27 |
+ PlayMusicStream (song); |
|
|
28 |
+ } |
|
|
29 |
+ else |
|
|
30 |
+ { |
|
|
31 |
+ |
|
|
32 |
+ FILE *f = popen ("zenity --file-selection", "r"); |
|
|
33 |
+ if (f != NULL) |
|
|
34 |
+ { |
|
|
35 |
+ |
|
|
36 |
+ |
|
|
37 |
+ if (fgets (song_path, sizeof (song_path), f) != NULL) |
|
|
38 |
+ { |
|
|
39 |
+ song_path[strcspn (song_path, "\n")] = 0; |
|
|
40 |
+ song = LoadMusicStream (song_path); |
|
|
41 |
+ PlayMusicStream (song); |
|
|
42 |
+ } |
|
|
43 |
+ pclose (f); |
|
|
44 |
+ } |
| 22 |
} |
45 |
} |
| 23 |
- else { |
46 |
+ |
| 24 |
- |
|
|
| 25 |
- FILE *f = popen("zenity --file-selection", "r"); |
|
|
| 26 |
- if (f != NULL) |
|
|
| 27 |
- { |
|
|
| 28 |
- char song_path[1024]; |
|
|
| 29 |
- |
|
|
| 30 |
- if (fgets(song_path, sizeof(song_path), f) != NULL) |
|
|
| 31 |
- { |
|
|
| 32 |
- song_path[strcspn(song_path, "\n")] = 0; |
|
|
| 33 |
- song = LoadMusicStream(song_path); |
|
|
| 34 |
- PlayMusicStream(song); |
|
|
| 35 |
- } |
|
|
| 36 |
- pclose(f); |
|
|
| 37 |
- } |
|
|
| 38 |
- } |
|
|
| 39 |
- |
|
|
| 40 |
while (!WindowShouldClose ()) |
47 |
while (!WindowShouldClose ()) |
| 41 |
{ |
48 |
{ |
| 42 |
UpdateMusicStream (song); |
49 |
UpdateMusicStream (song); |
| 43 |
float vol = GetMasterVolume (); |
50 |
float vol = GetMasterVolume (); |
| 44 |
- |
51 |
+ float total = GetMusicTimeLength (song); |
|
|
52 |
+ float time_played = GetMusicTimePlayed (song); |
|
|
53 |
+ |
|
|
54 |
+ if (IsKeyPressed (KEY_Q) == true) |
|
|
55 |
+ { |
|
|
56 |
+ break; |
|
|
57 |
+ } |
|
|
58 |
+ |
| 45 |
if (IsKeyPressed (KEY_P) == true && IsMusicStreamPlaying (song)) |
59 |
if (IsKeyPressed (KEY_P) == true && IsMusicStreamPlaying (song)) |
| 46 |
- { |
60 |
+ { |
| 47 |
- PauseMusicStream (song); |
61 |
+ PauseMusicStream (song); |
| 48 |
- } |
62 |
+ } |
|
|
63 |
+ |
| 49 |
else if (IsKeyPressed (KEY_P) == true && !IsMusicStreamPlaying (song)) |
64 |
else if (IsKeyPressed (KEY_P) == true && !IsMusicStreamPlaying (song)) |
| 50 |
- { |
65 |
+ { |
| 51 |
- ResumeMusicStream (song); |
66 |
+ ResumeMusicStream (song); |
| 52 |
- } |
67 |
+ } |
| 53 |
- else if (IsKeyPressed (KEY_EQUAL) == true && IsMusicStreamPlaying (song)) |
68 |
+ else if (IsKeyPressed (KEY_EQUAL) == true) |
| 54 |
- { |
69 |
+ { |
| 55 |
- SetMasterVolume (vol + 0.1f); |
70 |
+ SetMasterVolume (vol + 0.1f); |
| 56 |
- } |
71 |
+ } |
| 57 |
- else if (IsKeyPressed (KEY_MINUS) == true && IsMusicStreamPlaying (song)) |
72 |
+ else if (IsKeyPressed (KEY_MINUS) == true) |
| 58 |
- { |
73 |
+ { |
| 59 |
- SetMasterVolume (vol - 0.1f); |
74 |
+ SetMasterVolume (vol - 0.1f); |
| 60 |
- } |
75 |
+ } |
| 61 |
- |
76 |
+ |
|
|
77 |
+ if (IsKeyPressed (KEY_RIGHT) || IsKeyPressedRepeat (KEY_RIGHT)) |
|
|
78 |
+ { |
|
|
79 |
+ float t = time_played + 5.0f; |
|
|
80 |
+ SeekMusicStream (song, t < total ? t : total - 0.1f); |
|
|
81 |
+ } |
|
|
82 |
+ if (IsKeyPressed (KEY_LEFT) || IsKeyPressedRepeat (KEY_LEFT)) |
|
|
83 |
+ { |
|
|
84 |
+ float t = time_played - 5.0f; |
|
|
85 |
+ SeekMusicStream (song, t > 0.0f ? t : 0.0f); |
|
|
86 |
+ } |
|
|
87 |
+ |
| 62 |
BeginDrawing (); |
88 |
BeginDrawing (); |
| 63 |
ClearBackground (BLACK); |
89 |
ClearBackground (BLACK); |
| 64 |
- |
90 |
+ |
| 65 |
char path_copy[1024]; |
91 |
char path_copy[1024]; |
| 66 |
- char song_path[1024]; |
92 |
+ strncpy (path_copy, song_path, sizeof (path_copy)); |
| 67 |
- strncpy(path_copy, song_path, sizeof(path_copy)); |
93 |
+ char *filename = basename (path_copy); |
| 68 |
- char *filename = basename(path_copy); |
|
|
| 69 |
- |
|
|
| 70 |
- |
|
|
| 71 |
- |
|
|
| 72 |
- const char *text = !IsMusicStreamPlaying(song) |
|
|
| 73 |
- ? "paused :<" |
|
|
| 74 |
- : TextFormat("currently playing %s :D\n Volume: %.2f", filename, vol); |
|
|
| 75 |
- int font_size = 24; |
|
|
| 76 |
- int text_width = MeasureText(text, font_size); |
|
|
| 77 |
- |
|
|
| 78 |
- int text_x = (width - text_width) / 2; |
|
|
| 79 |
- int text_y = (height - font_size) / 2; |
|
|
| 80 |
- |
|
|
| 81 |
- |
|
|
| 82 |
- DrawText(text, text_x, text_y , font_size, RAYWHITE); |
|
|
| 83 |
|
94 |
|
| 84 |
- EndDrawing (); |
95 |
+ const char *line1 = !IsMusicStreamPlaying (song) |
|
|
96 |
+ ? "paused :<" : TextFormat ("currently playing %s :D", filename); |
|
|
97 |
+ |
|
|
98 |
+ const char *line2 = TextFormat ("Volume: %.2f", vol); |
|
|
99 |
+ int tp = (int) time_played; |
|
|
100 |
+ int tt = (int) total; |
|
|
101 |
+ const char *line3 = |
|
|
102 |
+ TextFormat ("%d:%02d / %d:%02d", tp / 60, tp % 60, tt / 60, tt % 60); |
|
|
103 |
+ |
|
|
104 |
+ |
|
|
105 |
+ int font_size = 32; |
|
|
106 |
+ float spacing = 1.0f; |
|
|
107 |
+ float line_spacing = 35.0f; |
| 85 |
|
108 |
|
|
|
109 |
+ Vector2 width1 = |
|
|
110 |
+ MeasureTextEx (font, line1, (float) font_size, spacing); |
|
|
111 |
+ Vector2 width2 = |
|
|
112 |
+ MeasureTextEx (font, line2, (float) font_size, spacing); |
|
|
113 |
+ Vector2 width3 = |
|
|
114 |
+ MeasureTextEx (font, line3, (float) font_size, spacing); |
|
|
115 |
+ |
|
|
116 |
+ int x1 = (width - (int) width1.x) / 2; |
|
|
117 |
+ int x2 = (width - (int) width2.x) / 2; |
|
|
118 |
+ int x3 = (width - (int) width3.x) / 2; |
|
|
119 |
+ int start_y = (height - 60) / 2; |
|
|
120 |
+ |
|
|
121 |
+ DrawTextEx (font, line1, (Vector2) |
|
|
122 |
+ { |
|
|
123 |
+ (float) x1, (float) start_y}, (float) font_size, spacing, |
|
|
124 |
+ RAYWHITE); |
|
|
125 |
+ DrawTextEx (font, line2, (Vector2) |
|
|
126 |
+ { |
|
|
127 |
+ (float) x2, (float) start_y + line_spacing}, |
|
|
128 |
+ (float) font_size, spacing, RAYWHITE); |
|
|
129 |
+ DrawTextEx (font, line3, (Vector2) |
|
|
130 |
+ { |
|
|
131 |
+ (float) x3, (float) start_y + line_spacing * 2}, |
|
|
132 |
+ (float) font_size, spacing, RAYWHITE); |
|
|
133 |
+ |
|
|
134 |
+ EndDrawing (); |
| 86 |
} |
135 |
} |
| 87 |
- |
136 |
+ |
| 88 |
- UnloadMusicStream(song); |
137 |
+ UnloadMusicStream (song); |
| 89 |
- CloseAudioDevice (); |
138 |
+ UnloadFont (font); |
| 90 |
- CloseWindow (); |
139 |
+ CloseAudioDevice (); |
|
|
140 |
+ CloseWindow (); |
| 91 |
return 0; |
141 |
return 0; |
| 92 |
} |
142 |
} |