The OpenTV Player SDK for FPS supports multiple instance of OTVAVPlayer to be created and used at the same time. This allows features such as the main stream playback continuing to be shown whilst a preview window of another stream is shown to the user.

To use multiple players for clear streams, simply create two players and attach each to its own AVPlayerLayer (or OTVContainerView). By doing this you will get independent playback and control for each player.

Multi instance playback for encrypted streams is slightly more complex, requiring additional information from the license delegate.


To support playback of multiple encrypted streams at the same time, a license delegate is created to handle the license requests for each stream differently.

The OTVDefaultLicenseDelegate used in the encrypted-playback-simple example only supports single instance playback, with the license delegate being told which HTTP headers are required to request the license for playback of the next stream.

For multi instance playback an alternative implementation is provided, with OTVCommonLicenseDelegate subclassed (of which OTVDefaultLicenseDelegate is also a subclass). In this example code, the implementation is contained in MultiInstanceDelegate.swift.

The license delegate is effectively given multiple HTTP headers to request licenses for different streams at the same time. Instead of a setHTTPHeader function to set the license request header, the setStreamToken function takes both an SSP stream token and the related SSP content ID. The token is stored in a map using the content ID as the key, and can then be retrieved in the generateHTTPHeaders function when a license request is being made.

When a license request is made, the delegate's generateHTTPHeaders function is passed an asset ID, which is base-64 encoded JSON which includes the SSP content ID. The stream's token can then be pulled from the map and used to authenticate the license request.

If you use MultiInstanceDelegate in your own app, so that memory usage does not increase endlessly, tokens can be removed from tokenIDMap when they are no longer required.

In the ViewController class, the example code shows how to setup the license delegate and provide the SSP token and content ID before setting up two players. The example has one encrypted stream and one clear stream; the clear stream does not require a license and so does not have a token or content ID. For two encrypted streams, a second call to defaultLicenseDelegate.setStreamToken would be required, to provide the necessary second token and content ID.