Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed get volume for pulseaudio

  • Loading branch information...
commit 2f0640f8b6be9d4941eab69a41fcb0f607f40caa 1 parent 3f99100
@msoap authored
Showing with 20 additions and 8 deletions.
  1. +10 −4 mojolicious-radio-box.pl
  2. +5 −3 src/cmus-client.pm
  3. +5 −1 src/util.pm
View
14 mojolicious-radio-box.pl
@@ -53,7 +53,11 @@ sub init {
# get default sound card for pulseaudio
if ($OPTIONS{is_pulseaudio} && ! defined $OPTIONS{"pa-default-sink"}) {
$OPTIONS{"pa-default-sink"} = `pacmd dump | grep set-default-sink | awk '{print \$2}'`;
- $OPTIONS{"pa-default-sink"} = "0" unless defined $OPTIONS{"pa-default-sink"} && length($OPTIONS{"pa-default-sink"}) > 0;
+ if (defined $OPTIONS{"pa-default-sink"} && length($OPTIONS{"pa-default-sink"}) > 0) {
+ chomp $OPTIONS{"pa-default-sink"};
+ } else {
+ $OPTIONS{"pa-default-sink"} = "0";
+ }
}
}
@@ -150,9 +154,11 @@ sub cmus_get_info {
$info->{volume} = int(`osascript -e "output volume of (get volume settings)"`);
} elsif ($OPTIONS{is_pulseaudio}) {
my ($pa_info) = grep {/set-sink-volume/ && /\Q$OPTIONS{"pa-default-sink"}\E/} `pacmd dump`;
- $pa_info =~ /\s+ ([0-9a-fx]+) \s* $/xi;
- if (defined $1 && hex($1) >= 0) {
- $info->{volume} = int(sprintf("%0.0f", hex($1) / 65536 * 100));
+ if (defined $pa_info) {
+ $pa_info =~ /\s+ ([0-9a-fx]+) \s* $/xi;
+ if (defined $1 && hex($1) >= 0) {
+ $info->{volume} = int(sprintf("%0.0f", hex($1) / 65536 * 100));
+ }
}
} elsif ($OPTIONS{is_alsa}) {
my $alsa_info = join "#", grep {/Front\s+(Left|Right):\s+Playback/} `amixer get Master`;
View
8 src/cmus-client.pm
@@ -42,9 +42,11 @@ sub cmus_get_info {
$info->{volume} = int(`osascript -e "output volume of (get volume settings)"`);
} elsif ($OPTIONS{is_pulseaudio}) {
my ($pa_info) = grep {/set-sink-volume/ && /\Q$OPTIONS{"pa-default-sink"}\E/} `pacmd dump`;
- $pa_info =~ /\s+ ([0-9a-fx]+) \s* $/xi;
- if (defined $1 && hex($1) >= 0) {
- $info->{volume} = int(sprintf("%0.0f", hex($1) / 65536 * 100));
+ if (defined $pa_info) {
+ $pa_info =~ /\s+ ([0-9a-fx]+) \s* $/xi;
+ if (defined $1 && hex($1) >= 0) {
+ $info->{volume} = int(sprintf("%0.0f", hex($1) / 65536 * 100));
+ }
}
} elsif ($OPTIONS{is_alsa}) {
my $alsa_info = join "#", grep {/Front\s+(Left|Right):\s+Playback/} `amixer get Master`;
View
6 src/util.pm
@@ -21,7 +21,11 @@ sub init {
# get default sound card for pulseaudio
if ($OPTIONS{is_pulseaudio} && ! defined $OPTIONS{"pa-default-sink"}) {
$OPTIONS{"pa-default-sink"} = `pacmd dump | grep set-default-sink | awk '{print \$2}'`;
- $OPTIONS{"pa-default-sink"} = "0" unless defined $OPTIONS{"pa-default-sink"} && length($OPTIONS{"pa-default-sink"}) > 0;
+ if (defined $OPTIONS{"pa-default-sink"} && length($OPTIONS{"pa-default-sink"}) > 0) {
+ chomp $OPTIONS{"pa-default-sink"};
+ } else {
+ $OPTIONS{"pa-default-sink"} = "0";
+ }
}
}
Please sign in to comment.
Something went wrong with that request. Please try again.