Re: LMS & time/timer/timing

Michael Herger <slim-b/[email protected]> Sat, 6 Aug 2022 13:30:46 +0200
Newsgroups gmane.music.equipment.slimdevices.devel
Message-ID <[email protected]>
> I'd like to *trigger a function at a _specific_ time*: hh:mm - accurate
> to the minute is all I need. I know you can set alarms for clients. But
> how would I do that server-side *without* clients?

Server-side you can use Slim::Utils::Timers::setTimer() to execute some 
code at a given time. You'll have to calculate the execution time 
yourself as epochtime: date()+secondsToWantedTime. See 
https://github.com/Logitech/slimserver/blob/public/8.3/Slim/Utils/Timers.pm

> If a plugin requires the exact/*accurate* playback time (i.e. *time
> elapsed*) of a *song on a client*, not just once but *continuously*, I
> could start a timer with the plugin when a song starts on a client
> though I don't know how accurate/synced that would be. Is there any
> other way to do this?

Please define "continuously": do you need it every second? More than 
once a second? As you might know LMS is single-threaded. You can't run 
this in a loop or something.

But you could again use a timer. setHighTimer() allows you to use more 
granular resolution than 1s. This then could call 
Slim::Player::Source::songTime($client) to get a client's playtime.

It's good practice to kill all timers for any given event when the event 
handler is called. This is to prevent multiple timers for the same event 
to happen. And then, when you're done processing whatever you need, you 
set a new timer for the next execution.

If that's not what you're looking for, then you might describe in a 
larger picture what you're trying to do.