Compare commits

..

1 Commits

Author SHA1 Message Date
e38f103b82 mpv: Delays the fade in after enable returns
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/tag Build is passing
2024-10-01 19:32:55 +02:00
6 changed files with 84 additions and 102 deletions

2
app.go
View File

@ -73,7 +73,7 @@ func (app *App) loadCustomSources() error {
if newss, ok := sources.LoadableSources[csrc.Source]; !ok {
return fmt.Errorf("Unable to load source #%d: %q: no such source registered", id, csrc.Source)
} else {
src, err := newss.LoadSource(csrc.KV)
src, err := newss(csrc.KV)
if err != nil {
return fmt.Errorf("Unable to load source #%d (%s): %w", id, csrc.Source, err)
}

View File

@ -9,8 +9,8 @@ import (
)
type CustomSource struct {
Source string `json:"src"`
KV map[string]interface{} `json:"kv"`
Source string `json:"src"`
KV map[string]string `json:"kv"`
}
type Settings struct {

View File

@ -1,8 +1,6 @@
package sources
import (
"encoding/json"
)
import ()
var (
LoadableSources = map[string]LoadaleSource{}
@ -21,17 +19,4 @@ type PlayingSource interface {
CurrentlyPlaying() string
}
type LoadaleSource struct {
LoadSource func(map[string]interface{}) (SoundSource, error)
Description string
SourceDefinition interface{}
}
func Unmarshal(in map[string]interface{}, out interface{}) error {
jin, err := json.Marshal(in)
if err != nil {
return err
}
return json.Unmarshal(jin, out)
}
type LoadaleSource func(map[string]string) (SoundSource, error)

View File

@ -1,12 +1,12 @@
package mpv
import (
"errors"
"fmt"
"log"
"os"
"os/exec"
"path"
"strings"
"time"
"github.com/DexterLB/mpvipc"
@ -17,23 +17,31 @@ import (
type MPVSource struct {
process *exec.Cmd
ipcSocketDir string
Name string `json:"name"`
Options []string `json:"opts"`
File string `json:"file"`
Name string
Options []string
File string
}
func init() {
sources.LoadableSources["mpv"] = sources.LoadaleSource{
LoadSource: NewMPVSource,
Description: "Play any file, stream or URL through mpv",
SourceDefinition: &MPVSource{},
}
sources.LoadableSources["mpv"] = NewMPVSource
}
func NewMPVSource(kv map[string]interface{}) (sources.SoundSource, error) {
func NewMPVSource(kv map[string]string) (sources.SoundSource, error) {
var s MPVSource
err := sources.Unmarshal(kv, &s)
return &s, err
if name, ok := kv["name"]; ok {
s.Name = name
}
if opts, ok := kv["opts"]; ok {
s.Options = strings.Split(opts, " ")
}
if file, ok := kv["file"]; ok {
s.File = file
}
return &s, nil
}
func (s *MPVSource) GetName() string {
@ -67,23 +75,13 @@ func (s *MPVSource) Enable() (err error) {
s.process = exec.Command("mpv", opts...)
if err = s.process.Start(); err != nil {
log.Println("Unable to launch mpv:", err.Error())
return
}
go func() {
err := s.process.Wait()
if err != nil {
var exiterr *exec.ExitError
if errors.As(err, &exiterr) {
if exiterr.ExitCode() > 0 {
log.Printf("mpv exited with error code = %d", exiterr.ExitCode())
} else {
log.Print("mpv exited successfully")
}
} else {
s.process.Process.Kill()
}
s.process.Process.Kill()
}
if s.ipcSocketDir != "" {
@ -108,7 +106,6 @@ func (s *MPVSource) Enable() (err error) {
err = conn.Open()
}
if err != nil {
log.Println("Unable to connect to mpv socket:", err.Error())
return err
}
defer conn.Close()
@ -123,23 +120,24 @@ func (s *MPVSource) Enable() (err error) {
err = conn.Set("pause", false)
if err != nil {
log.Println("Unable to unpause:", err.Error())
return err
}
var pfc interface{}
pfc, err = conn.Get("core-idle")
for err == nil && pfc.(bool) {
time.Sleep(250 * time.Millisecond)
pfc, err = conn.Get("core-idle")
}
if err == nil && pfc.(bool) {
go func() {
for err == nil && pfc.(bool) {
time.Sleep(250 * time.Millisecond)
pfc, err = conn.Get("core-idle")
}
if err != nil {
log.Println("Unable to retrieve core-idle status:", err.Error())
s.FadeIn(conn, 3, 50)
}()
} else {
s.FadeIn(conn, 3, 50)
}
s.FadeIn(conn, 3, 50)
}
return

View File

@ -1,17 +1,15 @@
<script>
import '../hathoris.scss';
import '../hathoris.scss'
import "bootstrap-icons/font/bootstrap-icons.css";
import { activeSources, sources } from '$lib/stores/sources';
import { sources } from '$lib/stores/sources';
sources.refresh();
setInterval(sources.refresh, 5000);
import { activeInputs, inputs } from '$lib/stores/inputs';
import { inputs } from '$lib/stores/inputs';
inputs.refresh();
setInterval(inputs.refresh, 4500);
import SourceSelection from '$lib/components/SourceSelection.svelte';
const version = fetch('api/version', {headers: {'Accept': 'application/json'}}).then((res) => res.json())
</script>
@ -20,50 +18,7 @@
</svelte:head>
<div class="flex-fill d-flex flex-column">
<div class="container-fluid flex-fill d-flex flex-column justify-content-start">
<div class="my-3">
<SourceSelection />
</div>
{#if $activeSources.length === 0 && $activeInputs.length === 0}
<div class="text-muted text-center mt-1 mb-1">
Aucune source active pour l'instant.
</div>
{:else}
<marquee>
{#each $activeSources as source}
<div class="d-inline-block me-3">
<div class="d-flex justify-content-between align-items-center">
<div>
{#if source.currentTitle}
<strong>{source.currentTitle}</strong> <span class="text-muted">@ {source.name}</span>
{:else}
{source.name} activée
{/if}
</div>
</div>
</div>
{/each}
{#each $activeInputs as input}
<div class="d-inline-block me-3">
<div class="d-flex justify-content-between align-items-center">
<div>
{#if input.streams.length}
{#each Object.keys(input.streams) as idstream}
{@const title = input.streams[idstream]}
<strong>{title}</strong>
{/each}
<span class="text-muted">@ {input.name}</span>
{:else}
{input.name} activée
{/if}
</div>
</div>
</div>
{/each}
</marquee>
{/if}
<div class="container-fluid flex-fill d-flex flex-column justify-content-center">
<slot></slot>
</div>
</div>

View File

@ -2,6 +2,7 @@
import Applications from '$lib/components/Applications.svelte';
import Inputs from '$lib/components/Inputs.svelte';
import Mixer from '$lib/components/Mixer.svelte';
import SourceSelection from '$lib/components/SourceSelection.svelte';
import { activeSources } from '$lib/stores/sources';
import { activeInputs } from '$lib/stores/inputs';
@ -9,7 +10,50 @@
let showInactiveInputs = false;
</script>
<div class="my-3">
<SourceSelection />
</div>
<div class="container">
{#if $activeSources.length === 0 && $activeInputs.length === 0}
<div class="text-muted text-center mt-1 mb-1">
Aucune source active pour l'instant.
</div>
{:else}
<marquee>
{#each $activeSources as source}
<div class="d-inline-block me-3">
<div class="d-flex justify-content-between align-items-center">
<div>
{#if source.currentTitle}
<strong>{source.currentTitle}</strong> <span class="text-muted">@ {source.name}</span>
{:else}
{source.name} activée
{/if}
</div>
</div>
</div>
{/each}
{#each $activeInputs as input}
<div class="d-inline-block me-3">
<div class="d-flex justify-content-between align-items-center">
<div>
{#if input.streams.length}
{#each Object.keys(input.streams) as idstream}
{@const title = input.streams[idstream]}
<strong>{title}</strong>
{/each}
<span class="text-muted">@ {input.name}</span>
{:else}
{input.name} activée
{/if}
</div>
</div>
</div>
{/each}
</marquee>
{/if}
<div class="row">
<div class="col-md">
<div class="card my-3">