silicon进来(50分)

  • 主题发起人 主题发起人 jacky1936
  • 开始时间 开始时间
J

jacky1936

Unregistered / Unconfirmed
GUEST, unregistred user!
如何判断神龙卡的当前文件播放完毕[:D]
 
判断结束有多种办法:
如果你用缓冲方式的话:回调函数可以这样写:
function FMPCallbackProc(bMsg: Byte;
hMPEGStream: Byte;
dwValue: DWORD): WORD stdcall;
begin

Result:= 0;
try
Buf:= Pointer(FMPGet(hMPEGStream, FMPI_STM_USER));
case bMsg of
FMPM_BUF_CREATE: Result:= CreateBuf;
// 建立
FMPM_BUF_CLOSE : CloseBuf;
// 关闭
FMPM_BUF_POS : PosBuf;
// 读数据
FMPM_BUF_EMPTY : BufEmpty;
// 缓冲区空
FMPM_COMPLETED : if dwValue = 3 then
// 播完
begin

if AutoPlayNext then

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

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

end;

except
end;

end;


如果是用其他方式打开的。还可以用判断文件是否读完来得到。
 
[:D]可能读文件方式也要用这种方法吧
 
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:DWORD):WORD;stdcall;
var
i:integer;
Buf:buf1;
dd:Dword;
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;

 
在FMPOpen之前你是不是忘记要执行 [red]FMPOpenDriver[/red]了吗?
{--------------------------------------------------------------
* FUNCTION : FMPOpenDriver()
* DESCRIPTION : Opens IMPEG32.DLL
* RETURN : non-zero if successful, 0 if failed.
---------------------------------------------------------------}
function FMPOpenDriver: integer;
const
szDriverName = 'reeldrv';
szSectionName = 'Drivers32';
begin

hReelDrv:= OpenDriver(szDriverName, szSectionName, 0);
Result := hReelDrv;
end;

 
OpenDriver(szDriverName, szSectionName, 0)
已经执行成功。。
用播放文件的形式可以播放。。

但BUFFER模式就出了问题,CALLBACK中的执行都很成功,
但FMPOPEN的返回值 就是为0
 
silicon:
怎样判断文件是否已经读完?
houling:
你的问题解决了吗?我也碰到相同的问题。
 
文件是否读完,可用Position = Size来比较
 
mpegstream等于0能否解决?
 
关注中……PS:初学者,请多指教
 
后退
顶部