在DELPHI中为AVPlayer设置用户代理

时间:2019-03-15 15:23:14

标签: delphi avplayer firemonkey

我正在尝试根据以下简短代码在Delphi中为User Agent设置一个AvPlayer

NSMutableDictionary* * *headers = [NSMutableDictionary dictionary];
[headers setObject:@"YourHeader"forKey:@"User-Agent"];
self.urlAsset = [AVURLAsset URLAssetWithURL:self.videoURL options:@{@"AVURLAssetHTTPHeaderFieldsKey" : headers}];
self.playerItem = [AVPlayerItem playerItemWithAsset:self.urlAsset];
self.player = [AVPlayer playerWithPlayerItem:self.playerItem];

我在这部分上遇到麻烦了

options:@{@"AVURLAssetHTTPHeaderFieldsKey" : headers}

我已将标头声明为NSMutableDictionarysetobject并带有必填字段,但是我应该如何将其分配给键AVURLAssetHTTPHeaderFieldsKey

我正在使用ALVideoPlayer库中的Alcinoe,并且需要在此处设置用户代理。

1 个答案:

答案 0 :(得分:0)

它似乎正在执行以下操作:

uses
  Macapi.Foundation, Macapi.Helpers, Macapi.AVFoundation;

var
  LDictionary: Pointer;
  LOptions: NSDictionary;
  LURLAsset: AVURLAsset;
  LVideoURL: NSURL;
begin
  // Make sure you initialize LVideoURL with whatever value it is expecting
  LDictionary := TNSDictionary.OCClass.dictionaryWithObject(StringToID('YourHeader'), StringToID('User-Agent'));
  LOptions := TNSDictionary.Wrap(TNSDictionary.OCClass.dictionaryWithObject(LDictionary, StringToID('AVURLAssetHTTPHeaderFieldsKey')));
  LURLAsset := TAVURLAsset.OCClass.URLAssetWithURL(LVideoURL, LOptions);
  // etc
end;