今天尝试做视频播放,遇到的一个问题。
我们网站的视频的不能直接拿来URL播放,需要给Request加上Referer才可以请求到资源。
- (void)viewDidLoad {
//referer
NSString *referer = @"https://scontent.cdninstagram.com/hphotos-xpa1/t50.2886-16/11200303_1440130956287424_1714699187_n";
//视频url
NSURL *videoURL = [NSURL URLWithString:@"http://test.3dker.cn/api/files/get/file/by/576a4b22cc673f1c008f444e.mp4"];
//传给视频url给播放库进行播放
[self playVideoWithURL:request.URL];
}
- (void)playVideoWithURL:(NSURL *)url
{
if (!self.videoController) {
CGFloat width = [UIScreen mainScreen].bounds.size.width;
self.videoController = [[KRVideoPlayerController alloc] initWithFrame:CGRectMake(0, 0, width, width*(9.0/16.0))];
__weak typeof(self)weakSelf = self;
[self.videoController setDimissCompleteBlock:^{
weakSelf.videoController = nil;
}];
[self.videoController showInWindow];
}
//此库就直接调用系统MPMoviePlayerController Api了,里面又不可以修改
self.videoController.contentURL = url;
}
//若不加referer资源就请求不到,但是Api又并没有生成Request,请问,有没有办法解决这种问题?
Perhaps it can be customized
NSURLProtocol
来实现为每一个特定的NSURLRequest
添加 Header,如果你那个库底层是用到NSURLRequest
ifYou can realize your needs by modifying some of the codes below.
I also encountered this problem. I would like to know how to achieve it. Can you give me a demo or something like that?