Skip to content
On this page

AvPlayer

1. Introduction

Integration information:

get_customer_info

2. Require

Prerequisite

  • Operating system:

    • iOS 8.0 and above

3. Integrate SigmaDRM

3.1. Config pods

Config pods

  • Add below line in Podfile
objectivec
pod 'sigma-drm-ios', :git => 'https://github.com/sigmadrm/sigma-drm-ios.git'
  • Run the command below to update the library:
objectivec
pod install

3.1. Using SigmDRM

Using SigmDRM

  • Add library:

    • libc++.tbd
    • AVFoundation.framework
  • Disable Bitcode

3.2. Setup Sigma DRM

Setup Sigma DRM

objectivec
#import <sigma-drm-ios/SigmaDRM.h>

    -(NSURL *)setupSigma
    {
        [[SigmaDRM getInstance] setAppId:@"APP_ID"];
        [[SigmaDRM getInstance] setMerchantId:@"MERCHANT_ID"];
        [[SigmaDRM getInstance] setSessionId:@"SESSION_ID"];
        [[SigmaDRM getInstance] setUserId:@"USER_ID"];
        NSURL *URL = CONTENT_URL;
        return URL;
    }
PropsTypeDescription
MERCHANT_IDNSStringCustomer ID
APP_IDNSStringApp ID
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

3.3. Create Asset with Sigma

Create asset (AVURLAsset) with Sigma

objectivec
AVURLAsset *asset = [[SigmaDRM getInstance] assetWithUrl: @"CONTENT_URL"];
    NSArray *requestedKeys = [NSArray arrayWithObjects:kPlayableKey, nil];
    [self prepareToPlayAsset:asset withKeys:requestedKeys];

3.4. Integrate asset into Player

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