#=============================================================================== # By trebor777 # Date: 26/10/2008 # Version 1.5 - Updated 27/10/2008 #------------------------------------------------------------------------------- # RMVX Avi Player # # Instructions: # Video Specification ( to ensure good playability ) # Recommended encoding: Xvid + MP3 CBR (very important to keep a constant # bit rate for the audio, else it won't play it) # Video Resolution : Up to 640*480 # Save the videos into a new folder called Movies in your project root folder. # # Call in an event(using the call script command) or in your script: # # Movie.play("myvideo",width,height) # Movie.play("myvideo") # # By providing the dimensions of your video, if smaller than 640*480, the script # will stretch it in the window(or in the screen if in fullscreen), to fit a # width of 640px, but keeping the original aspect ratio. # # Don't need to provide the dimensions if the video is 640*480. #=============================================================================== module Movie attr_accessor :fps def self.play(movie, width=Graphics.width, height=Graphics.height) movie= "./Movies/#{movie}.avi" fps = 24 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') @detector = Win32API.new('user32','GetSystemMetrics','%w(l)','L') timer= 1.0/fps info= " " * 255 game_name= "\0" * 256 readini.call('Game','Title','',game_name,255,".\\Game.ini") game_name.delete!("\0") hwnd= wnd.call(0,0,nil,game_name).to_s @mplayer.call("open #{movie} alias FILM style child parent #{hwnd}",0,0,0) @mplayer.call("status FILM length",info,255,0) movie_lenght = info.unpack("a*")[0].gsub!("\000","").to_i info= " " * 255 @ratio = height.to_f/width @width = 0 self.update_stretch @mplayer.call("play FILM window",0,0,0) loop do sleep(timer) Input.update update_stretch @mplayer.call("status FILM mode",info,255,0) s= info.unpack("a*")[0].gsub!("\000","") break if Input.repeat?(Input::B) or s.to_s == "stopped" end @mplayer.call("close FILM",0,0,0) Input.update end def self.update_stretch n_w = @detector.call(0) if @width != n_w @width = n_w w = (n_w == 544)? 544 : Graphics.width h = (n_w == 544)? 416 : Graphics.height new_height = (w*@ratio).round @mplayer.call("put FILM window at 0 #{(h-new_height)/2} #{w} #{new_height}",0,0,0) end end end
|