Improve encoding conversion code
[oggquiz.git] / player.c
blobcf5419beec5423856718f6b29062cc6d46cf139a
1 /*-
2 * "THE BEER-WARE LICENSE" (Revision 42):
3 * <tobias.rehbein@web.de> wrote this file. As long as you retain this notice
4 * you can do whatever you want with this stuff. If we meet some day, and you
5 * think this stuff is worth it, you can buy me a beer in return.
6 * Tobias Rehbein
7 */
9 #include <unistd.h>
10 #include <signal.h>
11 #include <err.h>
12 #include <sys/types.h>
13 #include "common.h"
14 #include "oggfile.h"
15 #include "player.h"
16 #include "oggquiz.h"
18 /* Global variables */
19 extern options_t options;
20 static pid_t pid = (pid_t) (-1);
22 void
23 player_play(oggfile_t *oggfile)
25 pid_t lpid;
27 player_stop();
29 switch (lpid = fork()) {
30 case (0):
31 execl(options.ogg123, "ogg123", "-q", oggfile->filename, NULL);
32 err(1, "could not exec %s", options.ogg123);
33 case (-1):
34 err(1, "could not fork player");
35 default:
36 pid = lpid;
37 return;
41 void
42 player_stop()
44 if (pid != (pid_t) (-1)) {
45 if (kill(pid, SIGHUP))
46 err(1, "could not kill running player");
47 pid = -1;