playClip
Notifies the client app that a particular key plays clip should be played.
Overview
The SDK calls this method when a user selects a key play clip to watch. Your app should handle starting playback of the requested clip. Note that the MaestroKeyPlaysResponse subdivides key plays by section, so the index referenced here is the global index in the flattened list of key plays across all sections.
Syntax
abstract fun playClip(index: Int, clipId: String?)
Parameters
| Parameter | Type | Description |
|---|---|---|
index | Int | The flattened index of the clip in the key plays list |
clipId | String? | Optional clip identifier |
Example
override fun playClip(index: Int, clipId: String?) {
lifecycleScope.launch {
try {
// Find the clip at the given index
val clip = getClipAtIndex(index)
// Start playback
videoPlayer.playClip(clip)
// Notify SDK that playback started
viewModel.didStartPlayingClip(index)
} catch (e: Exception) {
// Notify SDK that playback failed
viewModel.clipDidFailToPlay(index)
}
}
}
private suspend fun getClipAtIndex(index: Int): ClipData {
val keyPlaysResponse = keyPlaysState.value.successOrNull()
?: throw IllegalStateException("No key plays data")
// Flatten all sections and get clip at index
val allClips = keyPlaysResponse.sections.flatMap { it.clips }
return allClips[index]
}
Notes
- The index is a flattened global index across all sections
- Handle potential errors gracefully and notify the SDK via
clipDidFailToPlay() - Start playback asynchronously to avoid blocking
- Notify the SDK of playback events using
MaestroEventInterfacemethods
Related Methods
- didStartPlayingClip() - Notify SDK when clip starts
- clipDidFailToPlay() - Notify SDK if playback fails