Last active
December 14, 2015 03:18
-
-
Save Shinpeim/5019615 to your computer and use it in GitHub Desktop.
https://github.com/moznion/App--Prove--WithSound/blob/master/prove-with-sound これ、どんなコマンドでもいいようにしてみた
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env perl | |
use strict; | |
use warnings; | |
use Audio::Play::MPG123; | |
use Config::Simple; | |
use File::Spec::Functions qw/catfile/; | |
sub load_config { | |
my $config = Config::Simple->new( catfile( $ENV{HOME}, '.with-soundrc' ) ); | |
return $config->param('SUCCESS'), $config->param('FAILURE'); | |
} | |
sub play_mp3 { | |
my ($mp3_file) = @_; | |
my $pid = fork; | |
die "fork failed." unless defined $pid; | |
if ( $pid == 0 ) { | |
my $player = Audio::Play::MPG123->new; | |
$player->load( glob $mp3_file ); | |
$player->poll(1) until $player->state == 0; | |
} | |
} | |
my ( $success_sound, $failure_sound ) = load_config; | |
my $retval = system(@ARGV); | |
if ($retval == 0) { | |
# success | |
play_mp3( glob $success_sound ); | |
} | |
else { | |
# error | |
play_mp3( glob $failure_sound ); | |
} | |
exit($retval); | |
__END__ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment