我早就查过了,只是一打开文件就出错了,请指教
function FMPCallbackProc(bMsg:BYTE;
hMPEGStream:BYTE;
dwValue
WORD):WORD;stdcall;
var
i:integer;
Buf
buf;
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;