Class: MMPlayer::Player::Invoker

Inherits:
Object
  • Object
show all
Defined in:
lib/mmplayer/player/invoker.rb

Overview

Invoke MPlayer

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Invoker

Returns a new instance of Invoker.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :flags (String)

    MPlayer command-line flags to use on startup



12
13
14
15
16
17
# File 'lib/mmplayer/player/invoker.rb', line 12

def initialize(options = {})
  @flags = "-fixed-vo -idle"
  @flags += " #{options[:flags]}" unless options[:flags].nil?
  @player.nil?
  @thread = nil
end

Instance Attribute Details

#playerObject (readonly)

Returns the value of attribute player.



8
9
10
# File 'lib/mmplayer/player/invoker.rb', line 8

def player
  @player
end

#threadObject (readonly)

Returns the value of attribute thread.



8
9
10
# File 'lib/mmplayer/player/invoker.rb', line 8

def thread
  @thread
end

Instance Method Details

#destroyObject



19
20
21
# File 'lib/mmplayer/player/invoker.rb', line 19

def destroy
  @thread.kill unless @thread.nil?
end

#ensure_invoked(file, state) ⇒ MPlayer::Slave

Ensure that the MPlayer process is invoked

Parameters:

  • file (String)

    The media file to invoke MPlayer with

  • state (MMplayer::Player::State)

Returns:

  • (MPlayer::Slave)


27
28
29
30
31
32
33
34
35
# File 'lib/mmplayer/player/invoker.rb', line 27

def ensure_invoked(file, state)
  if @player.nil? && @thread.nil?
    @thread = ::MMPlayer::Thread.new(:timeout => false) do
      @player = MPlayer::Slave.new(file, :options => @flags)
      state.handle_start
    end
  end
  @player
end