Class: Sh::MediaPanel
Instance Method Summary collapse
- #duration ⇒ Object
-
#initialize(parent) ⇒ MediaPanel
constructor
A new instance of MediaPanel.
-
#load_file(path) ⇒ Object
Load a media file into the MediaCtrl.
- #on_finished(&block) ⇒ Object
-
#on_media_loaded(evt) ⇒ Object
Set up the initial size for the move.
-
#pause ⇒ Object
Pause the playback.
-
#play ⇒ Object
Start the playback.
-
#position ⇒ Object
Get the position in seconds.
-
#seek(secs) ⇒ Object
Move the media to a position in the file, using the slider.
-
#stop ⇒ Object
Stop the playback.
Constructor Details
#initialize(parent) ⇒ MediaPanel
Returns a new instance of MediaPanel.
104 105 106 107 108 109 110 111 112 |
# File 'lib/sh_player.rb', line 104 def initialize(parent) super(parent) # The actual media player control @mc = Wx::MediaCtrl.new(self) evt_media_loaded @mc, :on_media_loaded evt_media_finished @mc, :on_media_finished end |
Instance Method Details
#duration ⇒ Object
153 154 155 |
# File 'lib/sh_player.rb', line 153 def duration return @mc.length / 1000 end |
#load_file(path) ⇒ Object
Load a media file into the MediaCtrl
126 127 128 129 130 131 |
# File 'lib/sh_player.rb', line 126 def load_file(path) unless @mc.load(path) Sh::Log.warning "Unable to load #{path} into MediaCtrl" on_media_finished nil end end |
#on_finished(&block) ⇒ Object
143 144 145 |
# File 'lib/sh_player.rb', line 143 def on_finished &block @finished_cb = block end |
#on_media_loaded(evt) ⇒ Object
Set up the initial size for the move
139 140 141 |
# File 'lib/sh_player.rb', line 139 def on_media_loaded(evt) @loaded = true end |
#pause ⇒ Object
Pause the playback
163 164 165 |
# File 'lib/sh_player.rb', line 163 def pause @mc.pause end |
#play ⇒ Object
Start the playback
168 169 170 171 172 173 |
# File 'lib/sh_player.rb', line 168 def play unless @mc.play Sh::Log.warning "Unable to play song with MediaCtrl" on_media_finished nil end end |
#position ⇒ Object
Get the position in seconds
115 116 117 118 119 120 121 122 123 |
# File 'lib/sh_player.rb', line 115 def position offset = @mc.tell # Will be -1 if nothing is loaded if offset >= 0 offset_secs = offset / 1000 return offset_secs end return nil end |
#seek(secs) ⇒ Object
Move the media to a position in the file, using the slider
134 135 136 |
# File 'lib/sh_player.rb', line 134 def seek(secs) @mc.seek((secs*1000).to_i) end |
#stop ⇒ Object
Stop the playback
158 159 160 |
# File 'lib/sh_player.rb', line 158 def stop @mc.stop end |