Class: Sh::Player

Inherits:
Wx::Frame show all
Defined in:
lib/sh_player.rb

Constant Summary collapse

@@scrobble_auth =
nil

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(song) ⇒ Player

Returns a new instance of Player.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sh_player.rb', line 21

def initialize song
  # Initialize frame, even though it will never be made visible
  super(nil,:title=>"",:size=>[0,0])
  self.hide

  @song = song
  @destroyed = false
  @play_time = 0

  # Load media so that it is ready to play
  @mp = MediaPanel.new(self)
  @mp.load_file song.path
  
  # Maintain a rough indication of time spent actually playing audio
  GLib::Timeout.add(1000) do
    @play_time += 1 if playing?
    !@destroyed
  end

  # Cleanup before exiting (Not sure whether this is necessary, but may
  # be useful in the future)
  trap('EXIT') do
    self.stop
    self.demolish
  end
end

Instance Attribute Details

#play_timeObject (readonly)

Returns the value of attribute play_time.



19
20
21
# File 'lib/sh_player.rb', line 19

def play_time
  @play_time
end

#songObject (readonly)

Returns the value of attribute song.



19
20
21
# File 'lib/sh_player.rb', line 19

def song
  @song
end

Instance Method Details

#demolish!Object

Destroys the player (should be called when it is no longer needed)



49
50
51
52
# File 'lib/sh_player.rb', line 49

def demolish!
  @destroyed = true
  self.destroy
end

#durationObject

Get the duration (in seconds)



82
83
84
# File 'lib/sh_player.rb', line 82

def duration
  @mp.duration
end

#on_finished(&block) ⇒ Object



96
97
98
# File 'lib/sh_player.rb', line 96

def on_finished &block
  @mp.on_finished {block.call(self)}
end

#pauseObject



60
61
62
63
64
# File 'lib/sh_player.rb', line 60

def pause
  @paused = true
  @playing = false
  @mp.pause
end

#paused?Boolean

Returns:

  • (Boolean)


70
71
72
# File 'lib/sh_player.rb', line 70

def paused?
  @paused
end

#playObject



54
55
56
57
58
# File 'lib/sh_player.rb', line 54

def play
  @paused = false
  @playing = true
  @mp.play
end

#playing?Boolean

Returns:

  • (Boolean)


66
67
68
# File 'lib/sh_player.rb', line 66

def playing?
  @playing
end

#positionObject

Get the position (in seconds) of playback



87
88
89
# File 'lib/sh_player.rb', line 87

def position
  @mp.position
end

#seek(pos) ⇒ Object

Set the position (in seconds) to start playback from



92
93
94
# File 'lib/sh_player.rb', line 92

def seek pos
  @mp.seek pos
end

#stopObject



74
75
76
77
78
79
# File 'lib/sh_player.rb', line 74

def stop
  @mp.stop

  # Dispatch event notification to plugins
  Plugin.broadcast(:on_player_stopped, self)
end