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.
You're using XP correct?
Could you please take a screenshot of the error?
Sure.. Meanwhile it pops up a window that says "cannot decompress mp42 missing" And then the movie starts to play in background, just the sound though :C
Btw, I really don't care how am I gonna make it to play that damn video. But if there is an easier way, I am all ears. Like if it was possible to open that file with an external app like windows media classic or something like that. I have some knowledge in Matlab and Java / C++ but not really in ruby or rgss. So...
Could you upload the video file to dropbox or mediafire?
Don't mind about the video, was not made by me, gonna ask them if I can use it though.
http://www.mediafire.com/watch/?r1i5xd278n7ttiv
I am also using this "no hang" script, though didn't think it was worth pointing it out.
if @zer_no_hang_stack.nil?
##
# Change the Graphics module so it contains the time of the last update
# Add a getter for the time property
#
module Graphics
# Alias the update method (you have to do it this way since Graphics is a module)
class << self
alias no_hang_update update
end
##
# Change the update method
#
def self.update
@@time = Time.now
self.no_hang_update
end
##
# Retrieve the Time at the last update
#
def self.time
# Protection if this method is called before the first update
@@time = Time.now if @@time.nil?
return @@time
end
end
##
# A separate thread that will run and keep track of the time since the last
# update
#
Thread.new {
loop do
# Lets the thread sleep for a while to minimize CPU usage
sleep 1
# If more than 4 seconds has passed since the last update
if Time.now - Graphics.time > 4
# Update the graphics
Graphics.update
end
end
}
@zer_no_hang_stack = true
end
Where did you get the script?
EDIT: For future request please reference this thread - http://rmrk.net/index.php/topic,19760.0.html
Somewhere across the internet. Just googled rpg maker xp avi file and tried almost 4 different scripts. None worked so far :c
Without the original thread, I can't really figure this script out.
Try these out.
http://forums.rpgmakerweb.com/index.php?/topic/6392-zeus-video-player/
http://www.gdunlimited.net/forums/topic/8595-easy-rgss-video-player/
http://www.rpgmakervxace.net/topic/7177-est-sov-video-player-script-conversion-v-14/
Yeah I have seen some posts like these. Now that I tried out the second link, it actually works. I'm going to have a small demo within a few hours, trying to make it almost 1 hour long. Thank you so much, you can now close this :) You were just awesome Lord Stark, thanks for the support. Also thanks Acolyte for being supportive in the irc too
So guys I have another question, I am using Celestias Ferrum Intro style, like legend of zelda intro with some pics before the game start and the initial screen is actually a map but I wanna join the movie right after you press New Game. Can you help me? Also make it full screen?
Anyone still alive in these forums? Please I want to make a project really cool for you all. And you can be a part of it. I can make a character just like you want in game (I am a "pixel artist")