Skip to content

Conversation

ishbosamiya
Copy link
Contributor

Changes

  • Add support for operating system level media controls

    • Uses souvlaki crate to add cross platform support for OS media controls. Information such as song metadata, play, pause and volume is shared between OS and tunein-cli.
    • User can use --enable-os-media-controls false command line argument to disable OS media controls, is on by default.
  • Add --poll-events-every and --poll-events-every-while-paused CLI arguments to reduce resource consumption

    • Allows specifying milliseconds to wait before polling for events during play and paused situations.
    • Helps reduce resource consumption with the trade off being responsiveness and animation smoothness.
      • Non scientific testing, CPU single thread consumption dropped from ~40% to ~6% during playback and from ~100% to ~4% when paused with no noticeable difference in responsiveness.
    • Defaults are picked as 16ms and 100ms respectively to ensure smooth animation (~60 FPS) and responsiveness while not wasting compute resources.
    • NOTE: waiting for an event with a timeout does not affect audio playback since it is running on a separate thread.
  • Fixed panic caused due to player thread returning before main thread
    There was an unwrap() on a channel receiver that receives from player thread. So when closing the program, if the player thread exits earlier, it would panic on the unwrap().

Note

  • Only tested on Linux, specifically Debian GNU/Linux 12 (bookworm) x86_64, kernel 6.1.0-37-amd64

    • In theory, macOS should also be supported but see TODO which indicates that without a winit (like) event loop it might not be possible to have it. I don't have a macOS system to test it on.
    • Windows is explicitly not supported due to requiring a window open to initialize any media controls. It might be possible to get the window of the terminal and use that to establish the OS media controls. Since I don't have a system to test it on at the moment, haven't added support for it.
  • Look into termion dependency, it appears to be unused but might prevent compilation on Windows.

  • It might make sense to introduce a config file instead of using only command line arguments.
    Number of user adjustable parameters is only growing, so having a config file would be better.

Setup the [`OsMediaControls`], process the ones reported by the OS.
Allow user to decide if OS media controls should be enabled.
If thread is not put to sleep, it would spin continuously and thus
consume a lot of resources. This prevents that.
… thread

It is possible that the player thread returns before this thread has a
chance to, this would mean that the sender is dropped and thus the
`recv()` would return an `Err`. Since this is the only time an `Err`
would be produced, it is safe to return from this function instead of
hoping it might be able to receive a frame again and thus continuing
within the function.
Allow user to decide how often events are polled. This helps reduce
resource consumption while still providing smooth playback and user
decides which one they prefer.
@tsirysndr
Copy link
Owner

LGTM 👍
Yeah, I agree, a separate PR for adding config support (TOML would be a good fit) makes sense. That way we can move away from relying only on CLI args as more adjustable parameters get added

@tsirysndr tsirysndr merged commit 3a89672 into tsirysndr:main Aug 15, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants