Add conditional build tag to exclude microphones for camera-only builds (#679)

* Add tag

* Add nomicrophone build tag for optional microphone support

- Changed from platform-specific (!windows) to opt-out build tag (!nomicrophone)
- Microphone support included by default (non-breaking)
- Use -tags nomicrophone to exclude when malgo deps unavailable
- Useful for cross-compilation and minimal builds
- Renamed microphone_windows.go to microphone_stub.go for clarity

* Update README
This commit is contained in:
sean yu
2026-02-05 13:30:34 -05:00
committed by GitHub
parent 85194b499f
commit 932e23af03
3 changed files with 28 additions and 0 deletions
+10
View File
@@ -21,6 +21,16 @@
go get -u github.com/pion/mediadevices go get -u github.com/pion/mediadevices
``` ```
### Build Tags
`mediadevices` provides a `nomicrophone` build tag. Use this tag to build without microphone support. This is particularly useful for:
- Cross-compilation where CGO dependencies like `malgo` are unavailable.
- Projects where audio is not required.
```bash
go build -tags nomicrophone
```
### Usage ### Usage
The following snippet shows how to capture a camera stream and store a frame as a jpeg image: The following snippet shows how to capture a camera stream and store a frame as a jpeg image:
+3
View File
@@ -1,3 +1,6 @@
//go:build !nomicrophone
// +build !nomicrophone
package microphone package microphone
import ( import (
+15
View File
@@ -0,0 +1,15 @@
//go:build nomicrophone
// +build nomicrophone
package microphone
// This stub file is used when building with the 'nomicrophone' build tag.
// Use this when cross-compiling or when malgo (miniaudio) dependencies are not available.
//
// To build without microphone support:
// go build -tags nomicrophone
//
// This is particularly useful for:
// - Cross-compilation where CGO dependencies are unavailable
// - Environments without audio system development libraries
// - Minimal builds that only need camera/video support