class MultimediaParadise::VideoPlayer

Constants

BE_VERBOSE
#

BE_VERBOSE

#
COLOUR_WARN
#

COLOUR_WARN

#
DEBUG
#

DEBUG

#
DEFAULT_COLOUR
#

Setup the colours to use.

#
DEFAULT_PLAY_MODE
#

DEFAULT_PLAY_MODE

#
FANCY_COLOUR
NAMESPACE
#

NAMESPACE

#
USE_VO_X11
#

USE_VO_X11

If true then we will use ‘-vo x11’

#

Public Class Methods

new( commandline_options = nil, run_already = true ) click to toggle source
#

initialize

#
# File lib/multimedia_paradise/video/video_player.rb, line 97
def initialize(
    commandline_options = nil,
    run_already         = true
  )
  register_sigint
  reset
  set_runmode :standalone
  set_commandline_options(
    commandline_options
  )
  case run_already
  when :dont_run_yet, :do_not_run_yet
    run_already = false
  end
  run if run_already
end

Public Instance Methods

add(i = nil) click to toggle source
#

add

#
# File lib/multimedia_paradise/video/video_player.rb, line 253
def add(i = nil)
  if i
    @array_play_these_video_files << i unless i.empty?
  end
end
add_all_videos() click to toggle source
#

add_all_videos

#
# File lib/multimedia_paradise/video/video_player.rb, line 481
def add_all_videos
  add(obtain_all_video_files.sort)
end
check_against_menu( i = commandline_options? )
Alias for: menu
commandline?()
commandline_options?() click to toggle source
#

commandline_options?

#
# File lib/multimedia_paradise/video/video_player.rb, line 358
def commandline_options?
  @commandline_options
end
Also aliased as: commandline?
disable_video() click to toggle source
#

disable_video

Use this method to disable video playback. You still get the audio output of the video file of course.

#
# File lib/multimedia_paradise/video/video_player.rb, line 201
def disable_video
  @disable_video = true
end
exit_program() click to toggle source
#

exit_program

Use only this method when you want to exit from this program.

#
# File lib/multimedia_paradise/video/video_player.rb, line 503
def exit_program
  case runmode?
  when 'standalone'
    exit
  else # else pass through.
  end
end
feedback_available_videos() click to toggle source
#

feedback_available_videos (listing tag)

Use this method to feedback all available video files.

#
# File lib/multimedia_paradise/video/video_player.rb, line 490
def feedback_available_videos
  videos?.uniq.sort_by {|line| File.basename(line)}.each {|entry|
    file = File.basename(entry)
    dir  = File.dirname(entry)
    e '  '+sdir(dir)+'/'+sfile(file)
  }
end
menu( i = commandline_options? ) click to toggle source
#

menu (menu tag)

#
Also aliased as: check_against_menu
obtain_all_video_files() click to toggle source
#

obtain_all_video_files

#
# File lib/multimedia_paradise/video/video_player.rb, line 377
def obtain_all_video_files
  # ======================================================================= #
  # Return only video files. And only from the target location.
  # ======================================================================= #
  files = Dir[@target_location+'**/**']
  filter_for_video_files(files)
end
play(i) click to toggle source
#

play (play tag)

Use this method to play the respective video file in question.

We will also pad the filename.

#
# File lib/multimedia_paradise/video/video_player.rb, line 315
def play(i)
  e 'In play() the argument was '+sfancy(i.to_s) if @debug
  if i.is_a? Array
    i.each {|entry| play(entry) }
  else
    i.strip!
    i.gsub!(/  /,' ') if i.include? '  '
    @count_how_many_times_we_played_already += 1
    if @count_how_many_times_we_played_already > 1000
      e 'We played more than 1000 files. We will exit now.'
      @shall_we_exit = true
    end
    if @use_wrapper_over_mplayer # Use the mplayer-wrapper in this case.
      Mplayer.new(i)
    else # else just build the command.
      _ = ::MultimediaParadise.which_video_player_to_use?.dup
      if @disable_video
        _ << ' -vo null '
      else
        _ << ' -vo x11' if USE_VO_X11
        # ================================================================= #
        # mpv does no longer support - zoom, whereas mplayer does.
        # ================================================================= #
        _ << ' -zoom'   if PLAY_ZOOMED and _.include? 'mplayer'
      end
      # =================================================================== #
      # Save which video file was last played next.
      # =================================================================== #
      save_last_video_file_played(i)
      # =================================================================== #
      # Pad the given input next.
      # =================================================================== #
      i = '"'+i+'"'
      _ << ' '+i
      e _
      system _ # Could also use: `#{_}`
    end
  end
end
play_in_a_loop?() click to toggle source
#

play_in_a_loop?

#
# File lib/multimedia_paradise/video/video_player.rb, line 269
def play_in_a_loop?
  @play_in_a_loop
end
play_video_file( i = @array_play_these_video_files )
Alias for: play_video_files
play_video_files( i = @array_play_these_video_files ) click to toggle source
#

play_video_files

#
# File lib/multimedia_paradise/video/video_player.rb, line 276
def play_video_files(
    i = @array_play_these_video_files
  )
  if i.empty?
    opnn; e 'Can not play any video file - our collection is empty.'
  else
    if play_in_a_loop?
      loop {
        play(random_video)
        break if @shall_we_exit
      }
    else
      play(video_files?)
    end
  end
end
Also aliased as: play_video_file
random_video(i = @matches) click to toggle source
#

random_video

This will return a random video.

It assumes that the @matches array exists; otherwise you will have to provide an array with all videos to this method.

#
# File lib/multimedia_paradise/video/video_player.rb, line 553
def random_video(i = @matches)
  i[rand(i.size)]
end
random_video?(i = @matches)
Alias for: random_video
register_sigint() click to toggle source
#

