用神龙卡,在FMPOpen后,为什么返回值总是等于0???我用的是Buffers。 ( 积分: 100 )

  • 主题发起人 GrassDragon
  • 开始时间
G

GrassDragon

Unregistered / Unconfirmed
GUEST, unregistred user!
在FMPOpen后,为什么返回值总是等于0。不知道是不是回调函数中哪里有错?或是其它哪里有问题??
var
hMPEGStream : byte;
PFileName: string;

if OpenDialog1.Execute then

begin

edit1.Text:=OpenDialog1.FileName;
PFileName:=OpenDialog1.FileName;
if hMPEGStream<>0 then

begin

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

fillchar(FMPOpenStruct,sizeof(TFMP_OPEN_STRUCT),0);
FMPOpenStruct.lpFileName:=PChar(PFileName);;
FMPOpenStruct.dwCALLback:=DWORD(@FMPCallbackProc);
// hMPEGStream:=FMPOpen(FMPF_FILE,DWORD(pchar(OpenDialog1.FileName)));
hMPEGStream:=FMPOpen(FMPF_BUFFERS,DWORD(@FMPOpenStruct));
FMPPlay(hMPEGStream,FMPF_POS_END or FMPF_END_STOP,0);
//hMPEGStream返回值始终等于0
end;


Function FMPCallbackProc(bMsg: Byte;
hMPEGStream: Byte;
dwValue: DWORD): WORD stdcall;
var
Buf:pBuf;
i:integer;
begin

// showmessage(inttostr(bmsg));
Result:= 0;
try
Buf:= Pointer(FMPGet(hMPEGStream, FMPI_STM_USER));
case bMsg of
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(pChar(PFileName),//TFMP_OPEN_STRUCT(dwValue).lpFileName,
GENERIC_READ,
FILE_SHARE_READ,
Nil,
OPEN_EXISTING,
0,
0);

if (Buf.hFile=INVALID_HANDLE_VALUE) then

begin

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


for i := 0 to MAX_BUF_NUMBER-1do

GetMem(Buf.Buffer,MAX_BUF_SIZE + 2);
//GlobalAllocPtr(GMEM_FIXED, MAX_BUF_SIZE + 2);

Buf.wIndex := 0;
Buf.dwSize := 0;

//存储缓冲区结构到用户段
FMPSet(hMPEGStream,FMPI_STM_USER, DWORD(Buf) );

//在到缓冲区3/4时,触发填充下一个缓冲区
FMPSet(hMPEGStream, FMPI_BUF_POS, DWORD(Trunc(MAX_BUF_SIZE* 0.75)));

//FMPSet(hMPEGStream,FMPI_BUF_MODE,FMPF_BUF_LOOP);
//showmessage('create ok');
end;


//关闭缓冲区
FMPM_BUF_CLOSE :
begin

showmessage('close');

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

FreeMemory(Buf.Buffer);
//GlobalFreePtr(Buf.Buffer);
FreeMemory(Buf);
//GlobalFreePtr(Buf);
end;


//跳跃
FMPM_BUF_SEEK:
begin

showmessage('seek');
SetFilePointer(Buf.hFile,dwValue,nil,FILE_begin
);
end;


//读数据
FMPM_BUF_POS:
begin

ReadFile(Buf^.hFile,Buf^.Buffer[Buf^.wIndex]^,MAX_BUF_SIZE,Buf^.dwSize,nil);
end;


// 缓冲区空
FMPM_BUF_EMPTY :
begin

FMPSet(hMPEGStream, FMPI_BUF_SIZE,Buf^.dwSize );
FMPSet(hMPEGStream, FMPI_BUF_ADDRESS, DWORD(Buf^.Buffer[Buf^.wIndex]));
Inc(Buf^.wIndex);
if (Buf^.wIndex = MAX_BUF_NUMBER) then
Buf^.wIndex:=0;
Buf^.wIndex := MAX_BUF_NUMBER MOD Buf^.wIndex;
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;

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

FreeMemory(Buf.Buffer);
FreeMemory(Buf);
end;

end;
 
我有这样的东东,还支持播放加密歌曲.如有意请和我联系 QQ 87797301
 
我现在不需要加密,就是正常的buffers方式播放.
谁帮我看看问题在哪里?
 
研究一下你下面代码中的Buf吧

[red] Buf:= Pointer(FMPGet(hMPEGStream, FMPI_STM_USER));[/red] case bMsg of
FMPM_BUF_CREATE:
begin

[red] GetMem(Buf,sizeof(TBuf));
Buf := GlobalAllocPtr(GMEM_FIXED,sizeof(TBuf));[/red]
if Buf=nil then
 
你的回调函数出了问题,你可以翻翻以前的一些老贴!
 
顶部