pillarbox-core-business

Provides a MediaSource for handling SRG SSR media URNs to Pillarbox. It basically converts an integration layer MediaComposition to a playable MediaSource.

The supported contents are:

  • On demand video and audio.

  • Live streams, with and without DRM.

  • Token-protected content.

  • DRM protected content.

  • 360° content (see SphericalSurfaceShowcase).

Integration

To use this module, add the following dependency to your module's build.gradle/build.gradle.kts file:

implementation("ch.srgssr.pillarbox:pillarbox-core-business:<pillarbox_version>")

Getting started

Create the player

To play a URN content with PillarboxPlayer, you have to create it like this:

val player = PillarboxExoPlayer(context)
// Make the player ready to play content
player.prepare()
// Will start playback when a MediaItem is ready to play
player.play()

Create a MediaItem with URN

To tell PillarboxPlayer to load a specific MediaItem, it has to be created with SRGMediaItem:

val urn = "urn:rts:video:12345"

// MediaItem created on Prod with Vector.MOBILE
val mediaItem: MediaItem = SRGMediaItem(urn)

// Optionally customize the MediaItem
val customMediaItem: MediaItem = SRGMediaItem(urn) {
setHost(IlHost.Stage)
setVector(Vector.TV)
setVector(context.getVector())
}

// Give the MediaItem to the player so it can be played
player.setMediaItem(mediaItem)

Handle error

All exceptions thrown by PillarboxMediaSource are caught by the player inside a PlaybackException.

PillarboxMediaSource can throw:

player.addListener(object : Player.Listener {
override fun onPlayerError(error: PlaybackException) {
when (val cause = error.cause) {
is BlockReasonException.StartDate -> Log.d("Pillarbox", "Content is blocked until ${cause.instant}")
is BlockReasonException -> Log.d("Pillarbox", "Content is blocked", cause)
is ResourceNotFoundException -> Log.d("Pillarbox", "No resources found in the chapter")
else -> Log.d("Pillarbox", "An error occurred", cause)
}
}
})

Going further

PillarboxMediaSource factory can be created with a MediaCompositionService, which can be used to retrieve a MediaComposition. You can create and provide your own implementation:

class CachedMediaCompositionService : MediaCompositionService {
private val mediaCompositionCache = mutableMapOf<Uri, MediaComposition>()

override suspend fun fetchMediaComposition(uri: Uri): Result<MediaComposition> {
if (uri in mediaCompositionCache) {
return Result.success(mediaCompositionCache.getValue(uri))
}

val mediaComposition = fetchMediaCompositionFromBackend(uri)
if (mediaComposition != null) {
mediaCompositionCache[uri] = mediaComposition

return Result.success(mediaComposition)
} else {
return Result.failure(IOException("$uri not found"))
}
}
}

Then, pass it to PillarboxExoPlayer:

val player = PillarboxExoPlayer(context) {
srgAssetLoader(context) {
mediaCompositionService(CachedMediaCompositionService())
}
}

Packages

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard