我正在尝试在我的应用程序中实现FairPlay。
我可以使用Apple提供的SDK播放加密视频,但问题是SDK在Swift中,但我的项目是在Objective C中。
所以我在我的项目中重写了代码,但我无法播放视频。
以下是我使用的链接:
证书:https://openidconnectweb.azurewebsites.net/Content/FPSAC.cer
以下是我遵循的步骤:
NSData *spc = [loadingRequest streamingContentKeyRequestDataForApp:certificate contentIdentifier:assetId options:nil error:nil];
[dataRequest respondWithData:base64CkcData];
[loadingRequest finishLoading];
有谁能帮我找到我在这里做错了什么?
感谢。
答案 0 :(得分:0)
我遇到了类似的麻烦。我假设您从https://gist.github.com/fousa/5709fb7c84e5b53dbdae508c9cb4fadc的obj-c版本开始,是吗?该代码部分似乎对我有用,我只是想知道这是否是您已经拥有的。
// licenseRequestURL is https://keydeliveryURL.azure.net/FairPlay/?kid=whatever-your-key-id-is
// contentId is keydeliveryURL.azure.net
// Create HTTP request
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:licenseRequestURL];
[request setHTTPMethod:@"POST"];
[request setValue:[NSString stringWithFormat:@"Bearer %@",authenticationToken] forHTTPHeaderField:@"Authorization"];
// Create Request HTTP body:
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
NSString *spcString = [spcData base64EncodedStringWithOptions:0];
NSString *httpBodyString = [NSString stringWithFormat:@"spc=%@&assetId=%@",
[spcString stringByAddingPercentEncodingWithAllowedCharacters:
[[NSCharacterSet characterSetWithCharactersInString:@"="] invertedSet]], contentId];
[request setHTTPBody:[httpBodyString dataUsingEncoding:NSUTF8StringEncoding]];
// Create session to run request asynchronously
NSURLSession *session = [NSURLSession sessionWithConfiguration:NSURLSessionConfiguration.defaultSessionConfiguration
delegate:self
delegateQueue:nil];
NSURLSessionTask *task = [session dataTaskWithRequest:request
completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
NSHTTPURLResponse *httpResponse = (NSHTTPURLResponse *) response;
NSString *dataString = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSString *stringStrippedOfCkcTags = [[dataString stringByReplacingOccurrencesOfString:@"<ckc>"
withString:@""]
stringByReplacingOccurrencesOfString:@"</ckc>"
withString:@""];
NSData *base64CkcData = [[NSData alloc] initWithBase64EncodedString:stringStrippedOfCkcTags
options:0];
[dataRequest respondWithData:base64CkcData];
[loadingRequest finishLoading];
}];
[task resume];
如果这是您所拥有的,那么可能是视频问题。