Using An External FairPlay License Server (KSM)
Since version 3.11.0.
Since there’s no Apple-defined protocol between FairPlay clients and servers, Kaltura’s DRM server has defined its own protocol. PlayKit has the client-side implementation of that protocol built-in. To use another DRM server, the application has to provide a custom FairPlay License Provider as a delegate to the Player.
On this page:
Setup
The delegate function is given all parameters that should be sent to a server; it has to perform an http request and return the result to the player via a callback.
Implement FairPlayLicenseProvider
Swift
class MyCustomFairPlayProvider: FairPlayLicenseProvider {
func getLicense(spc: Data, assetId: String, requestParams: PKRequestParams, callback: @escaping (Data?, TimeInterval, Error?) -> Void) {
// TODO: Send SPC to the server, call the callback function with:
// spc as Data, offline duration as TimeInterval, optional error
}
}
Objective-C
@interface MyCustomFairPlayProvider: NSObject <FairPlayLicenseProvider>
@property (nonatomic) NSString* customData;
@end
@implementation MyCustomFairPlayProvider
- (void)getLicenseWithSpc:(NSData * _Nonnull)spc assetId:(NSString * _Nonnull)assetId requestParams:(PKRequestParams * _Nonnull)requestParams callback:(void (^ _Nonnull)(NSData * _Nullable, NSTimeInterval, NSError * _Nullable))callback {
// TODO: Send SPC to the server, call the callback function with:
// spc as Data, offline duration as TimeInterval, optional error
}
@end
Create an instance of the custom provider
Swift
// Save in a property
let fairplayProvider = MyCustomFairPlayProvider()
Objective-C
// Save in a property
@property (strong, nonatomic) MyCustomFairPlayProvider* fairplayProvider = [[MyCustomFairPlayProvider alloc] init];
Install the Provider in the Player
Just after calling PlayKitManager.loadPlayer(), pass the provider to the player.
Swift
self.player?.settings.fairPlayLicenseProvider = self.fairplayProvider
Objective-C
self.player.settings.fairPlayLicenseProvider = self.fairplayProvider;
From this point, whenever the player need to get a FairPlay license it will use the custom provider instead of the built-in one. If the custom provider needs to pass more data to the server that differs between assets, the data should be set just in the provider just before calling player.prepare()
.
Example:
Swift
self.fairplayProvider.customData = @"foo"
self.player.prepare(mediaConfig)
Objective-C
self.fairplayProvider.customData = @"foo";
[self.player prepare:mediaConfig];
These examples assume that MyCustomFairPlayProvider
has a String
property named customData
and that the implementations sends it to the server (as an http header, query parameter, etc).
Offline
To enable the custom FairPlayLicenseProvider for offline (downloaded) assets, set the LocalAssetsManager.fairPlayLicenseProvider
property to an instance of the same class. Make sure to set any custom data properties on the provider before calling LocalAssetsManager.registerDownloadedAsset()
.
To prevent possible conflicts, LocalAssetsManager
should have its own instance of FairPlayLicenseProvider
.