Compare commits

..

No commits in common. "66c5bb84db49acd45321da792d4b95cebe12ad82" and "7421872586c76293a533e92361994ef6cc6408da" have entirely different histories.

3 changed files with 18 additions and 68 deletions

View file

@ -2,13 +2,8 @@
## Upcoming Changes
## Version 1.3
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
Minor tweaks to help text, README.

View file

@ -31,8 +31,3 @@ Which will execute (every 5 minutes):
/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

View file

@ -26,22 +26,13 @@ void interval_notification_handle_signal(int sig) {
int play_jingle_from_file(char *player,
char **player_args,
unsigned int args_count,
char *jingle_filename,
int use_internal_file_specified) {
int pipe_filedes[2];
if (use_internal_file_specified == 0) {
char *jingle_filename) {
int jingle_fd = open(jingle_filename, O_RDONLY);
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;
}
}
switch(fork()) {
case -1:
@ -57,23 +48,10 @@ int play_jingle_from_file(char *player,
dup2(null_fd, 1);
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.
if (args_count == 0 && strcmp(player, "/usr/bin/mpv") == 0) {
if (execl(player,
player,
"--vid=no",
jingle_filename,
(char*)NULL)
== -1) {
printf("ERROR: Failed to play with player \"%s\" and jingle \"%s\"!\n",
player, jingle_filename);
if (execl(player, player, "--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);
exit(5);
}
@ -93,7 +71,7 @@ int play_jingle_from_file(char *player,
printf("ERROR: Failed to play with player \"%s\"!\n", player);
free(argvs);
close(null_fd);
exit(6);
exit(4);
}
}
@ -102,13 +80,7 @@ int play_jingle_from_file(char *player,
exit(0);
break;
default:
if (use_internal_file_specified != 0) {
close(pipe_filedes[0]);
write(pipe_filedes[1],
interval_notification_mp3,
interval_notification_mp3_len);
close(pipe_filedes[1]);
}
// Intentionally left blank.
break;
}
@ -116,7 +88,8 @@ int play_jingle_from_file(char *player,
}
/// 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];
if (pipe(pipe_filedes) != 0) {
puts("ERROR: Failed to play jingle: Failed to create pipe!");
@ -143,12 +116,7 @@ int play_jingle_from_memory(void) {
dup2(null_fd, 2);
// Exec.
if (execl("/usr/bin/mpv",
"/usr/bin/mpv",
"--vid=no",
"-",
(char*)NULL)
== -1) {
if (execl("/usr/bin/mpv", "/usr/bin/mpv", "--vid=no", "-", (char*)NULL) == -1) {
printf("ERROR: Failed to play!\n");
close(pipe_filedes[0]);
close(null_fd);
@ -162,9 +130,7 @@ int play_jingle_from_memory(void) {
break;
default:
close(pipe_filedes[0]);
write(pipe_filedes[1],
interval_notification_mp3,
interval_notification_mp3_len);
write(pipe_filedes[1], jingle_data, jingle_size);
close(pipe_filedes[1]);
break;
}
@ -190,7 +156,6 @@ int main(int argc, char **argv) {
char *player_name = NULL;
char **player_args = NULL;
unsigned int args_count = 0;
int use_internal_file_specified = 0;
if (argc == 1) {
// Intentionally left blank.
@ -228,13 +193,8 @@ int main(int argc, char **argv) {
}
if (file_name) {
if (strcmp(file_name, "INTERNAL_FILE") == 0) {
puts("Using internal file...");
use_internal_file_specified = 1;
} else {
printf("Using file \"%s\"...\n", file_name);
}
}
// Setup for loop
is_running = 1;
@ -261,10 +221,10 @@ int main(int argc, char **argv) {
player_name : DEFAULT_FILE_PLAYER_PROGRAM,
player_args,
args_count,
file_name,
use_internal_file_specified);
file_name);
} else {
ret = play_jingle_from_memory();
ret = play_jingle_from_memory(interval_notification_mp3,
interval_notification_mp3_len);
}
if (ret != 0) {
printf("ERROR: Failed to play jingle! (returned \"%i\")\n", ret);