Class: Eg::Music::MusicPlayer

Inherits:
Object
  • Object
show all
Defined in:
lib/eg/music/music_player.rb

Constant Summary collapse

@@playing =
nil
@@paused =
0

Class Method Summary collapse

Class Method Details

.minutes_remainingObject



57
58
59
# File 'lib/eg/music/music_player.rb', line 57

def MusicPlayer.minutes_remaining
  (MusicPlayer.seconds_remaining / 0.6).ceil / 100.0
end

.pauseObject



31
32
33
34
35
36
37
# File 'lib/eg/music/music_player.rb', line 31

def MusicPlayer.pause
  Music.status = 'pause'
  if (not @@playing.nil?) and @@paused.zero?
    @@paused = (Simulator.next_play_complete - Simulator.time)
    Simulator.next_play_complete = 0
  end
end

.play(music) ⇒ Object

Controls



19
20
21
22
23
24
25
26
27
28
29
# File 'lib/eg/music/music_player.rb', line 19

def MusicPlayer.play music
  if @@paused.zero?
    Music.status = 'loading'
    seconds = (music == @@playing) ? 0.3 : 2.5
    Simulator.next_play_started = Simulator.schedule seconds
  else
    Music.status = 'playing'
    Simulator.next_play_complete = Simulator.schedule @@paused
    @@paused = 0
  end
end

.play_completeObject



69
70
71
72
# File 'lib/eg/music/music_player.rb', line 69

def MusicPlayer.play_complete
  Music.status = 'ready'
  @@playing = nil
end

.play_startedObject

Events



63
64
65
66
67
# File 'lib/eg/music/music_player.rb', line 63

def MusicPlayer.play_started
  Music.status = 'playing'
  @@playing = MusicLibrary.looking
  Simulator.next_play_complete = Simulator.schedule @@playing.seconds
end

.playingObject



15
# File 'lib/eg/music/music_player.rb', line 15

def MusicPlayer.playing; @@playing; end

.seconds_remainingObject

Status



47
48
49
50
51
52
53
54
55
# File 'lib/eg/music/music_player.rb', line 47

def MusicPlayer.seconds_remaining
  if not @@paused.zero?
    return @@paused
  elsif not @@playing.nil?
    return (Simulator.next_play_complete - Simulator.time)
  else
    return 0
  end
end

.stopObject



39
40
41
42
43
# File 'lib/eg/music/music_player.rb', line 39

def MusicPlayer.stop
  Simulator.next_play_started = 0
  Simulator.next_play_complete = 0
  play_complete
end