diff --git a/output/driver-pulseaudio.go b/output/driver-pulseaudio.go index e7e95c2b..1ce57bba 100644 --- a/output/driver-pulseaudio.go +++ b/output/driver-pulseaudio.go @@ -28,7 +28,13 @@ func newPulseAudioOutput(opts *NewOutputOptions) (*pulseAudioOutput, error) { // The device name is shown by PulseAudio volume controls (usually built // into a desktop environment), so we might want to use device_name here. // We could also maybe change the application icon name by device_type. - client, err := pulse.NewClient(pulse.ClientApplicationName("go-librespot"), pulse.ClientApplicationIconName("speaker")) + clientopts := []pulse.ClientOption{pulse.ClientApplicationName("go-librespot"), pulse.ClientApplicationIconName("speaker")} + + if opts.RuntimeSocket != "" { + clientopts = append(clientopts, pulse.ClientServerString(opts.RuntimeSocket)) + } + + client, err := pulse.NewClient(clientopts...) if err != nil { return nil, err } @@ -43,11 +49,12 @@ func newPulseAudioOutput(opts *NewOutputOptions) (*pulseAudioOutput, error) { // Create a new playback. var channelOpt pulse.PlaybackOption - if opts.ChannelCount == 1 { + switch opts.ChannelCount { + case 1: channelOpt = pulse.PlaybackMono - } else if opts.ChannelCount == 2 { + case 2: channelOpt = pulse.PlaybackStereo - } else { + default: return nil, fmt.Errorf("cannot play %d channels, pulse only supports mono and stereo", opts.ChannelCount) } volumeUpdates := make(chan proto.ChannelVolumes, 1) diff --git a/output/output.go b/output/output.go index 6a368257..7661cb52 100644 --- a/output/output.go +++ b/output/output.go @@ -57,8 +57,13 @@ type NewOutputOptions struct { // Device specifies the audio device name. // - // This feature is support only for the alsa backend. + // This feature is support only for the alsa and pulseaudio backend. Device string + // RuntimeSocket specifies a prefixed with protocol (e.g. `unix:` or `tcp:`) path + // to a runtime socket of audio backend. + // + // This feature is support only for pulseaudio backend. + RuntimeSocket string // Mixer specifies the audio mixer name. // diff --git a/player/player.go b/player/player.go index 8af38587..204a21be 100644 --- a/player/player.go +++ b/player/player.go @@ -114,9 +114,14 @@ type Options struct { // AudioBackend specifies the audio backend to use (alsa, pulseaudio, etc). AudioBackend string + // AudioRuntimeSocket specifies a prefixed with protocol (e.g. `unix:` or `tcp:`) path + // to a runtime socket of audio backend. + // + // This feature is support only for the pulseaudio backend. + AudioBackendRuntimeSocket string // AudioDevice specifies the audio device name. // - // This feature is support only for the alsa backend. + // This feature is support only for the alsa and pulseaudio backend. AudioDevice string // MixerDevice specifies the audio mixer name. // @@ -126,7 +131,6 @@ type Options struct { // // This only works in combination with Mixer. MixerControlName string - // AudioBufferTime is the buffer time in microseconds. // // This is only supported on the alsa backend. @@ -178,6 +182,7 @@ func NewPlayer(opts *Options) (*Player, error) { SampleRate: SampleRate, ChannelCount: Channels, Device: opts.AudioDevice, + RuntimeSocket: opts.AudioBackendRuntimeSocket, Mixer: opts.MixerDevice, Control: opts.MixerControlName, InitialVolume: volume,