Listeners
Error listener
When an error occurs, the Short Video module triggers an error callback with a code and a message.
To listen to errors, set a BlsShortVideoErrorListener
to the ShortVideoView
.
shortVideoView.setErrorListener(object : BlsShortVideoErrorListener {
override fun onShortVideoError(code: Int, msg: String?) {
}
})
The error code can be found in the BlsShortVideoErrorCode
.
Video item click listener
When a user clicks on a video item, it opens the main player and triggers a callback.
shortVideoView.setVideoItemClickedListener(object : BlsShortVideoItemClickListener {
override fun onShortVideoItemClicked(videoId: String) {
}
})
The implementation of the listener mainly serves analytics purposes and does not affect the flow.
Detail player action listener
This listener is different from other listeners as it's bound to a singleton handler. To avoid memory leaks, avoid implementing this interface as an anonymous class in the activity context. Instead, create a class and implement the interface.
class MainPlayerAction : BlsShortVideoMainPlayerActionListener {
override fun onProductItemClicked(
context: Context, item: ShortVideoProductModel
): Boolean {
context.openBrowser(item.productUrl.orEmpty())
return true
}
override fun onShareVideo(context: Context, videoId: String): Boolean {
context.shareText(videoId)
return true
}
override fun onSubmitPollError(context: Context, errorCode: Int) {
}
override fun onSubmitDefaultAnswerError(context: Context, errorCode: Int) {
}
override fun onSubmitFollowupAnswerError(context: Context, errorCode: Int) {
}
}
The onProductItemClicked
method is triggered when a shop CTA button is clicked. Returning true
in this method consumes the event and stops the flow.
If false
is returned, the SDK continues to handle the event.
The onShareVideo
method is triggered when a share button is clicked (in both Carousel and Main player). Returning true
consumes the event and stops the flow.
If false
is returned, the SDK continues to handle the event, and the default behavior is to open the system share dialog.
The onSubmitPollError
method is triggered when submitting a poll option fails.
The onSubmitDefaultAnswerError
method is triggered when submitting a default answer fails.
The onSubmitFollowupAnswerError
method is triggered when submitting a follow-up answer fails.