Skip to content

Instantly share code, notes, and snippets.

@vizbee
Last active February 19, 2024 15:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save vizbee/59c729036bc2a6f6f5c1869a772a6a20 to your computer and use it in GitHub Desktop.
Save vizbee/59c729036bc2a6f6f5c1869a772a6a20 to your computer and use it in GitHub Desktop.

Instructions

  • Step 1 - open the 'MyVizbeeAppAdapter' file in the 'vizbee' folder of your app's repo.
  • Step 2 - implement the 'onStart' method using the snippets provided below.
package com.myapp
import org.json.JSONObject
import tv.vizbee.screen.api.adapter.VizbeeAppAdapter
import tv.vizbee.screen.api.messages.CustomEvent
import tv.vizbee.screen.api.messages.VideoInfo
import android.util.Log
import myapp.Deeplinking
/**
* VizbeeAppAdapter to handle all "app" level commands
* sent by mobile app.
*
* App level commands include:
* [1] start or deeplink to a new video
* [2] handle app events
*/
public class MyVizbeeAppAdapter : VizbeeAppAdapter() {
/**
* Handle a request to start a video or audio deep-link from sender.
* This method should setup app state to correctly start playback of new video or audio.
* @param videoInfo The information about the video or audio to start.
* @param positionMs The start position of the video or audio.
*/
fun onStart(video: VideoInfo, positionMs: Long?) {
//--------
// handle unsupported content types
//--------
// As an example, if the Live content is not supported please use the following
// code block to handle the start video request
// Its important to send the interrupted status to the sender for it to dismiss the player card
if (videoInfo.isLive){
showInformativeModel()
sendInterruptedStatusToSender(video)
return
}
//--------
// handle deeplink sent from mobile apps
//--------
// Deeplinking can use default VideoInfo fields or custom metadata
Log.v(LOG_TAG, "onStart: video GUID " + video.getGUID())
val json: JSONObject = video.getCustomMetadata()
if (null == json) {
Log.w(LOG_TAG, "onStart: invalid metadata from mobile app")
return
}
Log.v(LOG_TAG, "onStart: custom metadata $json")
val guid: String = video.getGUID()
val catalogKind: String = json.optString("catalogKind")
val catalogId: String = json.optString("catalogId")
val mediaType: String = json.optString("mediaType")
val trackId: String = json.optString("trackId")
if (null != catalogKind && null != catalogId && catalogKind.equals("live", ignoreCase = true)) {
Log.i(LOG_TAG, "onStart: deeplinking to LIVE channel = $catalogId")
Deeplinking.getInstance().playLive(catalogId)
return
}
Log.e(LOG_TAG, "onStart: received invalid custom metadata $json")
}
private fun showInformativeModel() {
// Logic to show any information to the user
}
private fun sendInterruptedStatusToSender(videoInfo: VideoInfo) {
Log.v("Send video status error - set player adapter ")
var sentLoadingStatus = false
Vizbee.getInstance().setPlayerAdapter(videoInfo, object : VizbeePlayerAdapter() {
override fun play() {}
override fun pause() {}
override fun seek(p0: Long) {}
override fun stop(p0: Int) {}
override fun getVideoStatus(): VideoStatus {
val videoStatus = VideoStatus()
if (sentLoadingStatus) {
Log.i("Sending INTERRUPTED video status")
videoStatus.mPlaybackStatus = PlaybackStatus.INTERRUPTED
} else {
Log.i("Sending LOADING video status")
videoStatus.mPlaybackStatus = PlaybackStatus.LOADING
sentLoadingStatus = true
}
return videoStatus
}
})
Looper.myLooper()?.let {
Handler(it).postDelayed({
Log.i("Resetting player adapter")
Vizbee.getInstance().resetPlayerAdapter()
}, 1000L)
}
}
companion object {
private const val LOG_TAG = "VIZBEE_MyVizbeeAppAdapter"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment