请各位高手把神龙卡完整的回调函数贴出来可以吗?(50分)

  • 主题发起人 主题发起人 poppy
  • 开始时间 开始时间
P

poppy

Unregistered / Unconfirmed
GUEST, unregistred user!
如题,谢谢
 
你查查以前高手的单吧!早有人回答过了!
 
我早就查过了,只是一打开文件就出错了,请指教
function FMPCallbackProc(bMsg:BYTE;
hMPEGStream:BYTE;
dwValue:DWORD):WORD;stdcall;
var
i:integer;
Buf:Pbuf;
begin

try
Buf:=Pointer(FMPGet( hMPEGStream, FMPI_STM_USER));
case bMsg of
// first message received - make all your allocations here
FMPM_BUF_CREATE:
begin

GetMem(Buf,sizeof(TBuf));
Buf:= GlobalAllocPtr(GMEM_FIXED,sizeof(TBuf));
if Buf = nil then

begin

MessageBox(0,'分配内存出错,可能是内存不足!','错误',MB_ICONEXCLAMATION);
Result:=FMPE_DOS;
Exit;
end;

fillchar(Buf^,sizeof(TBUF),0);
Buf.hFile := CreateFile(PFMP_OPEN_STRUCT(dwValue).lpFileName,
GENERIC_READ, FILE_SHARE_READ,
nil, OPEN_EXISTING, 0, 0 );
// if we cannot open the file, return an error
// NOTE: the FMPM_BUF_CLOSE is not called when an error occurs
// during the creation
if ( Buf.hFile = INVALID_HANDLE_VALUE ) then

begin

MessageBox(0,'打开文件出错!','错误',MB_ICONEXCLAMATION);
GlobalFreePtr( Buf );
Result:=FMPE_DOS;
Exit;
end;


for i := 1 to MAX_BUF_NUMBERdo

begin

Buf.Buffer:= GlobalAllocPtr( GMEM_FIXED, MAX_BUF_SIZE + 2 );
end;

Buf.wIndex := 1;
Buf.dwSize := 0;
// store the structure address in the USER field
FMPSet(hMPEGStream,FMPI_STM_USER, DWORD(Buf) );
// trigger at 3/4 of the buffer to fill the next buffer
FMPSet(hMPEGStream, FMPI_BUF_POS, DWORD(trunc(MAX_BUF_SIZE* 0.75)));
end;

// message received when closing the stream - delete buffers
FMPM_BUF_CLOSE:
begin

CloseHandle( Buf.hFile );
// free all application buffers
for i:=1 to MAX_BUF_NUMBERdo

begin

GlobalFreePtr(@Buf.Buffer);
end;

GlobalFreePtr(Buf);
end;

// message received when a seek is required - seek to the position
// in Value (specified in bytes)
FMPM_BUF_SEEK:
begin

SetFilePointer( Buf.hFile, LongInt(dwValue), NIL, FILE_begin
);
end;

// message received when a buffer has reached its signal position -
// prepare here the next buffer
FMPM_BUF_POS:
begin

ReadFile(buf.hfile,buf.buffer[buf.wIndex],
MAX_BUF_SIZE,buf.dwSize,nil);
end;

// message received when a buffer has been completely read - switch to
// the next prepared buffer
FMPM_BUF_EMPTY:
begin

FMPSet(hMPEGStream, FMPI_BUF_SIZE,Buf.dwSize );
FMPSet(hMPEGStream, FMPI_BUF_ADDRESS, DWORD(Buf.Buffer[Buf.wIndex]));
//FMPSet( hMPEGStream, FMPI_BUF_HANDLE, DWORD(Buf.BufferIndex[Buf.wIndex]) );
Buf.wIndex:= Buf.wIndex+1;
if Buf.wIndex > MAX_BUF_NUMBER then

begin

Buf.wIndex:=1;
end;

end;

FMPM_ERROR:
begin

showmessage('error');
end;

//操作完成
FMPM_COMPLETED :
begin

showmessage('COMPLETED');
if dwValue = 3 then
// 播完
begin

//if AutoPlayNext then

// PostMessage(MainForm.Handle, FMP_NEXT, 0, 0)
//else

Showmessage('已播完,按停唱播下一首');
end;

end;

end;

result:= 0;
except
// CloseHandle(Buf.hFile);
for i:=0 to MAX_BUF_NUMBER - 1do

begin

// FreeMemory(Buf.Buffer);
end;

// FreeMemory(Buf);
result:= 0;
end;

end;
 
to:poppy
我看了一下,好象没错呀,你把 i的初值改成0
// GetMem(Buf,sizeof(TBuf));
Buf.wIndex := 0;
Buf.dwSize := 0;

if Buf.wIndex > MAX_BUF_NUMBER then

begin

Buf.wIndex:=0;
end;

试试吧,哈哈,有点意思!
 
我试试先
 
还是不行,以下是打开文件的代码
var
FMPOpenStruct: TFMP_OPEN_STRUCT;
begin

// stop and close any currently opened MPEG stream
if ghMPEGStream <> 0 then

begin

FMPStop( ghMPEGStream );
FMPClose( ghMPEGStream );
ghMPEGStream:= 0;
end;

fillchar(FMPOpenStruct,sizeof(TFMP_OPEN_STRUCT),0);
FMPOpenStruct.lpFileName:= pchar('F:/DEMO/888888.mpg');//gOpenFileName.lpstrFile;
FMPOpenStruct.dwCallBack:= DWORD(@FMPCallBackProc);
ghMPEGStream:= FMPOpen(FMPF_BUFFERS, DWord(@FMPOpenStruct));
if ghMPEGStream = 0 then

begin

MessageBox(0,'File open error','FMPBuf1 ERROR',MB_ICONEXCLAMATION);
end;

// set video keying mode
// FMPSet( ghMPEGStream, FMPI_VID_KEY_MODE, FMPF_KEY_VGA );
// set video keying color
// FMPSet( ghMPEGStream, FMPI_VID_KEY_COL, 0 );
// FMPSet(0,FMPI_VID_TV, 0);//
end;
 
你这些也没错呀!
你把这一句
GetMem(Buf,sizeof(TBuf));

Buf:= GlobalAllocPtr(GMEM_FIXED,sizeof(TBuf));
注销。
GlobalFreePtr---> Freememory 语句
 
还是不行
 
ghMPEGStream为什么打开后总是等于0!
 
后退
顶部