This commit is contained in:
Alexander Heldt
2025-11-14 19:15:31 +01:00
parent 1dcbff3e22
commit c395a5294d
2 changed files with 26 additions and 1 deletions

16
src/mpv/mpv.gleam Normal file
View File

@@ -0,0 +1,16 @@
import tcp/reason
import tcp/tcp.{type Socket}
pub fn new() -> Result(Socket, String) {
// TODO start up mvp here, currently hi-jacking `naviterm`s socket
let socket_path = "/tmp/naviterm_mpv"
case tcp.connect(socket_path) {
Error(r) -> Error("mpv - could not connect: " <> reason.to_string(r))
Ok(socket) -> Ok(socket)
}
}
pub fn toggle_play_pause(socket: Socket) {
tcp.send(socket, "{\"command\":[\"cycle\",\"pause\"]}\n")
}

View File

@@ -1,5 +1,14 @@
import gleam/io import gleam/io
import mpv/mpv
pub fn main() -> Nil { pub fn main() -> Nil {
io.println("musicplayer") case mpv.new() {
Error(err) -> io.println("Could not create new mpv connection: " <> err)
Ok(socket) -> handle_key_events(socket)
}
}
fn handle_key_events(socket) -> Nil {
let _ = mpv.toggle_play_pause(socket)
Nil
} }