The Firework Android SDK provides comprehensive livestream features including live broadcasts, replays, trailers, interactive chat, polls, questions, and giveaways. This guide covers livestream setup, configuration, and usage.
Overview
The FireworkSdk.livestream object provides access to all livestream-related functionality. Through this interface, you can:
Handle user interactions during livestreams
Manage chat and username display
Respond to links clicked within livestream content
Configure livestream-specific UI elements
Handle giveaways, polls, and questions
Livestream Content Types
The SDK supports three types of livestream content:
1. Livestream/Restream/VideoToLive
Real-time streaming content with interactive features:
Live chat
Real-time polls and questions
Giveaways and promotions
Interactive product links
2. Livestream Replays
Recorded livestream content that can be played on-demand:
import android.app.Application
import com.firework.sdk.FireworkSdk
import com.firework.sdk.FireworkSdkConfig
import com.firework.sdk.FireworkInitError
import com.firework.imageloading.glide.GlideImageLoaderFactory
import com.firework.external.livestream.singlehost.SingleHostLivestreamPlayerInitializer
class MyApp : Application() {
override fun onCreate() {
super.onCreate()
// Build SDK configuration with livestream support
val config = FireworkSdkConfig.Builder(context = this)
.clientId("YOUR_CLIENT_ID")
.imageLoader(GlideImageLoaderFactory.createInstance(context = this))
.addLivestreamPlayerInitializer(SingleHostLivestreamPlayerInitializer())
.build()
// Use the latest livestream player version (V2 - recommended)
FireworkSdk.setLivestreamPlayerVersion(FwLivestreamPlayerVersion.V2)
// Initialize SDK
FireworkSdk.init(
fireworkSdkConfig = config,
onSuccess = {
setupLivestreamCallbacks()
},
onError = { error ->
// Handle initialization error
}
)
}
private fun setupLivestreamCallbacks() {
// Configure livestream callbacks here
// See Livestream Callbacks section below
}
}
FireworkSdk.livestream.setOnLinkClickListener { link ->
// Open link in browser or handle deep link
openUrl(link)
true // Return true if handled, false to let SDK handle
}
FireworkSdk.livestream.setOnInteractionListener { interaction ->
when (interaction) {
is QuestionInteraction -> {
// User submitted an answer to a question
Log.d("Livestream", "Question: ${interaction.question}")
Log.d("Livestream", "Answer: ${interaction.answer}")
}
is PollInteraction -> {
// User voted in a poll
Log.d("Livestream", "Poll: ${interaction.pollId}")
Log.d("Livestream", "Option: ${interaction.selectedOption}")
}
is GiveawayInteraction -> {
// User joined a giveaway
Log.d("Livestream", "Giveaway: ${interaction.giveawayId}")
}
}
}
// Update username
FireworkSdk.livestream.updateUsername(
username = "JohnDoe",
onSuccess = {
Log.d("Livestream", "Username updated successfully")
},
onError = { error ->
Log.e("Livestream", "Failed to update username: ${error.message}")
}
)
// Get current username
val currentUsername = FireworkSdk.livestream.getUsername()
// Configure username display settings
FireworkSdk.livestream.updateUsernameConfiguration(
UsernameConfiguration(
isEditable = true, // Allow users to edit their username
isHidden = false // Show username in chat
)
)
FireworkSdk.livestream.setOnGiveawayTermsAndConditionsClickListener { url ->
// Open T&C page
openUrl(url)
}
FireworkSdk.livestream.setOnUpdateUsernameListener { newUsername, onComplete ->
// Validate username with your backend
if (isValidUsername(newUsername)) {
// Accept the username
onComplete(true)
} else {
// Reject the username
onComplete(false)
showError("Username not available")
}
}
val viewOptions = viewOptions {
baseOptions {
feedResource(FeedResource.Discovery) // Can include livestream content
}
}
val videoFeedView = findViewById<FwVideoFeedView>(R.id.videoFeedView)
videoFeedView.init(viewOptions)