1

我正在尝试在我的应用程序中实现 FairPlay。

我可以使用 Apple 提供的 SDK 播放加密视频,但问题是 SDK 在 Swift 中,但我的项目在 Objective C 中。

所以我在我的项目中重新编写了代码,但我无法播放视频。

在此处输入图像描述

以下是我正在使用的链接:

  1. 播放列表:https://willzhanmswest.streaming.mediaservices.windows.net/92fc0471-0878-4eeb-80a3-e5b6fc497806/NoAudio.ism/manifest(format=m3u8-aapl)

  2. 证书:https ://openidconnectweb.azurewebsites.net/Content/FPSAC.cer

以下是我遵循的步骤:

  1. 向 AVURLAsset 添加了一个委托来调用此函数 shouldWaitForLoadingOfRequestedResource。
  2. 在这个函数中,我首先在 NSData 中获取证书的内容
  3. 然后,我正在获取资产字符串并将其转换为 NSData。
  4. 然后,我调用这个函数来创建 SPC 值。
NSData *spc = [loadingRequest streamingContentKeyRequestDataForApp:certificate contentIdentifier:assetId options:nil error:nil];
  1. 收到的 SPC 和资产 ID 然后通过 application/x-www-form-urlencoded content-type 传递到 Azure 服务器。
  2. 然后对收到的 CKC 进行修剪以删除和标记,然后将其转换为 Base64String,然后调用这些函数
[dataRequest respondWithData:base64CkcData];
[加载请求完成加载];

谁能帮我找出我在这里做错了什么?

谢谢。

4

1 回答 1

0

我遇到了类似的麻烦。我假设您从 obj-c 版本的https://gist.github.com/fousa/5709fb7c84e5b53dbdae508c9cb4fadc开始,是吗?此代码部分似乎对我有用,我只是想知道这是否是您已经拥有的。

// 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];

如果这是您所拥有的,那么视频可能就是问题所在。

于 2018-09-11T20:26:27.673 回答