ScrollView Implementation

Android SDK

Adding the Primis Player to a ScrollView

  1. Add the Player Container to your layout. Use a FrameLayout. Set the height to WRAP_CONTENT and the width to MATCH_PARENT:
<FrameLayout
             android:id="@+id/player_container"
             android:layout_height="wrap_content"
             android:layout_width="match_parent"/>
  1. Get a reference to the view that will contain the Primis player:
val playerContainer = viewBinding.playerContainer
  1. Declare a PrimisPlayer variable to contain the Primis player and all of its functionality.
var primisPlayer: PrimisPlayer? = null
  1. Send your playerContainer via the PrimisConfiguration.Builder’s playerContainer() function
primisPlayer = PrimisConfiguration.Builder()
								 .placement("123456")
								 .playerContainer(playerContainer)
  							 .createPlayer(applicationContext)
  1. add Primis player:
primisPlayer.add()
  1. Removing Primis Player

Call PrimisPlayer.remove when the view is about to be destroyed (e.g. onDestroy(), onDestroyView())

primisPlayer?.let {
  it.remove()
  primisPlayer = null
}

📘

We used ViewBinding in our example but other approaches are good as well

Code example

package com.app.example-app

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.FrameLayout
import androidx.constraintlayout.widget.ConstraintLayout

// import Primis player
import tech.primis.player.PrimisPlayer

class MyActivity : AppCompatActivity() {
  
  //The PrimisPlayer class is an extension of "FrameLayout" and therefore 
  //may be added to any view type.
	private var primisPlayer: PrimisPlayer? = null

  
  override fun onCreate(savedInstanceState: Bundle?) {
     super.onCreate(savedInstanceState)
     setContentView(R.layout.activity_screen)

     //Fetch the view that will contain the Primis player. A FrameLayout.
		 val playerContainer = findViewById(R.id.player_container)

     //Create the player.
     primisPlayer = PrimisConfiguration.Builder()
    			.placement("123456") //The placement ID
    			.playerContainer(playerContainer) //The player container. A FrameLayout
    			.createPlayer(applicationContext)

     //Add Primis player. Once added it will initiate.
     primisPlayer.add()
  }
  
  override fun onDestroy() {
    super.onDestroy()
    primisPlayer?.remove()
    primisPlayer = null  
  }
}