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
#¶ ↑
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
#¶ ↑
commandline_options?¶ ↑
#¶ ↑
# File lib/multimedia_paradise/video/video_player.rb, line 358 def commandline_options? @commandline_options end
#¶ ↑
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
#¶ ↑
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 (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_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
#¶ ↑
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
#¶ ↑
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
#¶ ↑
reset (reset tag)¶ ↑
#¶ ↑
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
#¶ ↑
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_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_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
(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