Handle muting streams
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing

This commit is contained in:
nemunaire 2023-11-15 12:10:32 +01:00
parent bfd0bb866a
commit 9926248109
2 changed files with 31 additions and 18 deletions

View File

@ -154,18 +154,18 @@ func (s *PulseaudioInput) SetMixer(stream string, volume *inputs.InputMixer) err
for _, input := range sinkinputs {
if strconv.FormatInt(input.Index, 10) == stream {
cmd := exec.Command("pactl", "set-sink-input-volume", stream, strconv.FormatUint(uint64(volume.Volume), 10))
err := cmd.Run()
if err != nil {
return fmt.Errorf("unable to set volume: %w", err)
}
if input.Mute != volume.Mute {
cmd := exec.Command("pactl", "set-sink-input-mute", stream, "toggle")
err := cmd.Run()
if err != nil {
return fmt.Errorf("unable to change mute state: %w", err)
}
} else {
cmd := exec.Command("pactl", "set-sink-input-volume", stream, strconv.FormatUint(uint64(volume.Volume), 10))
err := cmd.Run()
if err != nil {
return fmt.Errorf("unable to set volume: %w", err)
}
}
return nil

View File

@ -11,6 +11,9 @@
altering_mixer = null;
}, 450);
}
async function muteMixer(input, streamid, mute) {
fetch(`api/inputs/${input.name}/streams/${streamid}/volume`, {headers: {'Accept': 'application/json'}, method: 'POST', body: JSON.stringify({'mute': mute !== undefined ? mute : input.mixer[streamid].mute})}).then(() => inputs.refresh());
}
</script>
<ul class="list-group list-group-flush">
@ -31,24 +34,34 @@
<label for={'input' + iid + 'stream' + idstream} class="form-label d-inline">{title}</label>
<span class="text-muted">({input.name})</span>
</div>
{#if input.controlable}
<div>
<div class="d-flex align-items-center">
{#if input.mixable && input.mixer[idstream]}
<button
class="btn btn-sm btn-primary"
class="btn btn-sm ms-1"
class:btn-primary={input.mixer[idstream].mute}
class:btn-secondary={!input.mixer[idstream].mute}
on:click={() => {muteMixer(input, idstream, !input.mixer[idstream].mute);}}
>
<i class="bi bi-volume-mute-fill"></i>
</button>
{/if}
{#if input.controlable}
<button
class="btn btn-sm btn-primary ms-1"
on:click={() => input.playpause(idstream)}
>
<i class="bi bi-pause"></i>
</button>
</div>
{:else if input.mixable && input.mixer[idstream]}
<div
class="badge bg-primary"
class="badge bg-primary ms-1"
title={input.mixer[idstream].volume_percent}
>
{input.mixer[idstream].volume_db}
</div>
{/if}
</div>
</div>
{#if input.mixable && input.mixer[idstream]}
<div>
<input