영상

??(Avi play ver beta 0.8)

by Man... posted Oct 28, 2008
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄
Avi Play
ver Beta 0.8

Authors: My self / From_Ariel
(as I have tweaked it here and there. this was originally an rpgmaker xp script )
and of course the original author
# - FantasyDR # - 2006.3.8 MSN: FantasyDR_SJL@hotmail.com



Information:
This is a robust avi player...

Included features:
  • Auto checking of frame rate and adjusting play speed ro match videos frame rate.
  • Numerous error trapping branches for bad video etc to help identify any problems with the game.
  • Works full screen or windowed but has trouble going back and forth.

Screenshots:

No one at this time it runs in windowed mode fine If i cant get it working in both i might remove the fullscrren code out soon....

Instructions:
Ok this is as simple as pie......
place this script snippet anywhere in your game...
Example .... $MP.play ( "640x480.avi", 3, true, false,x,y,width,height )
Parameters:

[Movie_name]...............video file name (*. avi), must be
[Movie_length]:.............film length, in the seconds if you specify longer than the clip actually lasts it will loop.
[Skip-- (true / false) ].....A key may be whether or not skip, true / false, the default is true
.................................... if skip is set to true then a key press will cause you to exit the movie and continue the game.
[Fullscr--(true / false].....whether or not mandatory for full-screen playback, true / false default is false
[X, y]: .........................video player offset calculated by upper left corner coordinates, the default is 0,0
[Width, height]: the width of video can be arbitrary. Default is 640,480




Demo Link: None yet maybe tomorrow.

Compatibility: Seems to play with all other scripts both vx and xp but has its own challenges.

Challenges:
  • Switching from Windowed to full screen or vice versa has numerous errors associated with it.
  • windowed mode plays but the video wont scale up to meet the size of the video frame.
    (I presume the width / height was intended for that but never got done.)
    As of current width / height changes the size of the big black box the video plays on top of.
  • Full screen don't always seem to initialize right and even if I can get it to launch
  • sometimes the main game window will be minimized when the movies over
    even using the alt+ent trick it just makes stuff more a hassle.
  • L] At present all width // height does is changer the size of the big black background that is behind the move.
    this can make the window breakout of the parents window space/ size..




Author's Notes:

many hours a a day googling. I'm no master scripter but after scouring the next this is the most powerful complete player i could finf.

What I would like to see this do.....
load and play avi file....
if rpg maker is currently in fullscreen then play full screen.
if rpg maker is currently in Windowed then play Windowed.
I would like it to play these files no avi control panel smile.gif
Return to previous screen

also remove those forced key commands.
Use win api to minimizer and restore windows for more predictable behavior..
스크립트
# FantasyDR
# Releases:
# Need to join the script is inside the game works, main and before the MoviePlayer SystemTimer
#================================================= =============================
# ☆ ★ ☆ AVI player ☆ ★ ☆
#------------------------------------------------- -----------------------------
# - FantasyDR
# - 2006.3.8
#------------------------------------------------- -----------------------------
# MSN: FantasyDR_SJL@hotmail.com
#------------------------------------------------- -----------------------------
# Note:
#
# 1. Games must use the model works with the game
#
# 2. PROJECT_NAME = below fill in the back of your game works.
#
# 3. In the game, calling the incident script play your video file, if his party can write no less than a comma after wrapping.
#
# $ MP.play (movie_name, movie_length,
# Skip, fullscr,
# X, y, width, height)
#
# Parameters:
#
# [Movie_name] video file name (*. avi), must be
# [Movie_length]: film, is the second unit, we must
# [Skip] A key may be whether or not skip, true / false, the default is true
# [Fullscr] whether or not mandatory for full-screen playback, true / false, the
# default is false
# [X, y]: video player in the upper left corner coordinates, the default is 0,0
# [Width, height]: the width of video can be arbitrary. Default is 640,480
#
# For example:
# $ MP.play ( "logo.avi", 13, false, true)
#================================================= =============================

class SystemTimer

attr_accessor:decimal #小数位数设定,默认为3



def initialize(use_GetTime=false)

# Initialization, according to choose a different system accuracy of the timer

@qpFrequency = Win32API.new("kernel32","QueryPerformanceFrequency",'p','L')

@qpCounter = Win32API.new("kernel32","QueryPerformanceCounter",'p','L')

@tGetTime = Win32API.new("winmm","timeGetTime",'','L')



@decimal=3

@perf_cnt=" " * 8

