首页 > 解决方案 > 在 DELPHI 中为 AVPlayer 设置用户代理

问题描述

我正在尝试根据下面的短代码在 Delphi中设置一个User Agentfor :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,我需要在那里设置用户代理。

标签: delphiavplayerfiremonkey

解决方案


似乎在做相当于这样的事情:

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;

推荐阅读