From 0147fe1c60977cef639503a957201c09c05ec717 Mon Sep 17 00:00:00 2001 From: Jeremy Baxter Date: Mon, 27 Mar 2023 13:32:18 +1300 Subject: [PATCH] Add support for changing the MP3 audio player through the ESV_PLAYER environment variable --- esv.1 | 14 ++++++++++++-- main.d | 12 +++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/esv.1 b/esv.1 index 0dea3c7..6ec92ab 100644 --- a/esv.1 +++ b/esv.1 @@ -18,11 +18,16 @@ is a program that displays passages of the Bible on your terminal. It can also play recorded audio tracks of certain passages, through integration with the .Xr mpg123 1 -utility. +utility. While audio is playing, you can use the standard mpg123 +controls: spacebar to pause/resume, comma to rewind, period +to fast-forward, etc. Read about the +.Fl C +option in mpg123's manual for more information. +.Pp If a text passage is too long for standard display on a terminal, .Nm will put it through a text pager (default less) in order for you to be able to -scroll through the text with ease. This behaviour can be disabled by passing +scroll through the text. This behaviour can be disabled by passing the .Fl P flag. @@ -73,6 +78,11 @@ What pager to use when the passage is over 32 lines long, rather than using the .Ic less utility. +.It Ev ESV_PLAYER +What MP3 player to use for playing audio, rather than using mpg123. +Using mpg123 is recommended over other players such as mpv, because +mpv's controls don't work well when started by another process +for some reason. .Sh FILES .Bl -tag -width ~/.config/esv.conf .It Pa ~/.config/esv.conf diff --git a/main.d b/main.d index 123db09..8e95f2e 100644 --- a/main.d +++ b/main.d @@ -38,6 +38,7 @@ enum DEFAULT_PAGER = "less"; enum ENV_CONFIG = "ESV_CONFIG"; enum ENV_PAGER = "ESV_PAGER"; +enum ENV_PLAYER = "ESV_PLAYER"; bool optAudio; string optConfigPath; @@ -175,14 +176,15 @@ int main(string[] args) return 1; } else { string tmpf = esv.getAudioVerses(args[1], args[2]); - string mpegPlayer; + string mpegPlayer = environment.get(ENV_PLAYER, DEFAULT_MPEGPLAYER); // esv has built-in support for mpg123 and mpv // other players will work, just recompile with // the DEFAULT_MPEGPLAYER enum set differently - if (DEFAULT_MPEGPLAYER == "mpg123") - mpegPlayer = DEFAULT_MPEGPLAYER ~ " -q "; - else if (DEFAULT_MPEGPLAYER == "mpv") - mpegPlayer = DEFAULT_MPEGPLAYER ~ " --msg-level=all=no "; + // or use the ESV_PLAYER environment variable + if (mpegPlayer == "mpg123") + mpegPlayer = mpegPlayer ~ " -q "; + else if (mpegPlayer == "mpv") + mpegPlayer = mpegPlayer ~ " --msg-level=all=no "; else mpegPlayer = DEFAULT_MPEGPLAYER ~ " "; // spawn mpg123