Class: MPlayer::Slave

Inherits:
Object
  • Object
show all
Includes:
SlaveCommands, SlaveVideoCommands
Defined in:
lib/mplayer-ruby/slave.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from SlaveVideoCommands

#audio_delay, #brightness, #contrast, #frame_drop, #gamma, #hue, #osd, #osd_show_property_text, #osd_show_text, #saturation, #sub_alignment, #sub_delay, #sub_demux, #sub_file, #sub_load, #sub_pos, #sub_remove, #sub_scale, #sub_select, #sub_source, #sub_step, #sub_visibility, #sub_vob, #switch_angle, #switch_audio, #switch_ratio, #switch_title, #switch_vsync

Methods included from SlaveCommands

#alt_src_step, #back, #edl_mark, #frame_step, #get, #load_file, #load_list, #loop, #mute, #next, #pause, #pt_step, #pt_up_step, #quit, #seek, #speed, #speed_incr, #speed_mult, #speed_set, #use_master, #volume

Constructor Details

#initialize(file = "", options = {:path => '/usr/bin/mplayer'}) ⇒ Slave

Initializes a new instance of MPlayer. set :path to point to the location of mplayer defaults to ‘/usr/bin/mplayer’

Raises:

  • (ArgumentError)


12
13
14
15
16
17
18
19
# File 'lib/mplayer-ruby/slave.rb', line 12

def initialize(file = "",options ={:path => '/usr/bin/mplayer'})
  raise ArgumentError,"Invalid File" unless File.exists?(file)
  @file = file
  mplayer = "#{options[:path]} -slave -quiet #{@file}"
  @pid,@stdin,@stdout,@stderr = Open4.popen4(mplayer)
  until @stdout.gets.inspect =~ /playback/ do
  end #fast forward to the desired output
end

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



4
5
6
# File 'lib/mplayer-ruby/slave.rb', line 4

def file
  @file
end

#pidObject (readonly)

Returns the value of attribute pid.



4
5
6
# File 'lib/mplayer-ruby/slave.rb', line 4

def pid
  @pid
end

#stderrObject (readonly)

Returns the value of attribute stderr.



4
5
6
# File 'lib/mplayer-ruby/slave.rb', line 4

def stderr
  @stderr
end

#stdinObject

Returns the value of attribute stdin.



3
4
5
# File 'lib/mplayer-ruby/slave.rb', line 3

def stdin
  @stdin
end

#stdoutObject (readonly)

Returns the value of attribute stdout.



4
5
6
# File 'lib/mplayer-ruby/slave.rb', line 4

def stdout
  @stdout
end

Instance Method Details

#send(cmd, match = //) ⇒ Object

sends command to mplayer stdin and retrieves stdout. If match is provided, fast-forwards stdout to matching response.



23
24
25
26
27
28
29
30
# File 'lib/mplayer-ruby/slave.rb', line 23

def send(cmd,match = //)
  @stdin.puts(cmd)
  response = @stdout.gets
  until response =~ match
    response = @stdout.gets
  end
  response.gsub("\e[A\r\e[K","")
end