| @@ -1,34 +1,46 @@ |
| 1 |
#include <stdio.h> |
1 |
#include <stdio.h> |
| 2 |
#include <string.h> |
2 |
#include <string.h> |
| 3 |
#include <stdlib.h> |
3 |
#include <stdlib.h> |
|
|
4 |
+#include <libgen.h> |
| 4 |
#include "raylib.h" |
5 |
#include "raylib.h" |
| 5 |
|
6 |
|
| 6 |
int |
7 |
int |
| 7 |
-main () |
8 |
+main (int argc, char **argv) |
| 8 |
{ |
9 |
{ |
| 9 |
- const int width = 640; |
10 |
+ const int width = 1280; |
| 10 |
- const int height = 480; |
11 |
+ const int height = 720; |
| 11 |
|
12 |
|
| 12 |
InitWindow (width, height, "moosic palyer"); |
13 |
InitWindow (width, height, "moosic palyer"); |
| 13 |
SetTargetFPS (60); |
14 |
SetTargetFPS (60); |
| 14 |
InitAudioDevice(); |
15 |
InitAudioDevice(); |
|
|
16 |
+ |
| 15 |
Music song; |
17 |
Music song; |
| 16 |
- FILE *f = popen("zenity --file-selection", "r"); |
18 |
+ if (argc > 1) |
| 17 |
- if (f != NULL) |
|
|
| 18 |
{ |
19 |
{ |
| 19 |
- char song_path[1024]; |
20 |
+ song = LoadMusicStream(argv[1]); |
| 20 |
- if (fgets(song_path, sizeof(song_path), f) != NULL) { |
21 |
+ PlayMusicStream(song); |
| 21 |
- song_path[strcspn(song_path, "\n")] = 0; |
22 |
+ } |
|
|
23 |
+ else { |
|
|
24 |
+ |
|
|
25 |
+ FILE *f = popen("zenity --file-selection", "r"); |
|
|
26 |
+ if (f != NULL) |
|
|
27 |
+ { |
|
|
28 |
+ char song_path[1024]; |
| 22 |
|
29 |
|
| 23 |
- song = LoadMusicStream(song_path); |
30 |
+ if (fgets(song_path, sizeof(song_path), f) != NULL) |
| 24 |
- PlayMusicStream(song); |
31 |
+ { |
|
|
32 |
+ song_path[strcspn(song_path, "\n")] = 0; |
|
|
33 |
+ song = LoadMusicStream(song_path); |
|
|
34 |
+ PlayMusicStream(song); |
|
|
35 |
+ } |
|
|
36 |
+ pclose(f); |
| 25 |
} |
37 |
} |
| 26 |
- pclose(f); |
38 |
+ } |
| 27 |
- } |
39 |
+ |
| 28 |
- |
|
|
| 29 |
while (!WindowShouldClose ()) |
40 |
while (!WindowShouldClose ()) |
| 30 |
{ |
41 |
{ |
| 31 |
UpdateMusicStream (song); |
42 |
UpdateMusicStream (song); |
|
|
43 |
+ float vol = GetMasterVolume (); |
| 32 |
|
44 |
|
| 33 |
if (IsKeyPressed (KEY_P) == true && IsMusicStreamPlaying (song)) |
45 |
if (IsKeyPressed (KEY_P) == true && IsMusicStreamPlaying (song)) |
| 34 |
{ |
46 |
{ |
| @@ -38,21 +50,41 @@ main () |
| 38 |
{ |
50 |
{ |
| 39 |
ResumeMusicStream (song); |
51 |
ResumeMusicStream (song); |
| 40 |
} |
52 |
} |
| 41 |
- |
53 |
+ else if (IsKeyPressed (KEY_EQUAL) == true && IsMusicStreamPlaying (song)) |
| 42 |
- BeginDrawing (); |
|
|
| 43 |
- ClearBackground (BLACK); |
|
|
| 44 |
- |
|
|
| 45 |
- if (!IsMusicStreamPlaying (song)) |
|
|
| 46 |
{ |
54 |
{ |
| 47 |
- DrawText("paused :<", width / 2, height /2 , 14, RAYWHITE); |
55 |
+ SetMasterVolume (vol + 0.1f); |
| 48 |
} |
56 |
} |
| 49 |
- else |
57 |
+ else if (IsKeyPressed (KEY_MINUS) == true && IsMusicStreamPlaying (song)) |
| 50 |
{ |
58 |
{ |
| 51 |
- DrawText("currently playing music :D", width / 2, height / 2 , 14, RAYWHITE); |
59 |
+ SetMasterVolume (vol - 0.1f); |
| 52 |
} |
60 |
} |
|
|
61 |
+ |
|
|
62 |
+ BeginDrawing (); |
|
|
63 |
+ ClearBackground (BLACK); |
|
|
64 |
+ |
|
|
65 |
+ char path_copy[1024]; |
|
|
66 |
+ char song_path[1024]; |
|
|
67 |
+ strncpy(path_copy, song_path, sizeof(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 |
+ |
| 53 |
EndDrawing (); |
84 |
EndDrawing (); |
| 54 |
|
85 |
|
| 55 |
} |
86 |
} |
|
|
87 |
+ |
| 56 |
UnloadMusicStream(song); |
88 |
UnloadMusicStream(song); |
| 57 |
CloseAudioDevice (); |
89 |
CloseAudioDevice (); |
| 58 |
CloseWindow (); |
90 |
CloseWindow (); |