module Video
# = = = = = = = = C O N F I G U R A B L E S = = = = = = =
# Depending on XP or VX system (544x416 with RPGMaker VX)
V_MAXWIDTH = 640 # (or 544 if for RMVX)
V_MAXHEIGHT = 480 # (or 416 if for RMVX)
# The Video Escape Button
VIDEO_ESCAPE = Input::B
#=============================================================================
# * Set Video
# video : filename of video
#=============================================================================
def self.load(video)
# Reset invalid flag
@invalid = nil
# Determine that directory exists, set invalid flag to true
begin; Dir.open("./Video"); rescue Errno::ENOENT; @invalid = true; end
# Optional default extension of .avi
video = video + ".avi" if FileTest.exist?("./Video/#{video}.avi")
# Determine that video exists
@invalid = true unless FileTest.exist?("./Video/#{video}")
# Load only valid video
@movie = "./Video/#{video}" unless @invalid == true
end
#=============================================================================
# * Set Start
# start : start in frames to begin video playback (default = nil)
#=============================================================================
def self.start(start=nil)
@start = start
end
#=============================================================================
# * Set Duration
# duration : duration in frames to play the video (default = nil)
#=============================================================================
def self.duration(duration=nil)
@duration = duration
end
#=============================================================================
# * Set Audio
# volume : volume playback (1 to 1000, with 100 default)
#=============================================================================
def self.audio(volume=100)
@volume = volume
end
#=============================================================================
# * Set Window
# left : left position of video (or 'true' if fit in window)
# top : right position of video
# width : width of video window
# height : height of video window
#=============================================================================
def self.window(left=0, top=0, width=V_MAXWIDTH, height=V_MAXHEIGHT)
# If fit in game window
if left == true
@left = 0 ; @top = 0 ; @width = V_MAXWIDTH ; @height = V_MAXHEIGHT
# Or use user-defined settings
else
@left = left ; @top = top ; @width = width ; @height = height
end
end
#=============================================================================
# * Reset All
#=============================================================================
def self.reset
start
duration
audio
window
end
#=============================================================================
# * Play Video
#=============================================================================
def self.play(reset_after_play = false)
# Exit if no valid video
return if @invalid == true
# Windows API Handles
readini = Win32API.new 'kernel32', 'GetPrivateProfileStringA', %w(p p p p l p), 'l'
wnd = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')
@mplayer = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')
# Detect Parameters of Current Game Window
@detector = Win32API.new('user32','GetSystemMetrics','%w(l)','L')
# Load Video File & Attach to Game Window
@mplayer.call("open #{@movie} alias FILM style child parent " +
handle.to_s, 0, 0, 0)
# Prepare the Video
self.prepare(reset_after_play)
# Play Video
info = " " * 255
info2 = " " * 255
info3 = " " * 255
play_message = "play FILM window"
play_message += " from " + @start.to_s if @start != nil
@mplayer.call(play_message, 0, 0, 0)
loop do
sleep(1.0 / 24)
Input.update
@mplayer.call("status FILM mode", info, 255, 0)
@mplayer.call("status FILM position", info2, 255, 0)
state = info.unpack("a*")[0].gsub!("\000","")
if @duration != nil
break if info2.to_i >= @duration
end
# Exit on end or Key control
unless VIDEO_ESCAPE == nil
break if Input.repeat?(VIDEO_ESCAPE) or state.to_s == "stopped"
else
break if state.to_s == "stopped"
end
end
# Reset Audio and Close Video
@mplayer.call("close FILM", 0, 0, 0)
Input.update
end
#--------------------------------------------------------------------------
# * Game Window Handle
#--------------------------------------------------------------------------
def self.handle
game_name = "\0" * 256
readini=Win32API.new('kernel32', 'GetPrivateProfileStringA', 'pppplp', 'l')
readini.call('Game', 'Title', '', game_name, 255, ".\\Game.ini")
return Win32API.new('user32', 'FindWindowEx', 'llpp', 'l').call(0, 0, nil,
game_name.delete!("\0"))
end
#=============================================================================
# * Video Prepare
#=============================================================================
def self.prepare(reset)
# Set defaults
l = 0 ; t = 0; w = V_MAXWIDTH ; h = V_MAXHEIGHT ; v = 100 ; s = nil ; d = nil
# Load options if available
l = @left if @left != nil ; t = @top if @top != nil
w = @width if @width != nil ; h = @height if @height != nil
v = @volume if @volume != nil ; d = @duration if @duration != nil
s = @start if @start != nil
# Prepare
@mplayer.call("put FILM window at #{l} #{t} #{w} #{h}", 0, 0, 0)
@mplayer.call("setaudio FILM volume to #{v}", @status, 0, 0)
# If the called values reset after the movie plays
@left, @top, @width, @height, @volume, @start, @duration = nil, nil, nil, nil, nil, nil, nil if reset
end
end
I keep getting an error when loading the avi file. It has already been converted to match the size limits of 640 x 480 and I have the latest codecs pack so I really don't know what am I doing wrong here.