jimmy_jukebox 0.3.7 → 0.4.1
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.
- data/bin/load_jukebox +1 -1
- data/bin/play_jukebox +31 -8
- data/lib/jimmy_jukebox/artists.rb +4 -1
- data/lib/jimmy_jukebox/jukebox.rb +100 -44
- data/lib/jimmy_jukebox/song.rb +130 -53
- data/lib/jimmy_jukebox/song_loader.rb +4 -0
- data/lib/jimmy_jukebox/songs/ArchibaldCampBanjo.yml +21 -0
- data/lib/jimmy_jukebox/songs/CharlieChristian.yml +9 -8
- data/lib/jimmy_jukebox/songs/CharlieParker.yml +8 -6
- data/lib/jimmy_jukebox/songs/CliffordHayesJugBlowers.yml +16 -0
- data/lib/jimmy_jukebox/songs/Dixieland.yml +9 -0
- data/lib/jimmy_jukebox/songs/LouisArmstrong.yml +5 -0
- data/lib/jimmy_jukebox/songs/MilesDavis.yml +31 -0
- data/lib/jimmy_jukebox/songs/Ragtime.yml +15 -0
- data/lib/jimmy_jukebox/user_config.rb +42 -35
- data/lib/jimmy_jukebox/user_interface.rb +46 -28
- data/lib/jimmy_jukebox/version.rb +2 -1
- data/spec/jimmy_jukebox_spec.rb +158 -133
- data/spec/song_loader_spec.rb +0 -1
- data/spec/song_spec.rb +4 -4
- data/spec/spec_helper.rb +30 -6
- data/spec/user_config_spec.rb +32 -15
- metadata +86 -74
- data/bin/jload_jukebox +0 -3
- data/bin/jplay_jukebox +0 -16
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
---
|
|
2
|
+
- http://archive.org/download/EDIS-SRP-0092-03/EDIS-SRP-0092-03.mp3
|
|
3
|
+
- http://archive.org/download/AlexandersRagtimeBand/AlexandersRagtimeBand.mp3
|
|
4
|
+
- http://archive.org/download/ScottJoplinRagtime/ScottJoplinMapleLeaf.mp3
|
|
5
|
+
- http://archive.org/download/ScottJoplinRagtime/ScottJoplinTheEntertainer.mp3
|
|
6
|
+
- http://archive.org/download/ScottJoplinRagtime/ScottJoplinTheSycamore.mp3
|
|
7
|
+
- http://archive.org/download/Eck_Robertson_Ragtime_Annie/Eck_Robertson-Ragtime_Annie_vbr.mp3
|
|
8
|
+
- http://archive.org/download/BlackAndWhiteRagtime1909/VictorOrchestra-BlackAndWhiteRagtime1909.mp3
|
|
9
|
+
- http://archive.org/download/WinnerRagtimeBand-TheTurkeyTrot1912/WinnerRagtimeBand-TurkeyTrot1912.mp3
|
|
10
|
+
- http://archive.org/download/MugsySpannerAndHisRagtimeBand-Relaxin/MugsySpannerAndHisRagtimeBand-Relaxin.mp3
|
|
11
|
+
- http://archive.org/download/ArthurCollinsByronHarlan-AlexandersRagtimeBand/ArthurCollinsByronHarlan-AlexandersRagtimeBand.mp3
|
|
12
|
+
- http://archive.org/download/FowlerStreetFiveAlexandersRagtimeBand/Fs5-1954-betaHouseAtlanta-alexandersRagtimeBand.mp3
|
|
13
|
+
- http://archive.org/download/DollyConnolly-TheRagtimeMockingbird1912/DollyConnolly-TheRagtimeMockingbird1912.mp3
|
|
14
|
+
- http://archive.org/download/OleMissRag/W.c.Handy-oleMissRag_1917_64kb.mp3
|
|
15
|
+
- http://archive.org/download/Dempsey_Jacks_Pig_Ankle_Rag/Dempsey_Jacks_Pig_Ankle_Rag.mp3
|
|
@@ -7,7 +7,8 @@ module JimmyJukebox
|
|
|
7
7
|
require 'jimmy_jukebox/artists'
|
|
8
8
|
include Artists
|
|
9
9
|
|
|
10
|
-
|
|
10
|
+
attr_writer :music_directories
|
|
11
|
+
attr_accessor :songs, :ogg_player, :mp3_player
|
|
11
12
|
|
|
12
13
|
DEFAULT_PLAYLIST_DIR = File.expand_path(File.join("~",".jimmy_jukebox"))
|
|
13
14
|
|
|
@@ -19,6 +20,7 @@ module JimmyJukebox
|
|
|
19
20
|
end
|
|
20
21
|
|
|
21
22
|
def initialize
|
|
23
|
+
self.songs = []
|
|
22
24
|
set_music_players
|
|
23
25
|
generate_directories_list
|
|
24
26
|
generate_song_list
|
|
@@ -31,8 +33,8 @@ module JimmyJukebox
|
|
|
31
33
|
def set_music_players
|
|
32
34
|
set_ogg_player
|
|
33
35
|
set_mp3_player
|
|
34
|
-
no_player_configured
|
|
35
|
-
warn_about_partial_functionality if
|
|
36
|
+
no_player_configured unless ogg_player || mp3_player
|
|
37
|
+
warn_about_partial_functionality if !ogg_player || !mp3_player
|
|
36
38
|
end
|
|
37
39
|
|
|
38
40
|
def no_player_configured
|
|
@@ -41,57 +43,61 @@ module JimmyJukebox
|
|
|
41
43
|
end
|
|
42
44
|
|
|
43
45
|
def warn_about_partial_functionality
|
|
44
|
-
if
|
|
46
|
+
if ogg_player && !mp3_player
|
|
45
47
|
puts "*** YOU CANNOT PLAY MP3S -- YOU MIGHT WANT TO INSTALL MPG123 OR MPG321 ***"
|
|
46
|
-
elsif
|
|
48
|
+
elsif mp3_player && !ogg_player
|
|
47
49
|
puts "*** YOU CANNOT PLAY OGG FILES -- YOU MIGHT WANT TO INSTALL OGG123 ***"
|
|
48
50
|
end
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
def set_ogg_player
|
|
52
54
|
if ogg123_exists?
|
|
53
|
-
|
|
55
|
+
self.ogg_player = "ogg123"
|
|
54
56
|
return
|
|
55
57
|
elsif music123_exists?
|
|
56
|
-
|
|
58
|
+
self.ogg_player = "music123"
|
|
57
59
|
return
|
|
58
60
|
elsif afplay_exists?
|
|
59
|
-
|
|
61
|
+
self.ogg_player = "afplay"
|
|
60
62
|
return
|
|
61
63
|
elsif mplayer_exists?
|
|
62
|
-
|
|
64
|
+
self.ogg_player = "mplayer -nolirc -noconfig all"
|
|
63
65
|
elsif play_exists?
|
|
64
|
-
|
|
66
|
+
self.ogg_player = "play"
|
|
65
67
|
#elsif RUBY_PLATFORM.downcase.include?('mac') || RUBY_PLATFORM.downcase.include?('darwin')
|
|
66
|
-
#
|
|
68
|
+
# ogg_player = "afplay"
|
|
67
69
|
# return
|
|
68
70
|
#elsif (require 'rbconfig') && ['mac','darwin'].include?(RbConfig::CONFIG['host_os'])
|
|
69
|
-
#
|
|
71
|
+
# ogg_player = "afplay"
|
|
72
|
+
else
|
|
73
|
+
raise NoOggPlayerFoundException, "Could not find an Ogg Vorbis player"
|
|
70
74
|
end
|
|
71
75
|
end
|
|
72
76
|
|
|
73
77
|
def set_mp3_player
|
|
74
78
|
if mpg123_exists?
|
|
75
|
-
|
|
79
|
+
self.mp3_player = "mpg123"
|
|
76
80
|
return
|
|
77
81
|
elsif mpg321_exists?
|
|
78
|
-
|
|
82
|
+
self.mp3_player = "mpg321"
|
|
79
83
|
return
|
|
80
84
|
elsif music123_exists?
|
|
81
|
-
|
|
85
|
+
self.mp3_player = "music123"
|
|
82
86
|
return
|
|
83
87
|
elsif afplay_exists?
|
|
84
|
-
|
|
88
|
+
self.mp3_player = "afplay"
|
|
85
89
|
return
|
|
86
90
|
elsif mplayer_exists?
|
|
87
|
-
|
|
91
|
+
self.mp3_player = "mplayer -nolirc -noconfig all"
|
|
88
92
|
elsif play_exists?
|
|
89
|
-
|
|
93
|
+
self.mp3_player = "play"
|
|
90
94
|
#elsif RUBY_PLATFORM.downcase.include?('mac') || RUBY_PLATFORM.downcase.include?('darwin')
|
|
91
|
-
#
|
|
95
|
+
# mp3_player = "afplay"
|
|
92
96
|
# return
|
|
93
97
|
#elsif (require 'rbconfig') && ['mac','darwin'].include?(RbConfig::CONFIG['host_os'])
|
|
94
|
-
#
|
|
98
|
+
# mp3_player = "afplay"
|
|
99
|
+
else
|
|
100
|
+
raise NoMP3PlayerFoundException, "Could not find an MP3 player"
|
|
95
101
|
end
|
|
96
102
|
end
|
|
97
103
|
|
|
@@ -132,27 +138,30 @@ module JimmyJukebox
|
|
|
132
138
|
load_top_level_directories_from_file
|
|
133
139
|
end
|
|
134
140
|
|
|
141
|
+
def music_directories
|
|
142
|
+
@music_directories ||= []
|
|
143
|
+
end
|
|
144
|
+
|
|
135
145
|
def generate_directories_list
|
|
136
|
-
@music_directories = []
|
|
137
146
|
# ARGV[0] can be "jazz.txt" (a file holding directory names), "~/Music/JAZZ" (a directory path) or nil
|
|
138
147
|
# puts "ARGV: " + ARGV.inspect + " (" + ARGV.class.to_s + ")"
|
|
139
148
|
if ARGV.empty?
|
|
140
|
-
|
|
149
|
+
music_directories << default_music_dir
|
|
141
150
|
elsif JAZZ_ARTISTS.keys.include?(ARGV[0].to_sym)
|
|
142
|
-
|
|
151
|
+
music_directories << default_music_dir + key_to_subdir_name(ARGV[0].to_sym)
|
|
143
152
|
elsif is_a_txt_file?(ARGV[0])
|
|
144
153
|
set_music_directories_from_file
|
|
145
154
|
elsif is_a_directory?(ARGV[0])
|
|
146
|
-
|
|
155
|
+
music_directories << File.expand_path(ARGV[0])
|
|
147
156
|
else
|
|
148
|
-
|
|
157
|
+
music_directories << default_music_dir
|
|
149
158
|
end
|
|
150
159
|
create_nonexistent_music_directories
|
|
151
160
|
add_all_subdirectories
|
|
152
161
|
end
|
|
153
162
|
|
|
154
163
|
def create_nonexistent_music_directories
|
|
155
|
-
|
|
164
|
+
music_directories.each do |md|
|
|
156
165
|
FileUtils.mkdir_p(md) unless Dir.exists?(md)
|
|
157
166
|
end
|
|
158
167
|
end
|
|
@@ -171,32 +180,30 @@ module JimmyJukebox
|
|
|
171
180
|
File.open(@music_directories_file, "r") do |inf|
|
|
172
181
|
while (line = inf.gets)
|
|
173
182
|
line.strip!
|
|
174
|
-
|
|
183
|
+
music_directories << File.expand_path(line)
|
|
175
184
|
end
|
|
176
185
|
end
|
|
177
186
|
end
|
|
178
187
|
|
|
179
188
|
def add_all_subdirectories
|
|
180
189
|
new_dirs = []
|
|
181
|
-
|
|
182
|
-
Dir.
|
|
183
|
-
new_dirs = new_dirs + Dir.glob("**/").map { |dir_name| File.expand_path(dir_name) }
|
|
190
|
+
music_directories.each do |dir|
|
|
191
|
+
new_dirs = new_dirs + Dir.glob(File.join(dir,"**/")).map { |dir_name| File.expand_path(dir_name) }
|
|
184
192
|
end
|
|
185
|
-
|
|
193
|
+
self.music_directories = music_directories + new_dirs
|
|
186
194
|
end
|
|
187
195
|
|
|
188
196
|
def generate_song_list
|
|
189
|
-
|
|
190
|
-
@music_directories.each do |music_dir|
|
|
197
|
+
music_directories.each do |music_dir|
|
|
191
198
|
files = Dir.entries(File.expand_path(music_dir))
|
|
192
199
|
if "".respond_to?(:force_encoding) # Ruby 1.8 doesn't have string encoding or String#force_encoding
|
|
193
200
|
files.delete_if { |f| !f.force_encoding("UTF-8").valid_encoding? } # avoid "invalid byte sequence in UTF-8 (ArgumentError)"
|
|
194
201
|
end
|
|
195
202
|
files.delete_if { |f| !f.match(/.*\.mp3/i) && !f.match(/.*\.ogg/i) }
|
|
196
203
|
files.map! { |f| File.expand_path(music_dir) + '/' + f }
|
|
197
|
-
|
|
204
|
+
files.each { |f| songs << f }
|
|
198
205
|
end
|
|
199
|
-
puts "WARNING: JimmyJukebox could not find any songs" unless
|
|
206
|
+
puts "WARNING: JimmyJukebox could not find any songs" unless songs.length > 0
|
|
200
207
|
#songs = ["~/Music/Artie_Shaw/Georgia On My Mind 1941.mp3",
|
|
201
208
|
# "~/Music/Jelly_Roll_Morton/High Society 1939.mp3"]
|
|
202
209
|
end
|
|
@@ -1,43 +1,61 @@
|
|
|
1
1
|
require 'readline'
|
|
2
2
|
|
|
3
|
-
jj = Jukebox
|
|
3
|
+
jj = Jukebox.new
|
|
4
4
|
|
|
5
5
|
play_loop_thread = Thread.new do
|
|
6
6
|
jj.play_loop
|
|
7
7
|
end
|
|
8
8
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
9
|
+
user_input_thread = Thread.new do
|
|
10
|
+
|
|
11
|
+
stty_save = `stty -g`.chomp # Store state of the terminal
|
|
12
|
+
|
|
13
|
+
def display_options
|
|
14
|
+
p "Press 'p' to (un)pause, 'q' to quit, 'r' for replay previous song, or 's' to skip this song"
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def display_options_after_delay
|
|
18
|
+
sleep 0.2
|
|
19
|
+
display_options
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
class NoPlayLoopThreadException < Exception; end
|
|
23
|
+
|
|
24
|
+
begin
|
|
25
|
+
loop do
|
|
26
|
+
display_options_after_delay
|
|
27
|
+
line = Readline.readline('> ', true)
|
|
28
|
+
case line.strip
|
|
29
|
+
when "q", "Q"
|
|
30
|
+
raise Interrupt
|
|
31
|
+
when "p", "P"
|
|
32
|
+
raise NoPlayLoopThreadException, "Can't find play_loop_thread" unless play_loop_thread
|
|
33
|
+
if jj.current_song.paused?
|
|
34
|
+
p "Unpause requested"
|
|
35
|
+
jj.unpause_current_song
|
|
36
|
+
else
|
|
37
|
+
p "Pause requested"
|
|
38
|
+
p "To unpause, enter 'p' again"
|
|
39
|
+
jj.pause_current_song
|
|
40
|
+
end
|
|
41
|
+
when "r", "R"
|
|
42
|
+
p "Replay previous song requested"
|
|
43
|
+
jj.replay_previous_song
|
|
44
|
+
when "s", "S"
|
|
45
|
+
p "Skip song requested"
|
|
46
|
+
jj.skip_song
|
|
26
47
|
else
|
|
27
|
-
|
|
48
|
+
p "#{line.strip} is not a valid response"
|
|
28
49
|
end
|
|
29
|
-
puts display_string
|
|
30
|
-
when "s"
|
|
31
|
-
puts "Skip song requested"
|
|
32
|
-
jj.skip_song
|
|
33
|
-
else
|
|
34
|
-
puts display_string
|
|
35
50
|
end
|
|
51
|
+
rescue Interrupt, SystemExit => e
|
|
52
|
+
p "JimmyJukebox closed by user request. Bye!"
|
|
53
|
+
jj.quit
|
|
54
|
+
system('stty', stty_save) unless RUBY_ENGINE == 'jruby' # Restore original terminal state
|
|
55
|
+
exit
|
|
36
56
|
end
|
|
37
|
-
rescue Interrupt => e
|
|
38
|
-
puts "\nMusic terminated by user"
|
|
39
|
-
exit
|
|
40
57
|
end
|
|
41
58
|
|
|
42
59
|
play_loop_thread.join
|
|
60
|
+
user_input_thread.join
|
|
43
61
|
|
data/spec/jimmy_jukebox_spec.rb
CHANGED
|
@@ -1,191 +1,214 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
|
-
|
|
3
|
-
require 'jimmy_jukebox'
|
|
2
|
+
require_relative '../lib/jimmy_jukebox/jukebox'
|
|
4
3
|
include JimmyJukebox
|
|
5
4
|
|
|
6
5
|
describe Jukebox do
|
|
7
6
|
|
|
7
|
+
include FakeFS::SpecHelpers
|
|
8
|
+
|
|
8
9
|
before(:all) do
|
|
9
10
|
ARGV.clear
|
|
10
|
-
#ARGV.pop
|
|
11
11
|
end
|
|
12
12
|
|
|
13
|
+
let(:jb) { Jukebox.new }
|
|
14
|
+
|
|
13
15
|
let(:uc) { double('user_config').as_null_object }
|
|
14
16
|
|
|
17
|
+
|
|
15
18
|
context "with no command line parameter" do
|
|
16
19
|
|
|
17
20
|
it "exists" do
|
|
18
|
-
|
|
19
|
-
|
|
21
|
+
jb.should_not be_nil
|
|
22
|
+
jb.quit
|
|
20
23
|
end
|
|
21
24
|
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
it "has a user_config method" do
|
|
29
|
-
Jukebox.user_config.is_a?(UserConfig)
|
|
25
|
+
it "calls play_random_song" do
|
|
26
|
+
jb.stub(:play_random_song).and_return(nil)
|
|
27
|
+
jb.should_receive(:play_once)
|
|
28
|
+
jb.play_once
|
|
29
|
+
jb.quit
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
it "
|
|
33
|
-
|
|
32
|
+
it "raises exception when no songs available" do
|
|
33
|
+
expect { jb.play_once }.to raise_error(Jukebox::NoSongException)
|
|
34
34
|
end
|
|
35
35
|
|
|
36
|
-
it "
|
|
37
|
-
|
|
38
|
-
Jukebox.user_config.songs.should_not be_empty
|
|
39
|
-
Jukebox.user_config.songs.length.should be > 0
|
|
36
|
+
it "has a user_config method" do
|
|
37
|
+
jb.user_config.is_a?(UserConfig)
|
|
40
38
|
end
|
|
41
39
|
|
|
42
|
-
it "generates
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
end
|
|
40
|
+
it "generates an empty song list" do
|
|
41
|
+
jb.user_config.songs.should be_empty
|
|
42
|
+
jb.user_config.songs.length.should == 0
|
|
46
43
|
end
|
|
47
44
|
|
|
48
|
-
|
|
45
|
+
context "when songs exist" do
|
|
49
46
|
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
end
|
|
47
|
+
let(:song1) { '/home/xavier/Music/Rock/Beatles/Abbey_Road.mp3' }
|
|
48
|
+
let(:song2) { '/home/xavier/Music/Rock/Beatles/Sgt_Pepper.mp3' }
|
|
49
|
+
let(:song3) { '/home/xavier/Music/Rock/Eagles/Hotel_California.ogg' }
|
|
54
50
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
Jukebox.play_once
|
|
51
|
+
before do
|
|
52
|
+
[song1, song2, song3].each do |song|
|
|
53
|
+
FileUtils.mkdir_p(File.dirname(song))
|
|
54
|
+
FileUtils.touch(song)
|
|
55
|
+
Dir.chdir('/home/xavier')
|
|
61
56
|
end
|
|
62
|
-
sleep 0.1
|
|
63
|
-
jj.current_song.is_a?(Song)
|
|
64
|
-
thread.exit
|
|
65
57
|
end
|
|
66
58
|
|
|
67
|
-
it "
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
Jukebox.play_once
|
|
73
|
-
end
|
|
74
|
-
sleep 0.1
|
|
75
|
-
jj.current_song.music_file.should match /\.mp3$|\.ogg$/
|
|
76
|
-
thread.exit
|
|
59
|
+
it "generates a non-empty song list" do
|
|
60
|
+
jb.user_config.songs.should_not be_nil
|
|
61
|
+
jb.user_config.songs.should_not be_empty
|
|
62
|
+
jb.user_config.songs.length.should == 3
|
|
63
|
+
jb.user_config.songs.should include(/Abbey_Road.mp3/)
|
|
77
64
|
end
|
|
78
65
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
66
|
+
=begin
|
|
67
|
+
xit "generates a non-empty song list with only mp3 & ogg files" do
|
|
68
|
+
jb.user_config.songs.each do |song|
|
|
69
|
+
song.should match(/.*\.mp3|.*\.ogg/i)
|
|
83
70
|
end
|
|
84
|
-
sleep 0.1
|
|
85
|
-
jj.current_song.player.should_not be_nil
|
|
86
|
-
thread.exit
|
|
87
71
|
end
|
|
88
72
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
73
|
+
describe "#play_once" do
|
|
74
|
+
|
|
75
|
+
xit "should call play_random_song" do
|
|
76
|
+
jb.should_receive(:play_random_song)
|
|
77
|
+
jb.play_once
|
|
93
78
|
end
|
|
94
|
-
sleep 0.3
|
|
95
|
-
jj.current_song.should be_nil
|
|
96
|
-
thread.exit
|
|
97
|
-
end
|
|
98
79
|
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
80
|
+
xit "should have a current_song" do
|
|
81
|
+
uc.stub(:mp3_player) {"play"}
|
|
82
|
+
uc.stub(:ogg_player) {"play"}
|
|
83
|
+
thread = Thread.new do
|
|
84
|
+
jb.play_once
|
|
85
|
+
end
|
|
86
|
+
sleep 0.1
|
|
87
|
+
jb.current_song.is_a?(Song)
|
|
88
|
+
thread.exit
|
|
103
89
|
end
|
|
104
|
-
sleep 0.1
|
|
105
|
-
jj.current_song.playing_pid.should_not be_nil
|
|
106
|
-
#jj.should_receive(:terminate_current_song)
|
|
107
|
-
jj.quit
|
|
108
|
-
thread.exit
|
|
109
|
-
end
|
|
110
90
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
91
|
+
xit "should have a current_song with a music_file" do
|
|
92
|
+
uc.stub(:mp3_player) {"play"}
|
|
93
|
+
uc.stub(:ogg_player) {"play"}
|
|
94
|
+
thread = Thread.new do
|
|
95
|
+
jb.play_once
|
|
96
|
+
end
|
|
97
|
+
sleep 0.1
|
|
98
|
+
jb.current_song.music_file.should match /\.mp3$|\.ogg$/
|
|
99
|
+
thread.exit
|
|
100
|
+
xend
|
|
101
|
+
|
|
102
|
+
xit "should have a player" do
|
|
103
|
+
thread = Thread.new do
|
|
104
|
+
jb.play_once
|
|
105
|
+
end
|
|
106
|
+
sleep 0.1
|
|
107
|
+
jb.current_song.player.should_not be_nil
|
|
108
|
+
thread.exit
|
|
109
|
+
end
|
|
115
110
|
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
111
|
+
xit "should not have a current_song after song finishes" do
|
|
112
|
+
thread = Thread.new do
|
|
113
|
+
jb.play_once
|
|
114
|
+
end
|
|
115
|
+
sleep 0.3
|
|
116
|
+
jb.current_song.should be_nil
|
|
117
|
+
thread.exit
|
|
119
118
|
end
|
|
120
|
-
sleep 0.1
|
|
121
|
-
song_1 = Jukebox.current_song.playing_pid
|
|
122
|
-
Jukebox.pause_current_song
|
|
123
|
-
song_2 = Jukebox.current_song.playing_pid
|
|
124
|
-
song_1.should == song_2
|
|
125
|
-
Jukebox.current_song.paused.should be_true
|
|
126
|
-
Jukebox.quit
|
|
127
|
-
thread.exit
|
|
128
|
-
end
|
|
129
119
|
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
120
|
+
xit "should have a current_song with a playing_pid" do
|
|
121
|
+
thread = Thread.new do
|
|
122
|
+
jb.play_once
|
|
123
|
+
end
|
|
124
|
+
sleep 0.1
|
|
125
|
+
jb.current_song.playing_pid.should_not be_nil
|
|
126
|
+
#jb.should_receive(:terminate_current_song)
|
|
127
|
+
jb.quit
|
|
128
|
+
thread.exit
|
|
129
|
+
end
|
|
130
|
+
|
|
131
|
+
xit "triggers play_random_song" do
|
|
132
|
+
jb.should_receive(:play_random_song)
|
|
133
|
+
jb.play_once
|
|
134
|
+
end
|
|
135
|
+
|
|
136
|
+
xit "can pause the current song" do
|
|
137
|
+
thread = Thread.new do
|
|
138
|
+
jb.play_once
|
|
139
|
+
end
|
|
140
|
+
sleep 0.1
|
|
141
|
+
song_1 = jb.current_song.playing_pid
|
|
142
|
+
jb.pause_current_song
|
|
143
|
+
song_2 = jb.current_song.playing_pid
|
|
144
|
+
song_1.should == song_2
|
|
145
|
+
jb.current_song.paused?.should be_true
|
|
146
|
+
jb.quit
|
|
147
|
+
thread.exit
|
|
148
|
+
end
|
|
149
|
+
|
|
150
|
+
xit "can unpause a paused song" do
|
|
151
|
+
thread = Thread.new do
|
|
152
|
+
jb.play_once
|
|
153
|
+
end
|
|
154
|
+
sleep 0.05
|
|
155
|
+
song_1 = jb.current_song
|
|
156
|
+
jb.current_song.paused?.should be_false
|
|
157
|
+
jb.pause_current_song
|
|
158
|
+
song_2 = jb.current_song
|
|
159
|
+
jb.current_song.paused?.should be_true
|
|
160
|
+
song_2.should == song_1
|
|
161
|
+
jb.unpause_current_song
|
|
162
|
+
jb.current_song.paused?.should be_false
|
|
163
|
+
song_3 = jb.current_song
|
|
164
|
+
jb.current_song.paused?.should be_false
|
|
165
|
+
jb.pause_current_song
|
|
166
|
+
song_4 = jb.current_song
|
|
167
|
+
jb.current_song.paused?.should be_true
|
|
168
|
+
song_4.should == song_3
|
|
169
|
+
jb.unpause_current_song
|
|
170
|
+
jb.current_song.paused?.should be_false
|
|
171
|
+
jb.quit
|
|
172
|
+
thread.exit
|
|
133
173
|
end
|
|
134
|
-
sleep 0.05
|
|
135
|
-
song_1 = Jukebox.current_song
|
|
136
|
-
Jukebox.current_song.paused.should be_false
|
|
137
|
-
Jukebox.pause_current_song
|
|
138
|
-
song_2 = Jukebox.current_song
|
|
139
|
-
Jukebox.current_song.paused.should be_true
|
|
140
|
-
song_2.should == song_1
|
|
141
|
-
Jukebox.unpause_current_song
|
|
142
|
-
Jukebox.current_song.paused.should be_false
|
|
143
|
-
song_3 = Jukebox.current_song
|
|
144
|
-
Jukebox.current_song.paused.should be_false
|
|
145
|
-
Jukebox.pause_current_song
|
|
146
|
-
song_4 = Jukebox.current_song
|
|
147
|
-
Jukebox.current_song.paused.should be_true
|
|
148
|
-
song_4.should == song_3
|
|
149
|
-
Jukebox.unpause_current_song
|
|
150
|
-
Jukebox.current_song.paused.should be_false
|
|
151
|
-
Jukebox.quit
|
|
152
|
-
thread.exit
|
|
153
|
-
end
|
|
154
174
|
|
|
175
|
+
=end
|
|
155
176
|
end
|
|
156
177
|
|
|
178
|
+
end
|
|
179
|
+
=begin
|
|
157
180
|
describe "#play_loop" do
|
|
158
181
|
|
|
159
|
-
|
|
182
|
+
xit "plays multiple songs" do
|
|
160
183
|
thread = Thread.new do
|
|
161
|
-
|
|
184
|
+
jb.play_loop
|
|
162
185
|
end
|
|
163
186
|
sleep 0.1
|
|
164
|
-
song1 =
|
|
187
|
+
song1 = jb.current_song.playing_pid
|
|
165
188
|
song1.should_not be_nil
|
|
166
|
-
|
|
189
|
+
jb.continuous_play.should be_true
|
|
167
190
|
sleep 0.2
|
|
168
|
-
song2 =
|
|
191
|
+
song2 = jb.current_song.playing_pid
|
|
169
192
|
song2.should_not be_nil
|
|
170
193
|
song2.should_not == song1
|
|
171
|
-
|
|
194
|
+
jb.quit
|
|
172
195
|
thread.exit
|
|
173
196
|
end
|
|
174
197
|
|
|
175
|
-
|
|
198
|
+
xit "can skip a song" do
|
|
176
199
|
thread = Thread.new do
|
|
177
|
-
|
|
200
|
+
jb.play_loop
|
|
178
201
|
end
|
|
179
202
|
sleep 0.2
|
|
180
|
-
song_1 =
|
|
181
|
-
|
|
203
|
+
song_1 = jb.current_song
|
|
204
|
+
jb.skip_song
|
|
182
205
|
sleep 0.2
|
|
183
|
-
song_2 =
|
|
184
|
-
|
|
206
|
+
song_2 = jb.current_song
|
|
207
|
+
jb.skip_song
|
|
185
208
|
sleep 0.2
|
|
186
|
-
song_3 =
|
|
209
|
+
song_3 = jb.current_song
|
|
187
210
|
song_1.should_not == song_2 || song_2.should_not == song_3
|
|
188
|
-
|
|
211
|
+
jb.quit
|
|
189
212
|
thread.exit
|
|
190
213
|
end
|
|
191
214
|
|
|
@@ -200,23 +223,25 @@ describe Jukebox do
|
|
|
200
223
|
ARGV << File.expand_path("~/Music")
|
|
201
224
|
end
|
|
202
225
|
|
|
203
|
-
|
|
226
|
+
xit "can skip a song" do
|
|
204
227
|
thread = Thread.new do
|
|
205
|
-
|
|
228
|
+
jb.play_loop
|
|
206
229
|
end
|
|
207
230
|
sleep 0.2
|
|
208
|
-
song_1 =
|
|
209
|
-
|
|
231
|
+
song_1 = jb.current_song
|
|
232
|
+
jb.skip_song
|
|
210
233
|
sleep 0.2
|
|
211
|
-
song_2 =
|
|
212
|
-
|
|
234
|
+
song_2 = jb.current_song
|
|
235
|
+
jb.skip_song
|
|
213
236
|
sleep 0.2
|
|
214
|
-
song_3 =
|
|
237
|
+
song_3 = jb.current_song
|
|
215
238
|
song_1.should_not == song_2 || song_2.should_not == song_3
|
|
216
|
-
|
|
239
|
+
jb.quit
|
|
217
240
|
thread.exit
|
|
218
241
|
end
|
|
219
242
|
|
|
220
243
|
end
|
|
221
244
|
|
|
245
|
+
=end
|
|
246
|
+
|
|
222
247
|
end
|