soundbox

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 31, 2025 License: MPL-2.0 Imports: 11 Imported by: 1

Documentation

Overview

Example (Pipewire)
package main

import (
	"context"
	"log"
	"net"
	"time"

	"xengineering.eu/soundbox-go/soundbox"
)

func main() {
	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},
	}

	// start streaming
	go func() {
		err := soundbox.StreamPipewireContext(ctx, soundboxes)
		if err != nil {
			log.Fatal(err)
		}
	}()

	// let it play for some time
	time.Sleep(time.Minute)

	// stop it
	cancel()
}
Output:

Example (Url)
package main

import (
	"context"
	"log"
	"net"
	"time"

	"xengineering.eu/soundbox-go/soundbox"
)

func main() {
	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()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func StreamPipewireContext added in v0.2.0

func StreamPipewireContext(ctx context.Context, targets []net.HardwareAddr) error

func StreamURLContext

func StreamURLContext(ctx context.Context, url string, targets []net.HardwareAddr) error

StreamURLContext streams audio from a given URL to one or multiple soundbox devices. The devices are referenced via their MAC addresses given by the targets argument. The ctx argument is passed to cancel the streaming.

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL