DELPHI BASS库Windows平台下,实时更换输出设备
#DELPHI BASS库Windows平台下,实时更换输出设备
取自网络,分享,项目嵌入无损音乐播放后,画蛇添足的功能分享!
直接贴核心代码,看不明白去看说明:这样操作无感换设备!
function TBassPlayer.ReInit(device: String; freq, flags: DWORD; clsid: Pointer): Boolean;
var ipos:Int64; vol:single; sFile:String; needReplay:Boolean;
begin//记录状态needReplay:= BASS_ChannelIsActive(Fch) = BASS_ACTIVE_STOPPED;if needReplay thenbeginsfile:=FFile;if not BASS_ChannelGetAttribute(Fch,BASS_ATTRIB_MUSIC_VOL_CHAN,vol) thenvol:=0.8;iPos := BASS_ChannelGetPosition(Fch, BASS_POS_BYTE);end;if (FDevice=device) and (FInitStatus>1) thenbeginresult :=True;Exit; //无改变end elsebegin// Free StreamsBASS_StreamFree(Fch);// Close BASSBASS_Free();end;FDevice:= device;if Init(device,freq, flags, clsid) thenbegin //恢复状态if needReplay thenbeginFFile:='';if FileExists(sfile) and Play(sfile,true,vol) thensetPos(iPos);end;end else result:=false;
end;
把bass库简单做了封装
init
play
setpos