Add support for changing the MP3 audio player through the ESV_PLAYER environment variable

This commit is contained in:
Jeremy Baxter 2023-03-27 13:32:18 +13:00
parent 3751040fe0
commit 0147fe1c60
2 changed files with 19 additions and 7 deletions

14
esv.1
View file

@ -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

12
main.d
View file

@ -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