/
playmp3
executable file
·38 lines (35 loc) · 905 Bytes
/
playmp3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#!/usr/bin/env bash
#
# playmp3 by Hayden Schiff (oxguy3)
#
# Play an MP3 with whatever MP3 software is already installed.
# Do whatever you want with this; the license is WTFPL.
#
# Usage: playmp3 filename.mp3
# or: playmp3 /path/to/file.mp3
#
# TODO: try to add volume control
# TODO: create playogg() and playwav()
# TODO: if no MP3 software found, try to dynamically recommend software to install
player=""
declare -a players=(
"afplay" # OS X built-in
"ffplay -nodisp" # ffmpeg
"mpg123 --quiet"
"maplay"
"mplayer -really-quiet -noconsolecontrols"
"play -V1" # SoX
"cvlc --play-and-exit" # VLC curses interface
)
for p in "${players[@]}"; do
pBase=$(echo $p | cut -d' ' -f1)
if command -v $pBase >/dev/null; then
player="$p"
break
fi
done
if [ -n "$player" ]; then
$player $@
else
>&2 echo -e "\aCould not find an MP3 player"
fi