Skip to main content

Basic Playback

Create the Player

// Sample Player Creation for Clear Content
val url = "https://storage.googleapis.com/shaka-demo-assets/angel-one-widevine/dash.mpd"

val player = PlayerBuilder()
.mediaURL(url)
.mediaType(MediaType.DASH)
.drmScheme(DRMScheme.NONE)
.drmLicenseURL("")
.build(applicationContext)

// Sample Player Creation for Platform DRM Protected Content
val player = PlayerBuilder()
.mediaURL(url)
.mediaType(MediaType.DASH)
.drmScheme(DRMScheme.WIDEVINE)
.drmLicenseURL("https://cwip-shaka-proxy.appspot.com/no_auth")
.build(applicationContext)

Attach Listeners

The application can listen to events such as changes in player state, buffering state, seek state and playback errors by registering a listener/delegate.

player.addListener(this)

Attach player to a view

  • View's XML
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/playerRoot"
android:theme="@style/ThemeOverlay.MaterialComponents.Dark"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="27dp"
android:layout_marginBottom="27dp"
android:layout_marginLeft="48dp"
android:layout_marginRight="48dp"/>
  • Activity / Fragment
class PlayerActivity : AppCompatActivity(), Player.Listener {
private lateinit var playerRoot: FrameLayout
override fun onCreate(savedInstanceState: Bundle?) {
setContentView(R.layout.activity_player)
playerRoot = findViewById(R.id.playerRoot)
}

override fun onResume() {
super.onResume()
if (this::player.isInitialized) {
player.addListener(this)
player.play()
}
}

private fun attachToPlayer() {
player.attachRendererView(
playerRoot,
FrameLayout.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
)
}

override fun onPlayerViewAvailable(playerView: FrameLayout) {
attachToPlayer()
}
}

Start Playback

The Player supports following Control Operations :

  • play - Play a paused/loaded content.
  • pause - Pause a Playing content.
  • seek - Seek a content to a specified position in the Playback Window.
danger

Client application developers shouldn't be performing any operations on the underlying raw player. The Player libraries behaviour is undefined, if done so.

Stop & Abort

  • Invoking stop(), would stop rendering and all underlying resources would be released.
  • Invoking abort(error: Error), would have same effect as stop(). Additionally, onError() callback on the attached Player.Listener will be invoked.
note

abort(error: Error) will be useful when another component (without user intervention) aborts the playback because of some policy restrictions and the appropriate error has to be shown on the UI.

danger

Make sure no Audio focus implementation is done on Application side when consuming QP library versions 7.0.135 and above versions. QP libraries internally handles the Audio focus. Would cause playback related issues if this warning is neglected.