summaryrefslogtreecommitdiff
path: root/example_test.go
diff options
context:
space:
mode:
authorxegineering <me@xegineering.eu>2024-10-03 19:16:56 +0200
committerxegineering <me@xegineering.eu>2024-10-03 20:00:04 +0200
commitb8fed490c275487f14bff4f5b49a6072d27e5b5f (patch)
tree0dc59aa2a31c7168fefa47e9839b984f8a6eb502 /example_test.go
parent9b995e02371e45e8cb5806ee7c7eb8139bf24fd8 (diff)
downloadsoundbox-go-b8fed490c275487f14bff4f5b49a6072d27e5b5f.tar
soundbox-go-b8fed490c275487f14bff4f5b49a6072d27e5b5f.tar.zst
soundbox-go-b8fed490c275487f14bff4f5b49a6072d27e5b5f.zip
Add soundbox.StreamURLContext()v0.1.0
This should be the primary public API of the library to stream web radio to soundbox devices.
Diffstat (limited to 'example_test.go')
-rw-r--r--example_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/example_test.go b/example_test.go
new file mode 100644
index 0000000..78b2f27
--- /dev/null
+++ b/example_test.go
@@ -0,0 +1,38 @@
+package soundbox_test
+
+import (
+ "context"
+ "log"
+ "net"
+ "time"
+
+ "xengineering.eu/soundbox"
+)
+
+func ExampleStreamURLContext() {
+ ctx, cancel := context.WithCancel(context.Background())
+
+ // all soundboxes are referenced by their MAC address
+ soundboxes := []net.HardwareAddr{
+ {0x00, 0x00, 0x5E, 0x00, 0x53, 0x01},
+ {0x00, 0x00, 0x5E, 0x00, 0x53, 0x02},
+ {0x00, 0x00, 0x5E, 0x00, 0x53, 0x03},
+ }
+
+ // currently only web radio is supported
+ url := "https://example.org/radio.mp3"
+
+ // start streaming
+ go func() {
+ err := soundbox.StreamURLContext(ctx, url, soundboxes)
+ if err != nil {
+ log.Fatal(err)
+ }
+ }()
+
+ // let it play for some time
+ time.Sleep(time.Minute)
+
+ // stop it
+ cancel()
+}