mpg321 0.0.2 → 0.0.3

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: 94514d21232c484e65ad6d3463838d0aa3fe0d3e
4
- data.tar.gz: f424ed7cf45a9a369a044d1218a99b358f24703f
3
+ metadata.gz: 24b0ecbf200a6881e339377bad2caabcb13f1908
4
+ data.tar.gz: 0de8362c74635f4fbb074e53d5e7ba6e0afb9444
5
5
  SHA512:
6
- metadata.gz: 834acd318be8e4fd1eede977760deb77a6d7e1752c3a40c831e1d80081d5af4948bca0ba969c521c8e06b35e65906eb284454eb11d9b04bb6595d08d9ee54316
7
- data.tar.gz: 00277f1f3adc68264e352366d891f412b2960a103411da77325a09676061230ea17f43d6c1dbb57fd42f97d0fa505043c1d551f2acd70b3c29963fbbe6d70711
6
+ metadata.gz: ad6de75c72fd0c26e9469aeae21aeea785162e2535c2b8155c9f2421d87c854958be790301b79442cfe0911c2817666fde230ba8ea4e7810c1f081b42a194c32
7
+ data.tar.gz: 12cc121d53898d66c4f00e8e28d14bcc1743507d87e203cf9966672fb7f81d06e97f6c5b81f630ce3db454d23a3be0e1a78bfc1154cc8999ca7c56e2fa153312
data/.semver ADDED
@@ -0,0 +1,6 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 0
4
+ :patch: 3
5
+ :special: ''
6
+ :metadata: ''
data/Gemfile CHANGED
@@ -1,11 +1,9 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
3
  group :test, :development do
4
- gem 'semver'
5
4
  gem 'simplecov'
6
- gem 'pry'
5
+ gem 'semver2'
7
6
  gem 'bundler-audit'
8
- gem 'pry-byebug'
9
7
  gem 'rake-n-bake'
10
8
  gem 'rspec'
11
9
  end
data/README.md CHANGED
@@ -1,9 +1,15 @@
1
1
  Mpg321
2
2
  ===========
3
3
 
4
+ [![Build Status](https://travis-ci.org/RichardVickerstaff/mpg321.svg)](https://travis-ci.org/RichardVickerstaff/mpg321)
5
+ [![Gem Version](https://badge.fury.io/rb/mpg321.svg)](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
- @mus, _stdout, _stderr, _thread = Open3.popen3("mpg321 -R mpg321_ruby")
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
- set_volume
11
+ send_volume
12
12
  end
13
13
 
14
14
  def pause
15
- @mus.puts "P"
15
+ @music_input.puts "P"
16
16
  end
17
17
 
18
18
  def stop
19
- @mus.puts "S"
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
- @mus.puts "L #{songs}"
24
+ @music_input.puts "L #{songs}"
25
25
  end
26
26
 
27
- def volume_up num
28
- @volume += num
27
+ def volume_up volume
28
+ @volume += volume
29
29
  @volume = [@volume, 100].min
30
- set_volume
30
+ send_volume
31
31
  end
32
32
 
33
- def volume_down num
34
- @volume -= num
33
+ def volume_down volume
34
+ @volume -= volume
35
35
  @volume = [@volume, 0].max
36
- set_volume
36
+ send_volume
37
37
  end
38
38
 
39
- private def set_volume
40
- @mus.puts "G #{@volume}"
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
@@ -1,3 +1,3 @@
1
1
  module Mpg321
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
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
@@ -1,6 +1,4 @@
1
- require 'rubygems'
2
1
  require 'bundler/setup'
3
- require 'pry-byebug'
4
2
  require 'simplecov'
5
3
  SimpleCov.start
6
4
 
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.2
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.2
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'