TO:silicon
/////////////////////////////
if mpegstream<>0 then
begin
FMPStop(mpegstream);
FMPClose(mpegstream);
mpegstream:=0;
end;
// if OpenDialog1.Execute then
begin
fillchar(fmpopenstruct,sizeof(FMP_OPEN_STRUCT),0);
FMPOpenStruct.lpFileName:='e:/song/老.mpg';//pchar(OpenDialog1.filename);
FMPOpenStruct.dwCALLback:=DWORD(@FMPCallbackProc);
mpegstream:=FMPOpen(FMPF_BUFFERS,DWORD(@FMPOpenStruct));
FMPPlay(mpegstream,FMPF_POS_END or FMPF_END_STOP,0);
end
//////////////////////////////////
这是我的CALLBACK程序,但上面程序中,用FMPOpen命令后,mpegstream却是0。
请silicon能不吝指点。
function FMPCallbackProc(bMsg:BYTE;
hMPEGStream:BYTE;
dwValue
WORD):WORD;stdcall;
var
i:integer;
Buf:buf1;
dd
word;
begin
Buf:=buf1(FMPGet( hMPEGStream, FMPI_STM_USER));
case bMsg of
// first message received - make all your allocations here
FMPM_BUF_CREATE:
begin
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(FMP_OPEN_STRUCT1(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
Buf.Buffer
:=charPtr(GlobalAllocPtr( GMEM_FIXED, MAX_BUF_SIZE + 2 ));
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
dd:=DWORD(trunc(MAX_BUF_SIZE* 0.75));
FMPSet(hMPEGStream, FMPI_BUF_POS, dd);
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
GlobalFreePtr(@Buf.Buffer);
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:
ReadFile(buf.hfile,buf.buffer[buf.wIndex],MAX_BUF_SIZE,buf.dwSize,nil);
// 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 );
dd:= DWORD(Buf.Buffer[Buf.wIndex]);
FMPSet(hMPEGStream, FMPI_BUF_ADDRESS,dd);
//FMPSet( hMPEGStream, FMPI_BUF_HANDLE, DWORD(Buf.BufferIndex[Buf.wIndex]) );
Buf.wIndex:=Buf.wIndex+1;
if Buf.wIndex > MAX_BUF_NUMBER then
Buf.wIndex:=1;
end;
end;
result:=0;
end;