@time_start=" " * 8

@time_now=" " * 8



result = @qpFrequency.call(@perf_cnt)



if use_GetTime

result = 0

end



if result!=0

@perf_flag=true

else

@perf_flag=false

@perf_cnt=[1000,0].pack('LL')

end


# Set a time proportion factor

@time_scale=@perf_cnt.unpack('LL')

@time_scale[0] /= 1000.0

@time_scale[1] /= 1000.0


# Start time cleared

self.clear()

end



#-=====================-#

# Timer cleared

#-=====================-#


def clear()

if @perf_flag

@qpCounter.call(@time_start)

else

@time_start=[@tGetTime.call(),0].pack('LL')

end

end



#-==============================-#

# After obtaining the current time, units ms

#-==============================-#

def now()

now_time = 0.0e1

now_time += self.timer() - self.start()

now_time /= self.scale()

return self.debug(now_time)

end


#-==============================-#

# After obtaining the current time, the second unit

#-==============================-#


def now_s()

now_time = 0.0e1

now_time += self.timer() - self.start()

now_time /= (self.scale()*1000)

return self.debug(now_time)

end


#-==============================-#

# Frame wrong ...

#-==============================-#


def debug(now_time)

if @decimal>0

now_time = (now_time * (10**@decimal)).floor/(10.0**@decimal)

else

now_time = now_time.floor

end

return now_time




# Debug mode for the following

if now_time < 0

p "Timer Wrong!! Clear...",now_time,

@perf_flag,@qpCounter,@tGetTime,

@time_now.unpack('LL')[0],@time_now.unpack('LL')[1],

@time_start.unpack('LL')[0],@time_start.unpack('LL')[1]

self.clear()

return 0.0

else

return now_time

end

end



#-=====================-#

# Access to the proportion of time factor

#-=====================-#

def scale()

return @time_scale[0]+

@time_scale[1]*0xffffffff

end



#-=====================-#

# Access to a few initial tack

#-=====================-#

def start()

return @time_start.unpack('LL')[0]+

@time_start.unpack('LL')[1]*0xffffffff

end



#-=====================-#

# Access to the current number of Di pyridazinones

#-=====================-#

def timer()

if @perf_flag

@qpCounter.call(@time_now)

else

@time_now=[@tGetTime.call(),0].pack('LL')

end

return @time_now.unpack('LL')[0]+

@time_now.unpack('LL')[1]*0xffffffff

end

end

#-------------------------------------#

# Initialize itself into a global variables

#-------------------------------------#

$sys_timer=SystemTimer.new()

#-------------------------------------#



#-------------------------------------#



#================================================= =============================

# ☆ ★ ☆ AVI player ☆ ★ ☆

#------------------------------------------------- -----------------------------

# - FantasyDR

# - 2006.3.8

#------------------------------------------------- -----------------------------

# MSN: FantasyDR_SJL@hotmail.com

#------------------------------------------------- -----------------------------

# Note:

#

# 1. Games must use the model works with the game RGSS102J.dll

#

# 2. PROJECT_NAME = below fill in the back of your game works.

#

# 3. In the game, calling the incident script play your video file, if his party can write no less than a comma after wrapping.

#

# $ MP.play (movie_name, movie_length,

# Skip, fullscr,

# X, y, width, height, loop)

#

# Parameters:

#

# Movie_name: video file name (*. avi), must be

# Movie_length: film, is the second unit, we must

# Skip: A key may be whether or not skip, true / false, the default is true

# Fullscr: whether or not mandatory for full-screen playback, true / false, the default is false

# X, y: video player in the upper left corner coordinates, the default is 0,0

# Width, height: the width of video can be arbitrary. Default is 640,480

# Loop: loop, true / false, the default is true

#

# For example, players logo.avi, time 13 seconds, Skip ban, compulsory full-screen, the scope of (a 0,0) - (640,480), the loop

# $ MP.play ( "logo.avi", 13, false, true)

#================================================= =============================

