可以随意播放你自己的文件;
下面是delphi7中我用bass.dll播放文件的实例.
(和分类标题一样,写的很菜的,请多多包含指点啊)
说明:
要播放文件名为wdf的某段数据;
偏移offset处开始,读取size大小的内容到memoryStream中,
然后调用bass播放;
(这是目前bass的版本,老版本没试过,呵呵)
function bassMp3(wdf: string; offset,size: LongWord; mem: boolean): boolean;
var fs: TfileStream;
f: pchar;
volume: integer;
p: Pointer;
begin
volume := 40;
if (mem) then
begin
BASS_Free; //free first;
freeandnil(mp3ms);//freeandnil(ms);
fs := TfileStream.Create(wdf,fmOpenRead,fmShareDenyNone);
fs.Seek(offset,soFromBeginning);
mp3ms := TmemoryStream.Create;//ms := TmemoryStream.Create;
mp3ms.CopyFrom(fs,size);//ms.CopyFrom(fs,size);
p := mp3ms.Memory;//p := ms.Memory;
freeandnil(fs);
BASS_Init(1,22050,0,0,nil);//if BASS_Init(1,22050,0,0,nil) then Logs('init ok') else logMsg('init failed');
BASS_SetVolume(volume);//if BASS_SetVolume(volume) then logs(Format('Volume set to %d',[volume])) else LogMsg('Set Volume failed');
hbs := BASS_StreamCreateFile(mem,p,0,size,BASS_STREAM_AUTOFREE);
Bass_ChannelPlay(hbs,false);//if (Bass_ChannelPlay(hbs,false)) then logs('play failed') else logs('playing...');
//while (Bass_) do Bass_ChannelPlay(hbs,false);
end
end;