From 14bbc21cf5ae12089d51c139bfabd159a1b94f29 Mon Sep 17 00:00:00 2001 From: dakkar Date: Thu, 30 Dec 2021 10:45:09 +0000 Subject: play from media list --- lib/App/MediaControl.rakumod | 1 + lib/App/MediaControl/Web.rakumod | 6 ++++++ lib/Vlc/Client.rakumod | 12 ++++++++++-- 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/App/MediaControl.rakumod b/lib/App/MediaControl.rakumod index b03e31b..82dc0dd 100644 --- a/lib/App/MediaControl.rakumod +++ b/lib/App/MediaControl.rakumod @@ -19,6 +19,7 @@ class App::MediaControl { $!vlc .= new( password => $!config, base-uri => $!config, + mrl-root => $!config, ); $!lirc-client .= new(); diff --git a/lib/App/MediaControl/Web.rakumod b/lib/App/MediaControl/Web.rakumod index c577d90..cb12783 100644 --- a/lib/App/MediaControl/Web.rakumod +++ b/lib/App/MediaControl/Web.rakumod @@ -15,6 +15,12 @@ class App::MediaControl::Web { method start() { my $vlc = route { post -> 'play' { await self.vlc.command('pl_play') } + post -> 'play', Int:D $id { + my $file = self.db.get-entry($id); + await self.vlc.play-file(|%( + $file:p # no comma! + )); + } post -> 'pause' { await self.vlc.command('pl_pause') } post -> 'stop' { await self.vlc.command('pl_stop') } diff --git a/lib/Vlc/Client.rakumod b/lib/Vlc/Client.rakumod index 3620d47..5b19c53 100644 --- a/lib/Vlc/Client.rakumod +++ b/lib/Vlc/Client.rakumod @@ -20,8 +20,9 @@ class Vlc::Client { has Cro::HTTP::Client $!vlc; has Str $.password is required; has Str $.base-uri = 'http://127.0.0.1:8080/requests/'; + has IO::Path() $.mrl-root = '/'; - method !call-vlc(Str $path, *%args) { + method !call-vlc(Str:D $path, *%args) { $!vlc ||= Cro::HTTP::Client.new( auth => { :username(), :password(self.password) }, add-body-parsers => [ Cro::BodyParser::VlcXML ], @@ -34,10 +35,17 @@ class Vlc::Client { ); } - method command(Str $command, *%args) { + method command(Str:D $command, *%args) { return self!call-vlc('status.xml', :$command, |%args); } + method play-file(Str:D :$path, Str:D :$name) { + return self.command( + 'in_play', + input => self.mrl-root.child($path).child($name), + ); + } + method status() { my $res = await self!call-vlc('status.xml'); my XML::Document $status = await $res.body; -- cgit v1.2.3