在PB中播放AVI文件
编号:QA002437
建立日期: 2000年1月13日 最后修改日期:2000年1月13日
所属类别:
佚名:
使用该段代码在PB中播放AVI文件,总是报错。
//***********************************************
// cb_open
// Opens the multimedia device
//
FUNCTION Long mciSendStringA(String LpstrCommand,ref string
lpstrReturnString,int wRtnLength,int hCallBack) LIBRARY "WINMM.DLL"
FUNCTION Boolean mciGetErrorStringA(long dwError,ref string lpstrBuffer,
int wLength ) LIBRARY "WINMM.DLL"
//***********************************************
string ls_Handle
string ls_return,ls_string,ls_error
long ll_rc
string ls_named,ls_command
ls_string=space(128)
ls_error=space(128)
// get file name to open
ll_rc = GetFileOpenName("Select File", &
is_file_name, ls_named, "DOC", &
" AVI Files (*.AVI),*.AVI" )
messagebox("",is_file_name)
//messagebox("",string(ll_rc))
// if user hit cancel...
IF ll_rc = - 1 OR &
upper(Right(Trim(is_file_name), 3 ))<>"AVI" THEN
messagebox("selection error","you must select an avi file")
is_file_name = ""
return
END IF
ls_command="open"+is_file_name+"type avivideo alias cartoon"
//messagebox("",ls_command)
ll_rc=mciSendStringA(ls_command,ls_string,127,0)
//messagebox("",string(ll_rc))
if ll_rc<>0 then
mciGetErrorStringA(ll_rc,ls_error,len(ls_error) -1)
messagebox("media error","error message:~r~n"+ls_error)
return ll_rc
end if
回答:
在窗口中放置三个CommandButton(Open、Play、Close)、一个Datawindow定义一实例变量:
String ls_pathname
CommandButton(Open) 的Clicked事件如下:
string ls_handle,ls_filename,ls_buffer,ls_driver,ls_file
long ll_rtn_code,ls_error
string ls_string
ls_string = Space(128)
ls_buffer="Hkey_local_Machine\System\CurrentControlSet\Control\MediaResources\MCI\AVIVideo"
ls_error = RegistryGet(ls_buffer,"Driver",RegString!,ls_driver)
ll_rtn_code = GetFileOpenName("Select Files",ls_PathName,ls_filename,"DOC","AVI File(*.AVI),*.AVI")
IF ll_rtn_code = -1 OR Upper(Right(Trim(ls_pathname),3)) <> "AVI" THEN
ls_pathname = ''
Return
END IF
//打开AVI文件
ls_file = "Open "+ls_pathname
mciSendstringA(ls_file,ls_string,127,handle(dw_1))
ls_handle = string(handle(dw_1))
ls_file = "Window "+ls_pathname+" handle "+ls_handle
mciSendstringA(ls_file,ls_string,127,handle(dw_1))
ls_file = "Put "+ls_pathname+" destination"
mciSendstringA(ls_file,ls_string,127,handle(dw_1))
ls_file = "Set "+ls_pathname+" time format frames"
mciSendstringA(ls_file,ls_string,127,handle(dw_1))
//播放AVI文件
CommandButton(Play) 的Clicked事件如下:
ls_string = Space(128)
ls_file = "Play "+ls_pathname
mciSendstringA(ls_file,ls_string,127,handle(dw_1))
//关闭AVI
CommandButton(Close) 的Clicked事件如下:
ls_string = Space(128)
ls_file = "Close "+ls_pathname
mciSendstringA(ls_file,ls_string,127,handle(dw_1))
此问题由fjq回答。
| |
|
|
| |
|
|