about summary refs log tree commit diff
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/brr.zig17
-rw-r--r--src/main.zig12
-rw-r--r--static/sample.mp3bin0 -> 7373059 bytes
3 files changed, 21 insertions, 8 deletions
diff --git a/src/brr.zig b/src/brr.zig
index 3a0c94c..74ee419 100644
--- a/src/brr.zig
+++ b/src/brr.zig
@@ -12,9 +12,9 @@ pub fn brr(file: []const u8) !void {
         return;
     };
 
-    const file_path = file.ptr;
-    if (c.mpg123_open(handle, file_path) != 0) {
-        std.log.warn("Filed to open the file: {s}\n", .{file_path});
+    const file_path: [*c]const u8 = @ptrCast(file);
+    if (c.mpg123_open(handle, file_path) != c.MPG123_OK) {
+        std.log.warn("Failed to open the file: {s}\n", .{file_path});
         return;
     }
 
@@ -23,6 +23,7 @@ pub fn brr(file: []const u8) !void {
         std.log.warn("Failed to open ALSA device\n", .{});
         return;
     }
+
     var params: ?*c.snd_pcm_hw_params_t = null;
     _ = c.snd_pcm_hw_params_malloc(&params);
 
@@ -37,7 +38,15 @@ pub fn brr(file: []const u8) !void {
 
     while (true) {
         var done: usize = 0;
-        _ = c.mpg123_read(handle, &buffer[0], buffer.len, &done);
+        const result = c.mpg123_read(handle, &buffer[0], buffer.len, &done);
+        switch (result) {
+            c.MPG123_OK => {
+                std.log.info("Reading successfule", .{});
+            },
+            else => {
+                std.log.err("Decode error {}", .{result});
+            },
+        }
 
         if (done == 0) {
             _ = c.mpg123_delete(handle);
diff --git a/src/main.zig b/src/main.zig
index e054495..5609376 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -49,7 +49,14 @@ pub fn main() !void {
         return;
     }
 
-    if (args.len >= 2) {
+    if (args.len == 3) {
+        if (std.mem.eql(u8, args[1], "brr")) {
+            try brr.brr(args[2]);
+            return;
+        }
+    }
+
+    if (args.len == 2) {
         var argument = Arg{
             .name = args[1],
         };
@@ -58,9 +65,6 @@ pub fn main() !void {
             .LS => try ls.ls(),
             .TCP => try socket_server.start_server(),
             .WINDOW => try sdl_window.present_sdl_window(),
-            // TODO: parse options for arguments
-            // TODO: fix compile errors
-            // .BRR => try brr.brr(args[2]),
             else => {
                 return;
             },
diff --git a/static/sample.mp3 b/static/sample.mp3
new file mode 100644
index 0000000..cec587f
--- /dev/null
+++ b/static/sample.mp3
Binary files differ