HSPでFlashを再生するサンプル

2009.03.22 01:55

// 不等号がタグと認識されるのを回避するため全角文字に置き換えてます。



#define EXENAME "flaHSPlayer"
#packopt name EXENAME
#packopt hide 1

#enum WINID_MAIN =0
#enum WINID_BUFF
#const NICO_W 512
#const NICO_H 384
#const SEEKBAR_H 32
#const KBD_TAB 9
#const KBD_ENTER 13
#const KBD_ESCAPE 27
#const KBD_SPACE 32
#const MOUSE_L 256
#const MOUSE_R 512
#const WP_MOUSE_L 1
#const WP_MOUSE_R 2
// TGetProperty
#const SWF_X_Position 0
#const SWF_Y_Position 1
#const SWF_X_SCALE 2
#const SWF_Y_SCALE 3
#const SWF_CURRENT_FRAME 4
#const SWF_TOTAL_FRAMES 5
#const SWF_ALPHA 6
#const SWF_VISIBLE 7
#const SWF_WIDTH 8
#const SWF_HEIGHT 9
#const SWF_ROTATE 10
#const SWF_TARGET 11
#const SWF_FRAMES_LOADED 12
#const SWF_NAME 13
#const SWF_DROP_TARGET 14
#const SWF_URL 15
#const SWF_HIGH_QUALITY 16
#const SWF_FOCUS_RECT 17
#const SWF_SOUND_BUF_TIME 18

#enum global NULL=0
#enum CMD_OPEN
#enum CMD_QUIT
#enum CMD_PLAY
#enum CMD_STOP
#enum CMD_REWIND
#enum CMD_INFO
#enum CMD_README
#enum CMD_BLOG
#uselib "user32.dll"
#func GetClientRect "GetClientRect" int,var
#func ClientToScreen "ClientToScreen" int,int
#func global CreateMenu "CreateMenu"
#func global CreatePopupMenu "CreatePopupMenu"
#func global AppendMenu "AppendMenuA" int,int,int,str
#func global SetMenu "SetMenu" int,int
#func global DrawMenuBar "DrawMenuBar" int
#func global PostMessage "PostMessageA" int,int,sptr,sptr
#const global WM_CLOSE 0x0010
#const global WM_COMMAND 0x0111
#uselib "shell32.dll"
#func DragAcceptFiles "DragAcceptFiles" int,int
#func DragQueryFile "DragQueryFileA" int,int,int,int
#func DragQueryPoint "DragQueryPoint" int,int
#func DragFinish "DragFinish" int
#define WM_DROPFILES 0x0233

//#include "mod_menu.as" //HSP同梱のモジュールを無理矢理連結
#module
#deffunc newmenu var _p1,int _p2
if( _p2==0 ){ CreateMenu }
if( _p2==1 ){ CreatePopupMenu: }
_p1=stat
return
#deffunc addmenu int _p1,str _p2,int _p3,int _p4
AppendMenu _p1,_p4,_p3,_p2
return
#deffunc applymenu int _p1
SetMenu hwnd,_p1: DrawMenuBar hwnd
return
#global

screen WINID_MAIN,NICO_W,NICO_H,2: title EXENAME+"( "+__date__+" "+__time__+")"
oncmd gosub *OnCommand,WM_COMMAND
oncmd gosub *OnDropFiles,WM_DROPFILES
onclick gosub *OnMouseClick
onexit goto *OnExitMess
newmenu hmenu,0
newmenu hfilemenu,1
addmenu hfilemenu, "開く(&O)", CMD_OPEN
addmenu hfilemenu, "", NULL, 0x800
addmenu hfilemenu, "終了(&Q)", CMD_QUIT
addmenu hmenu, "ファイル(&F)", hfilemenu, 0x10
newmenu hplaymenu,1
addmenu hplaymenu, "再生(&P)", CMD_PLAY
addmenu hplaymenu, "停止(&S)", CMD_STOP
addmenu hplaymenu, "巻き戻し(&W)", CMD_REWIND
addmenu hplaymenu, "", NULL, 0x800
addmenu hplaymenu, "動画情報(&I)", CMD_INFO
addmenu hmenu, "再生(&P)", hplaymenu, 0x10
newmenu hhelpmenu,1
addmenu hhelpmenu, "readme(&R)", CMD_README
addmenu hhelpmenu, "", NULL, 0x800
addmenu hhelpmenu, "ブログ(&b)", CMD_BLOG
addmenu hmenu, "ヘルプ(&H)", hhelpmenu, 0x10
applymenu hmenu
dim rect,4: GetClientRect hwnd,rect: API_H=NICO_H+(NICO_H-rect(3))+SEEKBAR_H
screen WINID_MAIN,NICO_W,API_H,0,(ginfo_dispx-NICO_W)/2,(ginfo_dispy-NICO_H)/2: title EXENAME
ClientToScreen hwnd,varptr(rect): border=rect(0)-ginfo_wx1: toolbar=rect(1)-ginfo_wy1
// border=(ginfo_sizex-ginfo_winx)/2: toolbar=ginfo_sizey-ginfo_winy-border

