Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit to single simultaneous play #46

Open
asim215 opened this issue Mar 28, 2022 · 2 comments
Open

Limit to single simultaneous play #46

asim215 opened this issue Mar 28, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@asim215
Copy link

asim215 commented Mar 28, 2022

Hello. Is it possible to limit to amount of started instances of player to single one? So I don't need to terminate (using htop) when I start many of them.

Start episode 1 (run player). Start episode 2 (if instance of player exist then terminate previous and start with file #2).

In my case player is mpv.

@jeff-hughes
Copy link
Owner

Given how shellcaster is set up, right now it's entirely agnostic to what command is used to play the media files. So there's not a particularly easy way to build this sort of thing in, though I can appreciate how it would be useful.

I was going to suggest changing the play_command option in the config file to something like "pkill mpv && mpv %s". However, when testing it I realized that I don't have it set up in a way where it properly interprets the &&. (It just treats mpv && mpv %s as arguments to pkill.)

I'll add it to the list of things to add; I think it would be useful to have the ability to set up some chains of commands like this.

@jeff-hughes jeff-hughes added the enhancement New feature or request label Mar 30, 2022
@a-kenji
Copy link
Contributor

a-kenji commented Apr 1, 2022

Hey! Yes, that is possible. Here is part of a script I use I save it as toggle_mpv_socket:

#!/usr/bin/env bash

# socat, mpv, jq

SOCKETNAME="/tmp/mpvsocket"

_toggle(){
    echo '{"command":["cycle","pause"]}' \
        | socat - "$SOCKETNAME" >/dev/null
}
_quit(){
    echo '{"command":["quit"]}' \
        | socat - "$SOCKETNAME" >/dev/null
}

_is_playing(){
    PATH=$(echo '{"command": ["get_property", "path"]}' \
    | socat - "$SOCKETNAME" \
    | jq '.data')

    # remove quotes
    PATH="${PATH%\"}"
    PATH="${PATH#\"}"

    if [ "$PATH" = "$1" ];then
        echo 0
    else
        echo 1
    fi
}

_start_mpv() {
    mpv \
    --x11-name=mpv_shellcaster \
    --title=mpv_shellcaster \
    --input-ipc-server="$SOCKETNAME" \
    "$1" \
    &
}

main() {
if [[ $(_is_playing "$1") = 0 ]];then
    _toggle
else
    _quit
    _start_mpv "$1"
fi
}

main "$@"

Now we can change the play command to play_command= "toggle_mpv_socket %s"

That way, if you hit play on the same podcast it toggles between play and pause, if you start a different podcast it kills the specific mpv instance and starts a new one. I also suggest adding saving the position to your configuration, that way if you go back to a podcast you already started it starts playing where you left off.

Sadly in addition to socat and mpv, this depends on jq, but that could be mitigated. I just found it the easiest solution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants