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.
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 !@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.
19 20 21 |
# File 'lib/sh_player.rb', line 19 def play_time @play_time end |
#song ⇒ Object (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 |
#duration ⇒ Object
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 |
#pause ⇒ Object
60 61 62 63 64 |
# File 'lib/sh_player.rb', line 60 def pause @paused = true @playing = false @mp.pause end |
#paused? ⇒ Boolean
70 71 72 |
# File 'lib/sh_player.rb', line 70 def paused? @paused end |
#play ⇒ Object
54 55 56 57 58 |
# File 'lib/sh_player.rb', line 54 def play @paused = false @playing = true @mp.play end |
#playing? ⇒ Boolean
66 67 68 |
# File 'lib/sh_player.rb', line 66 def @playing end |
#position ⇒ Object
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 |