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 then
begin
sfile:=FFile;
if not BASS_ChannelGetAttribute(Fch,BASS_ATTRIB_MUSIC_VOL_CHAN,vol) then
vol:=0.8;
iPos := BASS_ChannelGetPosition(Fch, BASS_POS_BYTE);
end;
if (FDevice=device) and (FInitStatus>1) then
begin
result :=True;
Exit; //无改变
end else
begin
// Free Streams
BASS_StreamFree(Fch);
// Close BASS
BASS_Free();
end;
FDevice:= device;
if Init(device,freq, flags, clsid) then
begin //恢复状态
if needReplay then
begin
FFile:='';
if FileExists(sfile) and Play(sfile,true,vol) then
setPos(iPos);
end;
end else result:=false;
end;
把bass库简单做了封装
init
play
setpos