gpt4 book ai didi

ios - 如何使用 AVPlayer 在 iOS 中播放 protected 视频内容

转载 作者:行者123 更新时间:2023-11-28 19:35:15 28 4
gpt4 key购买 nike

我使用以下实现从媒体服务器播放 protected 视频内容,但它显示带有十字线的播放图标。

登录后应用程序需要将 cookie 同步到媒体 Assets 以在身份验证后播放 protected 视频。
通过使用 AVURLAsset,我们正在流式传输 protected 视频但它不起作用。

NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];
NSDictionary *opt = @{
AVURLAssetReferenceRestrictionsKey: @(AVAssetReferenceRestrictionForbidRemoteReferenceToLocal),
AVURLAssetHTTPCookiesKey: cookies
};
AVAsset *asset = [AVURLAsset URLAssetWithURL:linkUrl//Media protected URL(http://www.example.com/media/video/media_mp4)
options:opt];

AVPlayerItem * item = [AVPlayerItem playerItemWithAsset:asset];
AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:item];
AVPlayerViewController *playerVC = [[AVPlayerViewController alloc]init];
playerVC.player = player;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self presentViewController:playerVC animated:NO completion:nil];
});

最佳答案

经过大量搜索,终于对我有用了。我从 NSHTTPCookieStorage 类中获取了应用程序 cookie。然后使用它我创建了一个包含键值对的字典,如下所示,@{AVURLAssetHTTPCookiesKey : cookies}

然后我将这个字典设置为 AVURLAsset URLAssetWithURL:linkUrl 选项中的选项:

NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies];

AVURLAsset * asset = [AVURLAsset URLAssetWithURL:linkUrl options:@{AVURLAssetHTTPCookiesKey : cookies}];

AVPlayerItem * item = [AVPlayerItem playerItemWithAsset:asset];

AVPlayer *player = [[AVPlayer alloc] initWithPlayerItem:item];

AVPlayerViewController *playerVC = [[AVPlayerViewController alloc]init];

playerVC.player = player;

dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{

[self presentViewController:playerVC animated:NO completion:nil];

});

关于ios - 如何使用 AVPlayer 在 iOS 中播放 protected 视频内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39722166/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com