pos 0,0: axobj flash, "ShockwaveFlash.ShockwaveFlash",NICO_W,NICO_H: comres axstat
buffer WINID_BUFF,NICO_W,API_H,0
sdim filepath,260: sdim filename,260: filesize=0: loadMovie=-1: sdim filedrop,260
gsel WINID_MAIN,1: DragAcceptFiles hwnd,1

*play
gsel WINID_BUFF: color 255,255,255: boxf
if( loadMovie==0 ){
flash->"IsPlaying": IsPlaying=axstat
flash->"PercentLoaded": PercentLoaded=axstat
flash->"TGetProperty" "/",SWF_CURRENT_FRAME: CurrentFrame=axstat
if( int(TotalFrames)>0 ){ swfpos=NICO_W*int(CurrentFrame)/int(TotalFrames) }
else{ swfpos=0 }
color 0,0,0: line swfpos,0,swfpos,SEEKBAR_H
}
gsel WINID_MAIN: gmode 1,NICO_W,API_H: gcopy WINID_BUFF,0,0
if( loadMovie==0 ){
swfinfo="「"+filepath+"」"+"\nIsPlaying="+IsPlaying+",PercentLoaded="+PercentLoaded
swfinfo+="\nCurrentFrame="+CurrentFrame+"/TotalFrames="+TotalFrames
swfinfo+="\nWidth="+swfWidth+",Height="+swfHeight
title "\""+filename+"\"["+CurrentFrame+"/"+TotalFrames+"]("+PercentLoaded+"%)"
}
else{
swfinfo="フラッシュ(swf)を読み込んでください。"
title EXENAME
}
redraw 1
wait 10: msx=ginfo_mx-ginfo_wx1-border: msy=ginfo_my-ginfo_wy1-toolbar
redraw 0
goto *play

*swfopen
exist filepath: filesize=strsize
if( filesize>0 ){
TotalFrames=0: flash->"stop"
flash->"loadMovie" 0,filepath: filename=getpath(filepath,8+1): loadMovie=stat
if( loadMovie==0 ){
flash->"TGetProperty" "/",SWF_TOTAL_FRAMES: TotalFrames=axstat
flash->"TGetProperty" "/",SWF_WIDTH: swfWidth=axstat
flash->"TGetProperty" "/",SWF_HEIGHT: swfHeight=axstat
flash->"play"
}
return

*OnCommand
switch (wparam & 0xFFFF)
case CMD_OPEN
dialog "swf",16,"Flashファイル": if( stat==1 ){ filepath=refstr: gosub *swfopen }
swbreak
case CMD_PLAY
if( loadMovie==0 ){ flash->"play" }
swbreak
case CMD_STOP
if( loadMovie==0 ){ flash->"StopPlay" }
swbreak
case CMD_REWIND
if( loadMovie==0 ){ flash->"Rewind" }
swbreak
case CMD_INFO
dialog swfinfo,0,filename
swbreak
case CMD_QUIT
PostMessage hwnd,WM_CLOSE,0,0 //gosub *OnExitMess
swbreak
case CMD_README
dialog {"HSPでFlashを再生するサンプルです。
\n・背景が真っ黒もしくは別な色になる場合があります。
・アプリケーションに近いコンテンツだとシークの意味が無い場合があります。
・このバージョンはflvやmp4を再生できません。
\n(c) 2009 光束ミユ/ooblog"},0,"\""+EXENAME+"\" Varsion 20090322"
swbreak
case CMD_BLOG
exec "http://blog.livedoor.jp/qd_flare-all/archives/cat_38917.html",16
swbreak
default
swbreak
swend
return

*OnDropFiles
hdrop=wParam: DragQueryFile hdrop,-1,0,0: ndrop=stat
repeat ndrop
DragQueryFile hdrop,cnt,varptr(filepath),260
loop
gosub *swfopen
DragFinish hdrop
return

*OnMouseClick
stk=wparam
if( 0<msx && msx<NICO_W && NICO_H<msy && msy<API_H ){
if( stk&WP_MOUSE_L ){
flash->"GotoFrame" mousex*TotalFrames/NICO_W: flash->"play"
}
if( stk&WP_MOUSE_R ){
flash->"GotoFrame" mousex*TotalFrames/NICO_W: flash->"stop"
}
}
return

*OnExitMess
delcom flash
end

// 参考資料
// [HSP3 あれこれ <その他>] http://lhsp.s206.xrea.com/hsp_other.html
// [JavaScript でムービーを制御する] http://www.adobe.com/jp/support/flash/ts/documents/fl0017.html
// [Drag&Dropされたファイルを取得してみる] http://yokohama.cool.ne.jp/chokuto/urawaza/dragdrop.html
// [ウィンドウ外やオブジェクト上のマウス座標を取得] http://hspdev-wiki.net/?%A5%A6%A5%A3%A5%F3%A5%C9%A5%A6%B3%B0%A4%E4%A5%AA%A5%D6%A5%B8%A5%A7%A5%AF%A5%C8%BE%E5%A4%CE%A5%DE%A5%A6%A5%B9%BA%C2%C9%B8%A4%F2%BC%E8%C6%C0


posted by qd_flare

違反を報告する