All Collections
Paywalls
Media Specification
Displaying a video on Android devices
Displaying a video on Android devices

Video paywall Android ExoPlayer

Kevin Herembourg avatar
Written by Kevin Herembourg
Updated over a week ago

Purchasely Android SDK does not include by default a video player starting with version 3.1.0 to avoid dependency conflicts in your project.

If you have added a video to your paywall, you need to include our player dependency or implement PLYPlayerInterface.

Purchasely video player

The easiest way is to add the Purchasely player in your build.gradle file.
Our SDK will detect it and use it to play videos in a paywall.
โ€‹Implementation 'io.purchasely:player:3.2.1'

This includes ExoPlayer version 2.15.1, if you already use another version of Exoplayer in your project not compatible with this version you should provide your own class to Purchasely SDK.

Custom video player

You can use your own video player for Purchasely paywall, this player needs to be a View and implements PLYPlayerInterface.

interface PLYPlayerInterface {
fun setup(url: String, contentMode: String, isMuted: Boolean)
fun play()
fun pause()
fun release()
}

You can declare it to the SDK either by specifying the path to your class.

Purchasely.playerView = "com.myapp.ui.player.MyPlayerView"

Notice: your class must have a constructor with android.content.Context as unique parameter

Or by providing an instance of your class.

Purchasely.playerView = MyPlayerView(context)

Notice: you should set it to null when the player is no longer needed to avoid memory leaks

A sample of implementation of PLYPlayerInterface with Exoplayer

class PurchaselyPlayerView(context: Context) : PlayerView(context), PLYPlayerInterface {

private var exoPlayer: SimpleExoPlayer = SimpleExoPlayer.Builder(context).build()

override fun setup(url: String, contentMode: String, isMuted: Boolean) {
val mediaItem = MediaItem.fromUri(Uri.parse(url))
exoPlayer.addMediaItem(mediaItem)
exoPlayer.playWhenReady = false
exoPlayer.prepare()

resizeMode = when (contentMode) {
"fill" -> AspectRatioFrameLayout.RESIZE_MODE_ZOOM
"fit" -> AspectRatioFrameLayout.RESIZE_MODE_FIT
else -> AspectRatioFrameLayout.RESIZE_MODE_ZOOM
}

player = exoPlayer
controllerAutoShow = false

if (isMuted) {
exoPlayer.volume = 0f
} else {
exoPlayer.volume = 1f
}

exoPlayer.repeatMode = Player.REPEAT_MODE_ALL
hideController()
}

override fun play() {
exoPlayer.play()
}

override fun pause() {
exoPlayer.pause()
}

override fun release() {
exoPlayer.release()
}
}

Did this answer your question?