【发布时间】:2018-08-11 07:05:40
【问题描述】:
我正在尝试加载需要标头中的令牌的视频文件。我在 Stackverflow 上了解到,这可能是通过查看以下 question 来实现的。问题是我不相信 AVURLAssetHTTPHeaderFieldsKey 是公开的,或者我的资产变量写错了。我想要做的是将令牌添加到标题中,以便 AVPlayer 加载视频文件。到目前为止,这是我的代码,它只显示播放器,但不加载我猜的视频,因为我的标题设置不正确:
NSURL *videoURL = [NSURL URLWithString:cell.media[@"redirectionUrl"]];
NSMutableDictionary * headers = [NSMutableDictionary dictionary];
[headers setObject:[CMUser currentUser].token forKey:@"Authorization"];
AVURLAsset *asset = [AVURLAsset URLAssetWithURL:videoURL options:@{@"AVURLAssetHTTPHeaderFieldsKey" : headers}];
AVPlayerItem * item = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:item];
AVPlayerViewController *playerViewController = [AVPlayerViewController new];
playerViewController.player = player;
playerViewController.modalPresentationStyle = UIModalPresentationOverFullScreen;
[self presentViewController:playerViewController animated:YES completion:nil];
【问题讨论】:
-
您的代码似乎没有问题,请先尝试从邮递员那里获取视频。如果你从邮递员那里得到它,那么你的代码可能会出现一些问题,在完成块中显示控制器尝试通过调用“playerViewController.player.play()”进行播放之后
标签: ios objective-c http-headers avplayer avasset