Compare commits
No commits in common. "66c5bb84db49acd45321da792d4b95cebe12ad82" and "7421872586c76293a533e92361994ef6cc6408da" have entirely different histories.
66c5bb84db
...
7421872586
3 changed files with 18 additions and 68 deletions
|
@ -2,13 +2,8 @@
|
||||||
|
|
||||||
## Upcoming Changes
|
## Upcoming Changes
|
||||||
|
|
||||||
## Version 1.3
|
|
||||||
|
|
||||||
More tweaks to README.
|
More tweaks to README.
|
||||||
|
|
||||||
Allow playing internal file even if custom player command is specified.
|
|
||||||
Do this by specifying "INTERNAL_FILE" as the filename parameter.
|
|
||||||
|
|
||||||
## Version 1.2
|
## Version 1.2
|
||||||
|
|
||||||
Minor tweaks to help text, README.
|
Minor tweaks to help text, README.
|
||||||
|
|
|
@ -31,8 +31,3 @@ Which will execute (every 5 minutes):
|
||||||
|
|
||||||
/usr/bin/ffplay -nodisp /my/music/file.mp3
|
/usr/bin/ffplay -nodisp /my/music/file.mp3
|
||||||
|
|
||||||
To play the internal file instead of a specified one, use the parameter
|
|
||||||
"INTERNAL_FILE" for the filename and break\_interval will play the internal
|
|
||||||
file.
|
|
||||||
|
|
||||||
./break_interval 5 INTERNAL_FILE /usr/bin/ffplay -nodisp
|
|
||||||
|
|
76
src/main.c
76
src/main.c
|
@ -26,22 +26,13 @@ void interval_notification_handle_signal(int sig) {
|
||||||
int play_jingle_from_file(char *player,
|
int play_jingle_from_file(char *player,
|
||||||
char **player_args,
|
char **player_args,
|
||||||
unsigned int args_count,
|
unsigned int args_count,
|
||||||
char *jingle_filename,
|
char *jingle_filename) {
|
||||||
int use_internal_file_specified) {
|
int jingle_fd = open(jingle_filename, O_RDONLY);
|
||||||
int pipe_filedes[2];
|
if (jingle_fd == -1) {
|
||||||
if (use_internal_file_specified == 0) {
|
puts("ERROR: Failed to play jingle: Failed to open file!");
|
||||||
int jingle_fd = open(jingle_filename, O_RDONLY);
|
return 2;
|
||||||
if (jingle_fd == -1) {
|
|
||||||
puts("ERROR: Failed to play jingle: Failed to open file!");
|
|
||||||
return 2;
|
|
||||||
}
|
|
||||||
close(jingle_fd);
|
|
||||||
} else {
|
|
||||||
if (pipe(pipe_filedes) != 0) {
|
|
||||||
puts("ERROR: Failed to play jingle: Failed to create pipe!");
|
|
||||||
return 7;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
close(jingle_fd);
|
||||||
|
|
||||||
switch(fork()) {
|
switch(fork()) {
|
||||||
case -1:
|
case -1:
|
||||||
|
@ -57,23 +48,10 @@ int play_jingle_from_file(char *player,
|
||||||
dup2(null_fd, 1);
|
dup2(null_fd, 1);
|
||||||
dup2(null_fd, 2);
|
dup2(null_fd, 2);
|
||||||
|
|
||||||
if (use_internal_file_specified != 0) {
|
|
||||||
// Handle pipe into stdin.
|
|
||||||
close(pipe_filedes[1]);
|
|
||||||
dup2(pipe_filedes[0], 0);
|
|
||||||
jingle_filename = "/dev/stdin";
|
|
||||||
}
|
|
||||||
|
|
||||||
// Exec.
|
// Exec.
|
||||||
if (args_count == 0 && strcmp(player, "/usr/bin/mpv") == 0) {
|
if (args_count == 0 && strcmp(player, "/usr/bin/mpv") == 0) {
|
||||||
if (execl(player,
|
if (execl(player, player, "--vid=no", jingle_filename, (char*)NULL) == -1) {
|
||||||
player,
|
printf("ERROR: Failed to play with player \"%s\" and jingle \"%s\"!\n", player, jingle_filename);
|
||||||
"--vid=no",
|
|
||||||
jingle_filename,
|
|
||||||
(char*)NULL)
|
|
||||||
== -1) {
|
|
||||||
printf("ERROR: Failed to play with player \"%s\" and jingle \"%s\"!\n",
|
|
||||||
player, jingle_filename);
|
|
||||||
close(null_fd);
|
close(null_fd);
|
||||||
exit(5);
|
exit(5);
|
||||||
}
|
}
|
||||||
|
@ -93,7 +71,7 @@ int play_jingle_from_file(char *player,
|
||||||
printf("ERROR: Failed to play with player \"%s\"!\n", player);
|
printf("ERROR: Failed to play with player \"%s\"!\n", player);
|
||||||
free(argvs);
|
free(argvs);
|
||||||
close(null_fd);
|
close(null_fd);
|
||||||
exit(6);
|
exit(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -102,13 +80,7 @@ int play_jingle_from_file(char *player,
|
||||||
exit(0);
|
exit(0);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (use_internal_file_specified != 0) {
|
// Intentionally left blank.
|
||||||
close(pipe_filedes[0]);
|
|
||||||
write(pipe_filedes[1],
|
|
||||||
interval_notification_mp3,
|
|
||||||
interval_notification_mp3_len);
|
|
||||||
close(pipe_filedes[1]);
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -116,7 +88,8 @@ int play_jingle_from_file(char *player,
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Only supports playing with /usr/bin/mpv .
|
/// Only supports playing with /usr/bin/mpv .
|
||||||
int play_jingle_from_memory(void) {
|
int play_jingle_from_memory(const char *jingle_data,
|
||||||
|
int jingle_size) {
|
||||||
int pipe_filedes[2];
|
int pipe_filedes[2];
|
||||||
if (pipe(pipe_filedes) != 0) {
|
if (pipe(pipe_filedes) != 0) {
|
||||||
puts("ERROR: Failed to play jingle: Failed to create pipe!");
|
puts("ERROR: Failed to play jingle: Failed to create pipe!");
|
||||||
|
@ -143,12 +116,7 @@ int play_jingle_from_memory(void) {
|
||||||
dup2(null_fd, 2);
|
dup2(null_fd, 2);
|
||||||
|
|
||||||
// Exec.
|
// Exec.
|
||||||
if (execl("/usr/bin/mpv",
|
if (execl("/usr/bin/mpv", "/usr/bin/mpv", "--vid=no", "-", (char*)NULL) == -1) {
|
||||||
"/usr/bin/mpv",
|
|
||||||
"--vid=no",
|
|
||||||
"-",
|
|
||||||
(char*)NULL)
|
|
||||||
== -1) {
|
|
||||||
printf("ERROR: Failed to play!\n");
|
printf("ERROR: Failed to play!\n");
|
||||||
close(pipe_filedes[0]);
|
close(pipe_filedes[0]);
|
||||||
close(null_fd);
|
close(null_fd);
|
||||||
|
@ -162,9 +130,7 @@ int play_jingle_from_memory(void) {
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
close(pipe_filedes[0]);
|
close(pipe_filedes[0]);
|
||||||
write(pipe_filedes[1],
|
write(pipe_filedes[1], jingle_data, jingle_size);
|
||||||
interval_notification_mp3,
|
|
||||||
interval_notification_mp3_len);
|
|
||||||
close(pipe_filedes[1]);
|
close(pipe_filedes[1]);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -190,7 +156,6 @@ int main(int argc, char **argv) {
|
||||||
char *player_name = NULL;
|
char *player_name = NULL;
|
||||||
char **player_args = NULL;
|
char **player_args = NULL;
|
||||||
unsigned int args_count = 0;
|
unsigned int args_count = 0;
|
||||||
int use_internal_file_specified = 0;
|
|
||||||
|
|
||||||
if (argc == 1) {
|
if (argc == 1) {
|
||||||
// Intentionally left blank.
|
// Intentionally left blank.
|
||||||
|
@ -228,12 +193,7 @@ int main(int argc, char **argv) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (file_name) {
|
if (file_name) {
|
||||||
if (strcmp(file_name, "INTERNAL_FILE") == 0) {
|
printf("Using file \"%s\"...\n", file_name);
|
||||||
puts("Using internal file...");
|
|
||||||
use_internal_file_specified = 1;
|
|
||||||
} else {
|
|
||||||
printf("Using file \"%s\"...\n", file_name);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup for loop
|
// Setup for loop
|
||||||
|
@ -261,10 +221,10 @@ int main(int argc, char **argv) {
|
||||||
player_name : DEFAULT_FILE_PLAYER_PROGRAM,
|
player_name : DEFAULT_FILE_PLAYER_PROGRAM,
|
||||||
player_args,
|
player_args,
|
||||||
args_count,
|
args_count,
|
||||||
file_name,
|
file_name);
|
||||||
use_internal_file_specified);
|
|
||||||
} else {
|
} else {
|
||||||
ret = play_jingle_from_memory();
|
ret = play_jingle_from_memory(interval_notification_mp3,
|
||||||
|
interval_notification_mp3_len);
|
||||||
}
|
}
|
||||||
if (ret != 0) {
|
if (ret != 0) {
|
||||||
printf("ERROR: Failed to play jingle! (returned \"%i\")\n", ret);
|
printf("ERROR: Failed to play jingle! (returned \"%i\")\n", ret);
|
||||||
|
|
Loading…
Reference in a new issue