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.



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

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.



17
18
19
# File 'lib/sh_player.rb', line 17

def play_time
  @play_time
end

#songObject (readonly)

Returns the value of attribute song.



17
18
19
# File 'lib/sh_player.rb', line 17

def song
  @song
end

Instance Method Details

#demolish!Object

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



47
48
49
50
# File 'lib/sh_player.rb', line 47

def demolish!
  @destroyed = true
  self.destroy
end

#durationObject

Get the duration (in seconds)



80
81
82
# File 'lib/sh_player.rb', line 80

def duration
  @mp.duration
end

#on_finished(&block) ⇒ Object



94
95
96
# File 'lib/sh_player.rb', line 94

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

#pauseObject



58
59
60
61
62
# File 'lib/sh_player.rb', line 58

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

#paused?Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/sh_player.rb', line 68

def paused?
  @paused
end

#playObject



52
53
54
55
56
# File 'lib/sh_player.rb', line 52

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

#playing?Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/sh_player.rb', line 64

def playing?
  @playing
end

#positionObject

Get the position (in seconds) of playback



85
86
87
# File 'lib/sh_player.rb', line 85

def position
  @mp.position
end

#seek(pos) ⇒ Object

Set the position (in seconds) to start playback from



90
91
92
# File 'lib/sh_player.rb', line 90

def seek pos
  @mp.seek pos
end

#stopObject



72
73
74
75
76
77
# File 'lib/sh_player.rb', line 72

def stop
  @mp.stop

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