Class: Sh::Player
Constant Summary collapse
- @@scrobble_auth =
nil
Instance Attribute Summary collapse
-
#play_time ⇒ Object
readonly
Returns the value of attribute play_time.
-
#song ⇒ Object
readonly
Returns the value of attribute song.
Instance Method Summary collapse
-
#demolish! ⇒ Object
Destroys the player (should be called when it is no longer needed).
-
#duration ⇒ Object
Get the duration (in seconds).
-
#initialize(song) ⇒ Player
constructor
A new instance of Player.
- #on_finished(&block) ⇒ Object
- #pause ⇒ Object
- #paused? ⇒ Boolean
- #play ⇒ Object
- #playing? ⇒ Boolean
-
#position ⇒ Object
Get the position (in seconds) of playback.
-
#seek(pos) ⇒ Object
Set the position (in seconds) to start playback from.
- #stop ⇒ Object
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 !@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_time ⇒ Object (readonly)
Returns the value of attribute play_time.
17 18 19 |
# File 'lib/sh_player.rb', line 17 def play_time @play_time end |
#song ⇒ Object (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 |
#duration ⇒ Object
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 |
#pause ⇒ Object
58 59 60 61 62 |
# File 'lib/sh_player.rb', line 58 def pause @paused = true @playing = false @mp.pause end |
#paused? ⇒ Boolean
68 69 70 |
# File 'lib/sh_player.rb', line 68 def paused? @paused end |
#play ⇒ Object
52 53 54 55 56 |
# File 'lib/sh_player.rb', line 52 def play @paused = false @playing = true @mp.play end |
#playing? ⇒ Boolean
64 65 66 |
# File 'lib/sh_player.rb', line 64 def @playing end |
#position ⇒ Object
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 |