0
rated 0 times
[
0]
[
0]
/ answers: 1 / hits: 466
/ 2 Years ago, wed, march 16, 2022, 10:53:17
I have made a script that plays audio using ffplay directly onto the terminal. Now after it's executed I am unable to stop the sound without specifically killing it through the terminal or System Monitor.
What I am trying to do is to specify an argument, say audio.sh stop
to kill the PID and stop the audio.
But I am unable to do so by simply
PID=$$
elif [[ $# == 1 ]] && [[ $1 == 'stop' ]]; then
kill ${PID}
I got the problem here, that after running this with the stop argument it will create another instance of the script and then kill it instantly.
So, is there some way to do that?
Here is my full code.
1 folder=<folder path>
2
3 PID=$$
4
5 if [[ $# == 0 ]]; then
6 RANDOM=$$
7 for i in `seq 1`
8 do
9 R=$(($(($RANDOM%53))+1))
10 file=${folder}${R}.mp3
11 ffplay -nodisp -autoexit ${file} >/dev/null 2>&1 &
12 done
13 elif [[ $# == 1 ]]; then
14 file=${folder}${1}.mp3
15 ffplay -nodisp -autoexit ${file} >/dev/null 2>&1 &
16 elif [[ $# == 1 ]] && [[ $1 == 'stop' ]]; then
17 kill ${PID}
18 fi
More From » command-line