Class: Sh::MediaPanel

Inherits:
Wx::Panel
  • Object
show all
Defined in:
lib/sh_player.rb

Instance Method Summary collapse

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

#durationObject



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

#pauseObject

Pause the playback



165
166
167
# File 'lib/sh_player.rb', line 165

def pause
  @mc.pause
end

#playObject

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

#positionObject

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

#stopObject

Stop the playback



160
161
162
# File 'lib/sh_player.rb', line 160

def stop
  @mc.stop
end