mpg321 0.1.0 → 0.2.0
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 +1 -1
- data/README.md +36 -1
- data/lib/mpg321.rb +32 -5
- data/lib/version.rb +1 -1
- data/spec/mpg321_spec.rb +12 -3
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d42e22e01a5a3b5250a777fc39905db9c69e600
|
4
|
+
data.tar.gz: 314b8dcfe79580dd115b20254b90a6b6e0cad49b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ecc9a456d50dc3228748a28f271a11bd103c68aa2e3ac6c3d9c797ae36196a895bff143d4639dd1ba3d1aa6e6ae87fc888c0533a7da4e5c173b981c6c052403b
|
7
|
+
data.tar.gz: adeef58146da29e6397418e7c0f89feb21eb39a712004e12ed48539ad58b48675286a6a475e1310e9df588abe8bd1c2bf56c4a59b449c6aedaf2f31d46f340bb
|
data/.semver
CHANGED
data/README.md
CHANGED
@@ -25,8 +25,43 @@ Here's how you can easily play an mp3:
|
|
25
25
|
|
26
26
|
```ruby
|
27
27
|
require 'mpg321'
|
28
|
+
mog321 = Mpg321.new
|
28
29
|
|
29
|
-
|
30
|
+
mpg321.play('/some_path/song.mp3') #=> to play a song from a file
|
31
|
+
|
32
|
+
mpg321.play('http://example.com/a_hosted_song.mp3') #=> to play a song from the web
|
33
|
+
```
|
34
|
+
To play a list of songs:
|
35
|
+
|
36
|
+
```ruby
|
37
|
+
require 'mpg321'
|
38
|
+
|
39
|
+
mog321 = Mpg321.new
|
40
|
+
mpg321.play(['/some_path/song.mp3', '/another_path/another_song'])
|
41
|
+
```
|
42
|
+
|
43
|
+
Volume controls:
|
44
|
+
|
45
|
+
```ruby
|
46
|
+
require 'mpg321'
|
47
|
+
mog321 = Mpg321.new
|
48
|
+
|
49
|
+
mpg321.volume #=> initialized to 50
|
50
|
+
|
51
|
+
mpg321.volume = 10 #=> Set volume to a number between 0 and 100
|
52
|
+
|
53
|
+
mpg321.volume_up(10) #=> Increase volume by 10
|
54
|
+
mpg321.volume_down(10) #=> Decrease volume by 10
|
55
|
+
```
|
56
|
+
Other controls:
|
57
|
+
|
58
|
+
```ruby
|
59
|
+
require 'mpg321'
|
60
|
+
mog321 = Mpg321.new
|
61
|
+
|
62
|
+
mpg321.pause #=> Pause / unpause song
|
63
|
+
|
64
|
+
mpg321.stop #=> Stop playing song / song list
|
30
65
|
```
|
31
66
|
|
32
67
|
Contributing
|
data/lib/mpg321.rb
CHANGED
@@ -5,9 +5,9 @@ class Mpg321
|
|
5
5
|
|
6
6
|
def initialize
|
7
7
|
@volume = 50
|
8
|
-
@music_input,
|
9
|
-
|
10
|
-
|
8
|
+
@music_input, @stdout, @stderr, _thread = Open3.popen3("mpg321 -R mpg321_ruby")
|
9
|
+
handle_stderr
|
10
|
+
handle_stdout
|
11
11
|
send_volume
|
12
12
|
end
|
13
13
|
|
@@ -19,8 +19,15 @@ class Mpg321
|
|
19
19
|
@music_input.puts "S"
|
20
20
|
end
|
21
21
|
|
22
|
-
def play
|
23
|
-
@
|
22
|
+
def play song_list
|
23
|
+
@song_list = song_list
|
24
|
+
if song_list.class == Array
|
25
|
+
@list = true
|
26
|
+
play_song @song_list.shift
|
27
|
+
else
|
28
|
+
@list = false
|
29
|
+
play_song song_list
|
30
|
+
end
|
24
31
|
end
|
25
32
|
|
26
33
|
def volume_up volume
|
@@ -48,7 +55,27 @@ class Mpg321
|
|
48
55
|
|
49
56
|
private
|
50
57
|
|
58
|
+
def play_song song
|
59
|
+
@music_input.puts "L #{song}"
|
60
|
+
end
|
61
|
+
|
51
62
|
def send_volume
|
52
63
|
@music_input.puts "G #{@volume}"
|
53
64
|
end
|
65
|
+
|
66
|
+
def handle_stderr
|
67
|
+
Thread.new { loop do @stderr.readline end }
|
68
|
+
end
|
69
|
+
|
70
|
+
def handle_stdout
|
71
|
+
Thread.new do
|
72
|
+
loop do
|
73
|
+
line = @stdout.readline
|
74
|
+
#Not sure how to test this yet
|
75
|
+
if @list && line.match(/@P 3/)
|
76
|
+
play @song_list
|
77
|
+
end
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
54
81
|
end
|
data/lib/version.rb
CHANGED
data/spec/mpg321_spec.rb
CHANGED
@@ -77,9 +77,18 @@ describe Mpg321 do
|
|
77
77
|
end
|
78
78
|
|
79
79
|
describe '#play' do
|
80
|
-
|
81
|
-
|
82
|
-
|
80
|
+
context 'when there is only one song' do
|
81
|
+
it 'sends a message to play a song' do
|
82
|
+
expect(stdin).to receive(:puts).with "L /some_path/file_name"
|
83
|
+
subject.play '/some_path/file_name'
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context 'when there moer than one song' do
|
88
|
+
it 'sends a message to play the first song' do
|
89
|
+
expect(stdin).to receive(:puts).with "L /some_path/file_name"
|
90
|
+
subject.play ['/some_path/file_name', '/some_other_song']
|
91
|
+
end
|
83
92
|
end
|
84
93
|
end
|
85
94
|
|