TWebMultimediaPlayer URL / Headers

How to assign http headers (Authorization)
for TWebMultimediaPlayer file request
like this "WebClientConnection1.Headers.Add('Authorization=Bearer ' + Auth);" ?


The HTML video tag does not support such functionality.

You could try to modify your backend to check the query parameters of your request URL and put the token in there. See a similar discussion here:

Or alternatively you can use a TWebHTTPRequest component, set your request header and set the URL property to your video URL. This will most probably return your video in a binary format. After that, you'll need to encode the binary string to base64 and assign the result to the TWebMiltumediaPlayer.URL property.


that backend configuration looks fine, but how to do it with delphi sparkle / xdata server.

That second alternative I couldn't get to work.
I have a

  • function GetVideo(VideoId: integer; LangId: string): TStream;

which works correctly when correct http is assigned directly to WebMultimediaPlayer1.URL .
If I first call TWebHTTPRequest and assign that result to that URL , it does not play that video.

You can use a generic middleware to add custom code that converts a parameter in query string to an authentication header. Put the middleware before the JWT middleware and it should work. Something like this (not tested but you can get the idea):

procedure TForm6.XDataServer1GenericRequest(Sender: TObject; Context: THttpServerContext; Next: THttpServerProc);
  Params: TArray<TPair<string, string>>;
  Pair: TPair<string, string>;
  if Context.Request.Uri.Query <> '' then
    if Context.Request.Headers.Get('Authorization') = '' then
      Params := TSparkleUtils.GetQueryParams(Context.Request.Uri.Query);
      for Pair in Params do
        if SameText(Pair.Key, 'access_token') then
          Context.Request.Headers.SetValue('Authorization', 'Bearer ' + Pair.Value);

Thanks it works fine.

1 Like

This topic was automatically closed 60 minutes after the last reply. New replies are no longer allowed.