Skip to content
On this page

AvPlayer

1. Introduction

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;
    }
PropsTypeDescription
MERCHANT_IDNSStringCustomer ID
APP_IDNSStringApp ID
sigma_debugBooleaninstall running in staging or production mode
USER_IDNSStringUserId is allocated from the application side
SESSION_IDNSStringThe user's session is allocated by the application
CONTENT_URLNSStringLink of the content you want to watch

Step 3

Get customer information from DRM Dashboard

get_customer_info

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