This guide will walk you through the steps to start a BlendVision One streaming playback using the Android player SDK.
Before We Start
Before proceeding, ensure that you have prepared your BlendVision One streaming content. You can prepare your content in two ways:
- Using BlendVision One Console
- Using BlendVision One API
Step 1: Obtain a Playback Token
- Obtain a valid API token by following the authentication steps
- Retrieve the resource_id and resource_type of the streaming content you would like to playback. There are two ways to obtain this information:
- Retrieve using the API
- VOD: /bv/cms/v1/vods
- Livestream: /bv/cms/v1/lives
- Copy from your BlendVision One console
- Retrieve using the API
- Obtain the resource token using the API: /bv/cms/v1/resources/tokens, with the resource_id and resource_type as body parameters.
- You can also include customer_id in the body parameters if you want to track user playback with your own defined user ID
- Obtain the playback token using the API: /bv/playback/v1/tokens, with the resource token as a body parameter.
const val API_DOMAIN = "https://api.one.blendvision.com"
interface ApiService {
@POST("bv/cms/v1/resources/tokens")
suspend fun createResourceToken(
@Header("Authorization") cmsToken: String, // CMS token
@Body req: ResourceTokenRequest
): ResourceTokenResponse
@POST("bv/playback/v1/tokens")
suspend fun getPlaybackToken(
@Header("Authorization") resourceToken: String
}: PlaybackTokenResponse
}
// data for resource token
data class ResourceTokenRequest(
@SerializedName("resource_id")
val resourceId: String,
@SerializedName("resource_type")
val resourceType: String
)
data class ResourceTokenResponse(
@SerializedName("token")
val resourceToken: String
)
// data for playback token
data class PlaybackTokenResponse(
@SerializedName("token")
val playbackToken: String
)
Step 2: Start a Playback Session
- Start a playback session by making a POST request to bv/playback/v1/sessions/<device-id>:start
- Return: drm_server_endpoint
- Obtain stream information from bv/playback/v1/sessions/<device-id>
- Return: protocol, manifest url, resolutions, thumbnail_seeking_url
const val API_DOMAIN = "https://api.one.blendvision.com"
interface ApiService {
@POST("bv/playback/v1/sessions/{deviceId}:start")
suspend fun startPlaybackSession(
@Header("Authorization") playbackToken: String,
@Path("deviceId") deviceId: String
): StartSessionResponse
@POST("bv/playback/v1/sessions/${deviceId}")
suspend fun getStreamInfo(
@Header("Authorization") playbackToken: String,
@Path("deviceId") deviceId: String
): GetStreamInfoResponse
}
// data for start a session
data class StartSessionResponse(
@SerializedName("drm_server_endpoint")
val endPoint: String
)
// data for get stream information
data class GetStreamInfoResponse(
@SerializedName("sources")
val sources: List<Source>
)
data class Source(
@SerializedName("manifests")
val manifests: List<Manifest>,
@SerializedName("thumbnail_seeking_url")
val thumbnailSeekingUrl: String
)
data class Manifest(
@SerializedName("protocol")
val protocal: String,
@SerializedName("url")
val url: String,
@SerializedName("resolutions")
val resolutions: List<Resolution>
)
data class Resolution(
@SerializedName("height")
val height: String,
@SerializedName("width")
val width: String
)
Step 3: Initialize the Player
- Obtain a valid player license key from your BlendVision One console
- To play the streaming content, create a player instance with the license key and stream information in the initialization configuration:
// create the player instance
private var player: UniPlayer? = null
player = UniPlayer.Builder(
requireContext(),
PlayerConfig(
license = "YOUR_LICENSE_KEY"
)
).build()
// set player view type
binding.kksPlayerServiceView.setupControlPanel(
defaultContentType = ContentType.STANDALONE
)
// bind the new created player to player view
binding.playerView.setUnifiedPlayer(player)
// load stream information
player?.load(
MediaConfig(
source = listOf(
MediaConfig.Source(
url = streamInfoResponse.sources[0].manifests.filter { it.protocol == MediaConfig.Protocol.DASH }[0].url,
protocal = MediaConfig.Protocol.DASH,
drm = MediaConfig.DrmInfo.Widevine(
licenseUrl = startSessionResponse.endPoint,
headers = mapOf("" to "")
)
)
),
title = "",
imageUrl = "",
thumbnailSeekingUrl = ""
)
)
// start playback
player?.start()
// pause/play during playback
player?.pause()
player?.play()
// release the player
player?.release()
Step 4: Manage the Lifecycle of a Playback Session
- To keep the playback session alive, periodically invoke the heartbeat API every 10 seconds
- When the user leaves the player, release the session using the end playback session API
const val API_DOMAIN = "https://api.one.blendvision.com"
interface ApiService {
// post this API every 10 seconds
@POST("bv/playback/v1/sessions/${deviceId}:heartbeat")
suspend fun Heartbeat(
@Header("Authorization") playbackToken: String,
@Path("deviceId") deviceId: String
)
@POST("bv/playback/v1/sessions/${deviceId}:end")
suspend fun EndPlaybackSession(
@Header("Authorization") playbackToken: String,
@Path("deviceId") deviceId: String
)
}
What's More
- To control the playback, refer to the API Reference documentation.
- To track the playback, refer to the Playback Event documentation.
- To ensure a smooth playback experience, check the compatible operating systems.