register_sigint

Silently restore the prompt again here via reset, which is done via a system() call.

#
# File lib/multimedia_paradise/video/video_player.rb, line 225
def register_sigint
  sigint_proc = proc {
    system 'reset'
    efancy 'Requested to exit from MultimediaParadise::VideoPlayer. Exiting now.'
    @shall_we_exit = true
    exit_program
  }
  Signal.trap 'SIGINT', sigint_proc
end
report_filename() click to toggle source
#

report_filename

Simply prepend the filename.

#
# File lib/multimedia_paradise/video/video_player.rb, line 191
def report_filename
  File.basename(__FILE__)+': '
end
reset() click to toggle source
#

reset (reset tag)

#
Calls superclass method MultimediaParadise::Base#reset
# File lib/multimedia_paradise/video/video_player.rb, line 117
def reset
  super()
  # ======================================================================= #
  # === @namespace
  # ======================================================================= #
  @namespace = NAMESPACE
  # ======================================================================= #
  # === @use_wrapper_over_mplayer
  # ======================================================================= #
  set_be_verbose
  @use_wrapper_over_mplayer = false
  # ======================================================================= #
  # === @debug
  # ======================================================================= #
  @debug = false # Whether to debug or whether we won't.
  # ======================================================================= #
  # === @target_location
  #
  # The ivar @target_location will tell us where we have to search for.
  #
  # For instance, it can be '/Depot/Video/' or '/home/x/VIDEO/'.
  # ======================================================================= #
  @target_location = '/home/x/video/'.dup # We may need to change it.
  @shall_we_exit = false
  # ======================================================================= #
  # === @colour
  # ======================================================================= #
  @colour = DEFAULT_COLOUR
  # ======================================================================= #
  # === @disable_video
  # ======================================================================= #
  @disable_video = false
  # ======================================================================= #
  # @array_play_these_video_files is an Array that tells us which
  # video files will be played.
  # ======================================================================= #
  @array_play_these_video_files = []
  # ======================================================================= #
  # We keep track how many times we played a video file.
  # ======================================================================= #
  @count_how_many_times_we_played_already = 0
  @play_in_a_loop = false
  set_runmode :standalone # Set @runmode to 'standalone'
end
return_random_video(i = @matches)
Alias for: random_video
run() click to toggle source
#

run

#
# File lib/multimedia_paradise/video/video_player.rb, line 561
def run
  check_against_menu
  play_video_files
end
runmode?() click to toggle source
#

runmode?

#
# File lib/multimedia_paradise/video/video_player.rb, line 238
def runmode?
  @runmode
end
save_last_video_file_played(i = nil) click to toggle source
#

save_last_video_file_played

This method saves which video file was last played.

By default it stores into “$HOME/last_video_file_played”.

#
# File lib/multimedia_paradise/video/video_player.rb, line 300
def save_last_video_file_played(i = nil)
  if i
    store_where = HOME_DIR+'last_video_file_played'
    opnn; e 'Storing at `'+sfile(store_where)+'`.'
    save_file(i, store_where)
  end
end
set_be_verbose(i = BE_VERBOSE) click to toggle source
#

set_be_verbose

#
# File lib/multimedia_paradise/video/video_player.rb, line 208
def set_be_verbose(i = BE_VERBOSE)
  @be_verbose = i
end
set_commandline_options(i) click to toggle source
#

set_commandline_options

#
# File lib/multimedia_paradise/video/video_player.rb, line 365
def set_commandline_options(i)
  i = i.join(' ').strip if i.is_a? Array
  # ======================================================================= #
  # Get rid of ',' if they are part of a String.
  # ======================================================================= #
  i.delete!(',') if i.include? ','
  @commandline_options = i # Will be a String.
end
set_debug(i = DEBUG) click to toggle source
#

set_debug

#
# File lib/multimedia_paradise/video/video_player.rb, line 215
def set_debug(i = DEBUG)
  @debug = DEBUG
end
set_runmode(i = 'standalone') click to toggle source
#

set_runmode

This method can be used to set the runmode.

We currently support only two runmodes:

- standalone, or
- connected.

‘s’ is an alias to standalone. Some more aliases exist, see the case menu below for details.

#
# File lib/multimedia_paradise/video/video_player.rb, line 175
def set_runmode(i = 'standalone')
  i = i.to_s
  case i
  when 'conn'
    i = 'connected'
  when 's','solo','stand'
    i = 'standalone'
  end
  @runmode = i
end
show_help( prepend_this = 'Help requested. ' ) click to toggle source
#

show_help (help tag)

This method will tell us which options are available for this class.

It can be invoked via these keywords:

help? help hel h h? ?

rvid –help

#
# File lib/multimedia_paradise/video/video_player.rb, line 530
def show_help(
    prepend_this = 'Help requested. '
  )
  e prepend_this+N+N unless prepend_this.empty?
  e 'These options are available:'
  e
  e simp('  loop')
  e simp('  simpsons')
  e simp('  science')
  e simp('  married')
  e simp('  mma')
  e simp('  pwd')
  e
end
show_help_then_exit() click to toggle source
#

show_help_then_exit (help tag)

#
# File lib/multimedia_paradise/video/video_player.rb, line 514
def show_help_then_exit
  show_help
  exit
end
video_files?() click to toggle source
#

video_files?

#
# File lib/multimedia_paradise/video/video_player.rb, line 262
def video_files?
  @array_play_these_video_files.flatten
end
Also aliased as: videos?
videos?()
Alias for: video_files?
warn_then_exit(i) click to toggle source
#

warn_then_exit

#
# File lib/multimedia_paradise/video/video_player.rb, line 245
def warn_then_exit(i)
  e Colours::RED+i
  exit_program
end