Tested.
...
uses ... , WebAudio, WEBLib.REST, ...
...
procedure TForm1.WebButton1Click(Sender: TObject);
var
AContext: TJSAudioContext;
AGainNode: TJSGainNode;
ABufferSourceNode: TJSAudioBufferSourceNode;
ARequest: TWebHTTPRequest;
AResponse : TJSXMLHTTPRequest;
begin
AContext := TJSAudioContext.New;
AGainNode := AContext.CreateGain;
ABufferSourceNode := AContext.CreateBufferSource;
ABufferSourceNode.Connect( AContext.Destination );
ARequest := TWebHTTPRequest.Create(Self);
ARequest.URL := 'test.mp3';
ARequest.ResponseType := rtArrayBuffer;
try
AResponse := await( TJSXMLHTTPRequest, ARequest.Perform() );
ABufferSourceNode.Buffer := await(TJSAudioBuffer, AContext.DecodeAudioData(TJSArrayBuffer(AResponse.Response)));
ABufferSourceNode.Start;
except on E: Exception do
begin
// file not found, etc.
ShowMessage(E.ClassName+': '+E.Message);
end;
end;
end;
The test.mp3 file in this case was included in the Delphi project folder. Clicking the button loads and then plays the file. No JavaScript anywhere