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.
106 107 108 109 110 111 112 113 114 |
# File 'lib/sh_player.rb', line 106 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
155 156 157 |
# File 'lib/sh_player.rb', line 155 def duration return @mc.length / 1000 end |
#load_file(path) ⇒ Object
Load a media file into the MediaCtrl
128 129 130 131 132 133 |
# File 'lib/sh_player.rb', line 128 def load_file(path) unless @mc.load(path) puts "Unable to load file into MediaCtrl" on_media_finished nil end end |
#on_finished(&block) ⇒ Object
145 146 147 |
# File 'lib/sh_player.rb', line 145 def on_finished &block @finished_cb = block end |
#on_media_loaded(evt) ⇒ Object
Set up the initial size for the move
141 142 143 |
# File 'lib/sh_player.rb', line 141 def on_media_loaded(evt) @loaded = true end |
#pause ⇒ Object
Pause the playback
165 166 167 |
# File 'lib/sh_player.rb', line 165 def pause @mc.pause end |
#play ⇒ Object
Start the playback
170 171 172 173 174 175 |
# File 'lib/sh_player.rb', line 170 def play unless @mc.play puts "Unable to play media with MediaCtrl" on_media_finished nil end end |
#position ⇒ Object
Get the position in seconds
117 118 119 120 121 122 123 124 125 |
# File 'lib/sh_player.rb', line 117 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
136 137 138 |
# File 'lib/sh_player.rb', line 136 def seek(secs) @mc.seek((secs*1000).to_i) end |
#stop ⇒ Object
Stop the playback
160 161 162 |
# File 'lib/sh_player.rb', line 160 def stop @mc.stop end |