mpg321 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: da2b38df3bd14d07e31d8530bb53a0466639305c
4
- data.tar.gz: 60fe5ecaff83ac9e184e4423b95629a12d677249
3
+ metadata.gz: 8d42e22e01a5a3b5250a777fc39905db9c69e600
4
+ data.tar.gz: 314b8dcfe79580dd115b20254b90a6b6e0cad49b
5
5
  SHA512:
6
- metadata.gz: e59f321744297579547f84c2d08788f7c631e31ae24ab6faa0427523b8bb8d3a4e68399ac07e613e3484712f669bc7e53e82c9b9b561006bd2d1c7673cfe66dc
7
- data.tar.gz: 14a75a87353e176209675242be693ed347c1c8ae981e3e63f89899896bbd90e4517c0e73f2c71a956d43c9d5312cdf69d0f73fe824a201ea3fe6a50f477d80f1
6
+ metadata.gz: ecc9a456d50dc3228748a28f271a11bd103c68aa2e3ac6c3d9c797ae36196a895bff143d4639dd1ba3d1aa6e6ae87fc888c0533a7da4e5c173b981c6c052403b
7
+ data.tar.gz: adeef58146da29e6397418e7c0f89feb21eb39a712004e12ed48539ad58b48675286a6a475e1310e9df588abe8bd1c2bf56c4a59b449c6aedaf2f31d46f340bb
data/.semver CHANGED
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  :major: 0
3
- :minor: 1
3
+ :minor: 2
4
4
  :patch: 0
5
5
  :special: ''
6
6
  :metadata: ''
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
- Mpg321.new.play('/some_path/song.mp3')
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, _stdout, _stderr, _thread = Open3.popen3("mpg321 -R mpg321_ruby")
9
- Thread.new { loop do _stderr.readline end }
10
- Thread.new { loop do _stdout.readline end }
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 song
23
- @music_input.puts "L #{song}"
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
@@ -1,3 +1,3 @@
1
1
  module Mpg321
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
data/spec/mpg321_spec.rb CHANGED
@@ -77,9 +77,18 @@ describe Mpg321 do
77
77
  end
78
78
 
79
79
  describe '#play' do
80
- it 'sends a message to play a song' do
81
- expect(stdin).to receive(:puts).with "L /some_path/file_name"
82
- subject.play '/some_path/file_name'
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
 
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.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Richard Vickerstaff