AvPlayer
1. Introduction
Integrated information
Staging:
Certificate: https://cert-staging.sigmadrm.com/app/fairplay/{MERCHANT_ID}/{APP_ID}
License URL: https://license-staging.sigmadrm.com/license/verify/fairplay
Production:
Certificate: https://cert.sigmadrm.com/app/fairplay/{MERCHANT_ID}/{APP_ID}
License URL: https://license.sigmadrm.com/license/verify/fairplay
2. Require
Requirment
- iOS 8.0 and above
3. Integrate SigmaMultiDRM
Step 1
Configure pod
- Add below line in Podfile
objectivec
pod 'SigmaMultiDRM', :git => 'https://github.com/sigmadrm/sigma-multi-drm-ios.git'
- Run the command below to update the library:
objectivec
pod install
Step 2
Add Resource in Info.plist:
html
<key>merchant</key>
<string>MERCHANT_ID</string>
<key>appId</key>
<string>APP_ID</string>
// Optional default is false
<key>sigma_debug</key>
<string>true||false</string>
Step 3
Setup Sigma Multi DRM
objectivec
-(NSURL *)setupSigma
{
sdk = [[SigmaMultiDRM alloc] init];
[sdk setUserId:USER_ID];
[sdk setSessionId:SESSION_ID];
NSURL *URL = CONTENT_URL;
return URL;
}
Props | Type | Description |
---|---|---|
MERCHANT_ID | NSString | Customer ID |
APP_ID | NSString | App ID |
sigma_debug | Boolean | install running in staging or production mode |
USER_ID | NSString | UserId is allocated from the application side |
SESSION_ID | NSString | The user's session is allocated by the application |
CONTENT_URL | NSString | Link of the content you want to watch |
Step 3
Get customer information from DRM Dashboard
Step 4
Create asset (AVURLAsset) with Sigma
objectivec
NSURL *URL = [NSURL URLWithString:@"http://sdrm-test.gviet.vn/public/fairplay/master.m3u8"];
AVURLAsset *asset = [sdk assetWithUrl:URL.absoluteString];
NSArray *requestedKeys = [NSArray arrayWithObjects:kPlayableKey, nil];
[self prepareToPlayAsset:asset withKeys:requestedKeys];
Step 5
Integrate asset into Player
objectivec
self.playerItem = [AVPlayerItem playerItemWithAsset:asset];
self.playerItem.preferredForwardBufferDuration = 1.0;
[self.playerItem addObserver:self
forKeyPath:kStatusKey
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:AVARLDelegateDemoViewControllerStatusObservationContext];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playerItemDidReachEnd:)
name:AVPlayerItemDidPlayToEndTimeNotification
object:self.playerItem];
seekToZeroBeforePlay = NO;
if (!self.player)
{
[self setPlayer:[AVPlayer playerWithPlayerItem:self.playerItem]];
[self.player addObserver:self
forKeyPath:kCurrentItemKey
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:AVARLDelegateDemoViewControllerCurrentItemObservationContext];
[self.player addObserver:self
forKeyPath:kRateKey
options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
context:AVARLDelegateDemoViewControllerRateObservationContext];
}
4. Demo
Sample source code