# ★ ★ ★ Please fill out the game works here were ★ ★ ★
################################################################################
################################################################################
#### ▓▓▓▓▓▓▒░ ▓▓▓▓▓▒░ ▓▓▓▓▓▒░ ▓▓▓▓▓▓▓ ▓▓▓▓▓▓ ▓▓▓▓▓▒░ ▓▓▓▓▓▓▓▓ ###
#### ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ###
#### ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ###
#### ▓▓▓▓▓▓▓▒░ ▓▓▓▓▓▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▓▓▓▓ ▓▒░ ▓▒░ ###
#### ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ###
#### ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ###
#### ▓▒░ ▓▒░ ▓▒░ ▓▓▓▓▓▒░ ▓▓▓▒░ ▓▓▓▓▓ ▓▓▓▓▓▒░ ▓▒░ ###
#### ###
#### ▓▓▒░ ▓▒░ ▓▓▒░ ▓▒░ ▓▒░ ▓▓▓▓▓▒░ ▓▒░ ###
#### ▓▒▓▒░ ▓▒░ ▓▒░▓▒░ ▓▓▒░ ▓▓▒░ ▓▒░ ▓▒░ ###
#### ▓▒░▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▓▒░ ▓▓▒░ ▓▒░ ▓▒░ ###
#### ▓▒░ ▓▒░▓▒░ ▓▓▓▓▓▓▓▓▒░ ▓▒▓▒░▓ ▓▒░ ▓▓▓▓▒░ ▓▒░ ###
#### ▓▒░ ▓▒▓▒░ ▓▒░ ▓▒░ ▓▒▓▒░▓ ▓▒░ ▓▒░ ▓▒░ ###
#### ▓▒░ ▓▓▒░ ▓▒░ ▓▒░ ▓▒░▓ ▓▒░ ▓▒░ ###
#### ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▒░ ▓▓▓▓▓▒░ ▓▒░ ###
################################################################################
################################################################################
PROJECT_NAME = "Project1"

#================================================= =============================

# ■ Win32API

#------------------------------------------------- -----------------------------

# Need to use the API

#================================================= =============================

# Switch to full-screen delay

SWITCH_DELAY = 0.1

# API used by some constants

MCI_ANIM_WINDOW_ENABLE_STRETCH = 0x100000


WS_EX_TOPMOST = 0x8

SHOW_FULLSCREEN =(3)

WM_ACTIVATE =(6)

WS_EX_TOOLWINDOW= 0x80

WS_VISIBLE = 0x10000000

WS_POPUP = 0x80000000

GWL_HINSTANCE = (-6)

WM_CLOSE = 0x10

WS_CHILD = 0x40000000

WS_NONE = 0x16000000

CP_ACP = 0

CP_UTF8 = 65001

# Character encoding conversion API

$MP_m2w = Win32API.new('kernel32', 'MultiByteToWideChar', '%w(i,l,p,i,p,i)', 'i')

$MP_w2m = Win32API.new('kernel32', 'WideCharToMultiByte', '%w(i,l,p,i,p,i,p,p)', 'i')



# Keys API

$MP_keybd = Win32API.new('user32', 'keybd_event', '%w(i,i,l,l)', 'v')

# Video playback API

$MP_mciSendString = Win32API.new('winmm','mciSendString','%w(p,p,l,l)','V')


# Locked window

# HWnd, ifEnable

$MP_EnableWindow = Win32API.new('user32','EnableWindow','%w(l,l)','L')

# Activation window

# HWnd

$MP_SetActiveWindow = Win32API.new('user32','SetActiveWindow','%w(l)','L')

# Current activities window

$MP_GetActiveWindow = Win32API.new('user32','GetActiveWindow','%w()','L')

# hWnd,wMsg,wParam,lParam

$MP_PostMessage = Win32API.new('user32','PostMessage','%w(l,l,l,p)','L')

# Access to the current window handle

$MP_FindWindowEX = Win32API.new('user32','FindWindowEx','%w(l,l,p,p)','L')

# Access to the screen coordinates

$MP_ClientToScreen = Win32API.new("user32", "ClientToScreen", 'ip', 'i')

# Access hInt

$MP_GetWindowLong= Win32API.new('user32','GetWindowLong','%w(l,l)','L')

# 获取类名

# hWnd,lpClassName,maxCount

$MP_GetClassName= Win32API.new('user32','GetClassName','%w(l,p,l)','L')

# Create the form

# ExStyle, ClassName, WindowName,

# Style, x, y, width, height

# 0,0, hInstance, 0

$MP_CreateWindowEX = Win32API.new('user32','CreateWindowEx','%w(l,p,p,l,l,l,l,l,l,l,l,p)','L')


#================================================= =============================

# ■ MoviePlayer

#------------------------------------------------- -----------------------------

# Handle video screen category.

#================================================= =============================
class MoviePlayer


#================================================= =============================

# ■ MoviePlayer

#------------------------------------------------- -----------------------------

# Handle video screen category.

#================================================= =============================

