about summary refs log tree commit diff
path: root/examples/play.zig
diff options
context:
space:
mode:
Diffstat (limited to 'examples/play.zig')
-rw-r--r--examples/play.zig17
1 files changed, 8 insertions, 9 deletions
diff --git a/examples/play.zig b/examples/play.zig
index 210972c..fab8f3f 100644
--- a/examples/play.zig
+++ b/examples/play.zig
@@ -1,5 +1,5 @@
 // Playing audio example
-// Copyright (C) 2021  Nguyễn Gia Phong
+// Copyright (C) 2021, 2023  Nguyễn Gia Phong
 //
 // This file is part of zeal.
 //
@@ -18,7 +18,7 @@
 
 const std = @import("std");
 const allocator = std.heap.c_allocator;
-const args = std.process.args;
+const args = std.process.argsWithAllocator;
 const print = std.debug.print;
 const sleep = std.time.sleep;
 
@@ -33,14 +33,13 @@ const Source = zeal.Source;
 pub fn main() !void {
     const device = try Device.init(null);
     defer device.deinit() catch unreachable;
-    const context = try Context.init(device, &.{});
+    const context = try Context.init(device, &.{ 0 });
     defer context.deinit() catch unreachable;
 
-    var argv = args();
-    allocator.free(try argv.next(allocator).?);
-    const path = try argv.next(allocator).?;
-    defer allocator.free(path);
-    const audio = try Audio.read(allocator, path);
+    var argv = try args(allocator);
+    defer argv.deinit();
+    _ = argv.next().?;
+    const audio = try Audio.read(allocator, argv.next().?);
     defer audio.free();
 
     try context.makeCurrent();
@@ -53,7 +52,7 @@ pub fn main() !void {
     try source.play();
     defer print("\n", .{});
     while (try source.isPlaying()) {
+        print("\r{d:.1} s", .{ try source.getSecOffset() });
         sleep(10_000_000);
-        print("\r{d:.1} s", .{ source.getSecOffset() });
     }
 }