Home of the Squeezebox™ & Transporter® network music players.
Results 1 to 6 of 6
  1. #1
    Senior Member
    Join Date
    Jul 2010
    Location
    Oz
    Posts
    497

    LMS & time/timer/timing

    Hi.

    I have 2 questions related to the server and time/timing:

    #1
    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?


    #2
    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?

    Thank you.
    For bug reports, FAQ (if available) and more detailed information about my plugins, please see the GitHub page or the first post in the support thread for a plugin. Please post bug reports for my plugins only on GitHub. Thank you.

  2. #2
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,776

    LMS & time/timer/timing

    > 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/slimserv...tils/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.

  3. #3
    Senior Member
    Join Date
    Jul 2010
    Location
    Oz
    Posts
    497
    Quote Originally Posted by mherger View Post
    > 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/slimserv...tils/Timers.pm
    I use timers just the way you describe here and below (incl. preventing multiple timers for the same event) in some of my plugins.
    I guess, looking at alarms, I'd hoped that I could 'outsource' all of the time keeping to LMS, more or less like alarms work but without clients. I'll set my own timer then.

    Quote Originally Posted by mherger View Post
    > 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.
    I was reading about syncing lyrics display to songs (in a browser). You'd have some sort of subtitle file (e.g. Aegisub) that includes the exact time code (often up to the ms) for when a (partial) lyrics string should be displayed.
    So if timers are the only way, I guess you'd have to parse all time markers and corresponding lyrics strings from the subtitle file and then set a timer, display lyrics string, set next timer... Unless you know another way.
    Last edited by AF1; 2022-08-06 at 05:32.
    For bug reports, FAQ (if available) and more detailed information about my plugins, please see the GitHub page or the first post in the support thread for a plugin. Please post bug reports for my plugins only on GitHub. Thank you.

  4. #4
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,776

    LMS & time/timer/timing

    > I use timers just the way you describe here and below (incl. preventing
    > multiple timers for the same event) in some of my plugins.
    > I guess, looking at alarms, I'd hoped that I could 'outsource' *all* of
    > the time keeping to LMS, more or less like alarms work but without
    > clients. I'll set my own timer then.


    Back in the days when we were still actively developing LMS we actually
    considered implementing a more dev firendlyframework for scheduled tasks.

    > I was reading about syncing lyrics display to songs (in a browser).
    > You'd have some sorft of subtitle file (e.g. Aegisub) that includes the
    > exact time code (often up to the ms) for when a (partial) lyrics string
    > should be displayed.
    > So if timers are the only way, I guess you'd have to parse all time
    > markers and corresponding lyrics strings from the subtitle file and then
    > set a timer, display lyrics string, set next timer... Unless you know
    > another way.


    But you'd need that information on the frontend anyway, not the server?
    You can't push the updates from the server to the browser.

  5. #5
    Senior Member
    Join Date
    Jul 2010
    Location
    Oz
    Posts
    497
    Quote Originally Posted by mherger View Post
    But you'd need that information on the frontend anyway, not the server?
    You can't push the updates from the server to the browser.
    JS would have to handle most things. Since syncing the display of lyrics in a browser page to the time elapsed on a client is a time-sensitive matter, a web page in the browser would also have to know in time about events like newsong, pause, play/resume... how┐ Unless I'm wrong, it seems that even the default skin is "only" refreshed every x seconds or does it get notified of these server events? Sounds weird but I'm goint to ask anyway: can a web page subscribe to LMS server events?
    BTW can you recommend a documentation on the Ext JS Library that LMS uses if there is any? Haven't really had to use it before. Just curious. Not sure it plays a part here. Thank you.
    For bug reports, FAQ (if available) and more detailed information about my plugins, please see the GitHub page or the first post in the support thread for a plugin. Please post bug reports for my plugins only on GitHub. Thank you.

  6. #6
    Babelfish's Best Boy mherger's Avatar
    Join Date
    Apr 2005
    Location
    Switzerland
    Posts
    20,776

    LMS & time/timer/timing

    > seems that even the default skin is "only" refreshed every x seconds or
    > does it get notified of these server events? Sounds weird but I'm goint


    That's correct, it's polling every five seconds, IIRC.

    > to ask anyway: can a web page subscribe to LMS server events?


    Yes, nowadays that's possible. I always wanted to add this to the
    Default skin... but never did it. I think Material skin does it.

    It's using long-polling: eg. the server wouldn't hang up the connection
    once it has sent a response, but leaves it open, so the server can send
    more data back. Once it hangs up, the browser would immediately
    re-connect. That was state of the art a decade or more back :-).
    Nowadays websockets are the standard way to do this kind of things. But
    LMS doesn't support it, and adding support for it seems to be non-trivial.

    > BTW can you recommend a documentation on the -Ext JS Library- that LMS
    > uses if there is any? Haven't really had to use it before. Just curious.
    > Not sure it plays a part here. Thank you.


    https://docs.sencha.com/extjs/4.2.2/#!/api

    But what you'd probably want is to look into "SqueezeJS"
    (https://wiki.slimdevices.com/index.php/SqueezeJS.html), the library I
    wrote on top of ExtJS to create the Default skin. The documention
    obviously is mostly inexistent... but the code is your friend! The
    framework defines a few events to which you can subscribe:

    https://github.com/Logitech/slimserv...JS/Base.js#L59

    There's eg. `playtimeupdate`. If you subscribed to it you could update
    your content whenever the playtime changes. Obviously this will suffer
    from some lag in case the polling rate was too slow. But in many cases
    it's good enough anyway. 'playerstatechange' or 'playlistchange' might
    be of interest, too. If you search around the JS source in LMS you'll
    find use cases for these you can learn from.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •