用Fmx调用Bass.dll

时间:2022-09-13 16:33:03

用Fmx调用Bass.dll

先上图

帮亲戚做个小软件,选用FMX,因为画面不会像vcl那样在图片多的时候闪烁。还能添加动画

但是MediaPlayer播放音乐视频真是不给力,视频没想到好办法。音频方面想到之前万一的Bass.ll的教程

尝试用FMX做下试试

结果发现Bass也是跨开台,Github上有个老外做了个收音机

下面是从万一博客上拷贝的代码,按照fmx的稍做了点修改

begin

  if not OpenDialog1.Execute then
Exit; BASS_StreamFree(hs); hs := BASS_StreamCreateFile(False, PChar(OpenDialog1.FileName), , , BASS_UNICODE);
if hs < BASS_ERROR_ENDED then
begin
Caption := '打开失败:' + hs.tostring;
end
else
Caption :=OpenDialog1.FileName;
end

这个是打开文件,新版的支持UNICODE

const
w = ;
var
i,di: Integer;
begin
if BASS_ChannelIsActive(hs) <> BASS_ACTIVE_PLAYING then Exit; BASS_ChannelGetData(hs, @FFTData, BASS_DATA_FFT1024); Image1.Bitmap.SetSize(Round(Image1.Width),Round(Image1.Height));
Image1.Bitmap.Canvas.BeginScene;
Image1.Bitmap.Canvas.Clear(talphacolors.Black); for i := to Length(FFTData) - do
begin
di := Trunc(Abs(FFTData[i]) * ); if di > Image1.Height then di := Round(Image1.Height);
if di >= FFTPeacks[i] then FFTPeacks[i] := di else FFTPeacks[i] := FFTPeacks[i] - ;
if di >= FFTFallOff[i] then FFTFallOff[i] := di else FFTFallOff[i] := FFTFallOff[i] - ;
if (Image1.Height - FFTPeacks[i]) > Image1.Height then FFTPeacks[i] := ;
if (Image1.Height - FFTFallOff[i]) > Image1.Height then FFTFallOff[i] := ; with Image1.Bitmap.Canvas do
begin
Fill.Color :=talphacolors.red;
FillRect(RectF(i * (w + ), Image1.Height - FFTFallOff[i], i * (w + ) + w, Image1.Height),,,AllCorners, );
end; end;
Image1.Bitmap.Canvas.EndScene;
end;

这个是绘制波形的,其他函数直接copy万一博客的代码就可以用