def initialize(project_name = PROJECT_NAME)

@sys_timer=SystemTimer.new()

buffer = "" * project_name.size

@project_name = "" * project_name.size



$MP_m2w.call(CP_UTF8, 0, project_name, -1, buffer, project_name.size)

$MP_w2m.call(CP_ACP,0,buffer,-1,@project_name,project_name.size,0,0)



@hWnd = $MP_FindWindowEX.call(0,0,nil,@project_name)

@hInt = $MP_GetWindowLong.call(@hWnd,GWL_HINSTANCE)

@class_name = " " * 256

$MP_GetClassName.call(@hWnd,@class_name,256)

end

#------------------------------------------------- -------------------------

# ● whether full-screen

#------------------------------------------------- ------------------------- --------------------------------------------------------------------------

def is_full?

# Players start coordinates

point = [0, 0].pack('ll')

if $MP_ClientToScreen.call(@hWnd, point) == 0

return false

end

x, y = point.unpack('ll')

if x == 0 and y == 0

return true

else

return false

end

end

#------------------------------------------------- -------------------------

# ● full-screen switch

#------------------------------------------------- -------------------------

def switch_full

#~ $MP_keybd.call (0xA4, 0, 0, 0)

#~ $MP_keybd.call (13, 0, 0, 0)

#~ $MP_keybd.call (13, 0, 2, 0)

#~ $MP_keybd.call (0xA4, 0, 2, 0)


Graphics.update

sleep(SWITCH_DELAY)

Graphics.update

end

#------------------------------------------------- -------------------------

# ● movies

# Movie_name: video file name (*. avi)

# Movie_length: film, is the second unit

# Skip: can skip button

# Fullscr: whether or not mandatory for full-screen playback

# X, y, width, height: the location and width of players

# Loop: loop

#------------------------------------------------- -------------------------

def play(movie_name,movie_length,

skip = true,fullscr = false,

x = 0,y = 0,width = 1088,height = 832,loop = true)


# Data not rule out

return true if movie_name == nil or movie_length <= 0

# File does not exist

movie_name = Dir.getwd()+"Movies"+movie_name

return true unless FileTest.exist?(movie_name)

# File does not exist

width -= (x + width)- 1088 if (x + width) > 1088

height -= (y + height)- 832 if (y + height) > 832



if fullscr and !is_full?

self.switch_full

end



fullscr = self.is_full?



# Width of the window

point = [x, y].pack('ll')

if $MP_ClientToScreen.call(@hWnd, point) == 0

return true

end

x, y = point.unpack('ll')

return true if (x + width) < 0 or (y+height) < 0



if fullscr

wnd = $MP_CreateWindowEX.call(WS_EX_TOPMOST,@class_name,@project_name,

SHOW_FULLSCREEN | WS_VISIBLE | WS_POPUP,x,y,width,height,

0,0,@hInt,0)

else

wnd = $MP_CreateWindowEX.call(WS_EX_TOOLWINDOW,@class_name,@project_name,
SHOW_FULLSCREEN | WS_VISIBLE | WS_POPUP,x,y,width,height,

0,0,@hInt,0)

end


# Players start coordinates

return true if wnd == 0




# Shielding the original form

$MP_EnableWindow.call(@hWnd,0)



$MP_mciSendString.call("open "" + movie_name + """ +

" alias FILE style 1073741824 parent " +

wnd.to_s,0,0,0)

if loop

$MP_mciSendString.call("play FILE repeat window ",0,0,MCI_ANIM_WINDOW_ENABLE_STRETCH)

else

$MP_mciSendString.call("play FILE window",0,0,MCI_ANIM_WINDOW_ENABLE_STRETCH)

end



@sys_timer.clear()

step = 0.1

begin

loop do

# If the window mode

unless fullscr

# Become a full-screen

if self.is_full?

break

else

Graphics.update

end

end

#sleep(step)

if skip

Input.update

break if Input.trigger?(Input::A)

end

if @sys_timer.now_s >= movie_length

break

end

if $MP_GetActiveWindow.call() != wnd

$MP_SetActiveWindow.call(wnd)

end

end

rescue Hangup

retry

end

# Close current form and bring main window to front

$MP_PostMessage.call(wnd,WM_CLOSE,0,0)

$MP_mciSendString.call("close FILE",0,0,0)

$MP_EnableWindow.call(@hWnd,1)

$MP_SetActiveWindow.call(@hWnd)

return true

end

end

$MP = MoviePlayer.new