mpg321 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.semver +6 -0
- data/Gemfile +1 -3
- data/README.md +22 -0
- data/lib/mpg321.rb +24 -13
- data/lib/version.rb +1 -1
- data/spec/mpg321_spec.rb +24 -4
- data/spec/spec_helper.rb +0 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24b0ecbf200a6881e339377bad2caabcb13f1908
|
4
|
+
data.tar.gz: 0de8362c74635f4fbb074e53d5e7ba6e0afb9444
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ad6de75c72fd0c26e9469aeae21aeea785162e2535c2b8155c9f2421d87c854958be790301b79442cfe0911c2817666fde230ba8ea4e7810c1f081b42a194c32
|
7
|
+
data.tar.gz: 12cc121d53898d66c4f00e8e28d14bcc1743507d87e203cf9966672fb7f81d06e97f6c5b81f630ce3db454d23a3be0e1a78bfc1154cc8999ca7c56e2fa153312
|
data/.semver
ADDED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,15 @@
|
|
1
1
|
Mpg321
|
2
2
|
===========
|
3
3
|
|
4
|
+
[](https://travis-ci.org/RichardVickerstaff/mpg321)
|
5
|
+
[](http://badge.fury.io/rb/mpg321)
|
6
|
+
|
4
7
|
A simple ruby wrapper around mpg321
|
5
8
|
-----------------------------------
|
6
9
|
|
10
|
+
Mpg321 is a wrapper for the [mpg321][mpg321] library in "Remote control" mode, which
|
11
|
+
allows to you play, pause, stop and control the volume of mp3 files from Ruby.
|
12
|
+
|
7
13
|
Installation
|
8
14
|
------------
|
9
15
|
Either:
|
@@ -15,10 +21,26 @@ or
|
|
15
21
|
|
16
22
|
Usage
|
17
23
|
-----
|
24
|
+
Here's how you can easily play an mp3:
|
25
|
+
|
26
|
+
```ruby
|
27
|
+
require 'mpg321'
|
28
|
+
|
29
|
+
Mpg321.new.play('/some_path/song.mp3')
|
30
|
+
```
|
18
31
|
|
32
|
+
Play mutiple mp3 files:
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
require 'mpg321'
|
36
|
+
|
37
|
+
Mpg321.new.play(['/some_path/song1.mp3', '/some_path/song2.mp3'])
|
38
|
+
```
|
19
39
|
Contributing
|
20
40
|
------------
|
21
41
|
1. Make a fork
|
22
42
|
2. Make your changes
|
23
43
|
3. Push your changes to your fork
|
24
44
|
4. Create a Pull Request
|
45
|
+
|
46
|
+
[mpg321]: http://linux.die.net/man/1/mpg321
|
data/lib/mpg321.rb
CHANGED
@@ -5,38 +5,49 @@ class Mpg321
|
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@volume = 50
|
8
|
-
@
|
8
|
+
@music_input, _stdout, _stderr, _thread = Open3.popen3("mpg321 -R mpg321_ruby")
|
9
9
|
Thread.new { loop do _stderr.readline end }
|
10
10
|
Thread.new { loop do _stdout.readline end }
|
11
|
-
|
11
|
+
send_volume
|
12
12
|
end
|
13
13
|
|
14
14
|
def pause
|
15
|
-
@
|
15
|
+
@music_input.puts "P"
|
16
16
|
end
|
17
17
|
|
18
18
|
def stop
|
19
|
-
@
|
19
|
+
@music_input.puts "S"
|
20
20
|
end
|
21
21
|
|
22
22
|
def play song_list
|
23
23
|
songs = song_list.respond_to?(:join) ? song_list.join(' ') : song_list
|
24
|
-
@
|
24
|
+
@music_input.puts "L #{songs}"
|
25
25
|
end
|
26
26
|
|
27
|
-
def volume_up
|
28
|
-
@volume +=
|
27
|
+
def volume_up volume
|
28
|
+
@volume += volume
|
29
29
|
@volume = [@volume, 100].min
|
30
|
-
|
30
|
+
send_volume
|
31
31
|
end
|
32
32
|
|
33
|
-
def volume_down
|
34
|
-
@volume -=
|
33
|
+
def volume_down volume
|
34
|
+
@volume -= volume
|
35
35
|
@volume = [@volume, 0].max
|
36
|
-
|
36
|
+
send_volume
|
37
37
|
end
|
38
38
|
|
39
|
-
|
40
|
-
|
39
|
+
def volume= volume
|
40
|
+
if volume < 0
|
41
|
+
@volume = 0
|
42
|
+
elsif volume > 100
|
43
|
+
@volume = 100
|
44
|
+
else
|
45
|
+
@volume = volume
|
46
|
+
end
|
47
|
+
send_volume
|
48
|
+
end
|
49
|
+
|
50
|
+
private def send_volume
|
51
|
+
@music_input.puts "G #{@volume}"
|
41
52
|
end
|
42
53
|
end
|
data/lib/version.rb
CHANGED
data/spec/mpg321_spec.rb
CHANGED
@@ -46,16 +46,36 @@ describe Mpg321 do
|
|
46
46
|
end
|
47
47
|
|
48
48
|
describe '#volume' do
|
49
|
-
it 'sets the volume to 50' do
|
50
|
-
expect(subject.volume).to eq 50
|
51
|
-
end
|
52
|
-
|
53
49
|
it 'returns the current volume' do
|
50
|
+
expect(subject.volume).to eq 50
|
54
51
|
subject.volume_up 5
|
55
52
|
expect(subject.volume).to eq 55
|
56
53
|
end
|
57
54
|
end
|
58
55
|
|
56
|
+
describe '#volume=' do
|
57
|
+
it 'sets the volume' do
|
58
|
+
expect(subject.volume).to eq 50
|
59
|
+
subject.volume = 11
|
60
|
+
expect(subject.volume).to eq 11
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'has a minimum of 0' do
|
64
|
+
subject.volume = -1
|
65
|
+
expect(subject.volume).to eq 0
|
66
|
+
end
|
67
|
+
|
68
|
+
it 'has a maximum of 100' do
|
69
|
+
subject.volume = 101
|
70
|
+
expect(subject.volume).to eq 100
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'sends a message to set the volume' do
|
74
|
+
expect(stdin).to receive(:puts).with "G 11"
|
75
|
+
subject.volume = 11
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
59
79
|
describe '#play' do
|
60
80
|
it 'sends a message to play a song' do
|
61
81
|
expect(stdin).to receive(:puts).with "L /some_path/file_name"
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mpg321
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Richard Vickerstaff
|
@@ -18,6 +18,7 @@ extensions: []
|
|
18
18
|
extra_rdoc_files: []
|
19
19
|
files:
|
20
20
|
- ".gitignore"
|
21
|
+
- ".semver"
|
21
22
|
- ".travis.yml"
|
22
23
|
- Gemfile
|
23
24
|
- LICENSE
|
@@ -48,7 +49,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
48
49
|
version: '0'
|
49
50
|
requirements: []
|
50
51
|
rubyforge_project:
|
51
|
-
rubygems_version: 2.4.
|
52
|
+
rubygems_version: 2.4.5
|
52
53
|
signing_key:
|
53
54
|
specification_version: 4
|
54
55
|
summary: Provides a ruby object to wrap the mpg321 'Remote control'
|