Skip to content

Video Workouts ​

Video workouts are rendered through WorkoutVideoFragment. Use this flow for streaming sessions where TrainingKit displays the video player, navigation metadata, casting controls, and the completion screen inside the Android SDK UI.

Capabilities ​

  • Stream workout video content
  • Pause/resume playback
  • Skip forward/backward by 15 seconds
  • Navigate through video sections
  • Optional Google Cast controls
  • Optional exercise revision action
  • Workout save-state callbacks

Create the fragment ​

Fetch the video workout payload from the TrainingKit GraphQL API, prepare any JSON configuration your integration needs, then attach the fragment to your activity container.

kotlin
val videoFragment = WorkoutVideoFragment.newInstance(
    workoutContent,   // GraphQL payload
    workoutConfig,    // JSON configuration
    jwtToken          // JWT token
)

WorkoutVideoFragment.newInstance returns null when the payload does not contain a playable video URL. Check the result before committing the fragment.

kotlin
WorkoutVideoFragment.newInstance(
    workoutContent = workoutContent,
    workoutConfig = workoutConfig,
    JwtToken = jwtToken,
    castAvailable = true
)?.let { fragment ->
    supportFragmentManager.beginTransaction()
        .replace(R.id.workoutContainer, fragment)
        .commit()
}

Host activity integration ​

  • Add the fragment to your activity layout or container.
  • Implement WorkoutVideoKitInterface on the host activity before displaying the fragment.
  • Configure supported text overrides before fragment creation. See Configuration Options.
  • Keep the host activity alive for the full video flow.
  • Keep the screen on while the workout is visible.
  • Forward Android back actions to TrainingKit when you want the SDK to show its own quit flow.
kotlin
override fun onResume() {
    super.onResume()
    window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}

override fun onStop() {
    super.onStop()
    window.clearFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
}

If your integration uses Android 13 back handling or OnBackPressedDispatcher, dispatch GoAction.Workout.BackPressed() instead of closing the activity immediately. This lets TrainingKit decide whether to confirm quit or close.

Google Cast ​

Set castAvailable = true only when your app has configured Google Cast support. TrainingKit still checks whether Cast is available at runtime before showing the route button.

kotlin
override fun setupChromecastButton(castButton: MediaRouteButton) {
    // Optional: let the host app customize the Cast route button.
}

Handle completion ​

Video workouts report completion through the WorkoutVideoKitInterface implemented by your host activity.

kotlin
override fun saveWorkout(saveState: SaveWorkoutState): Promise<*, *, *> {
    // The workout completed. Persist saveState before resolving if needed.
    return DeferredObject<SaveWorkoutState, Throwable, Throwable>()
        .resolve(saveState)
}

override fun goToNextScreen() {
    // Continue or dismiss your host flow after the workout screen is done.
    finish()
}

override fun reviseExercise() {
    // Optional: open your exercise revision flow when the user requests it.
}

override fun trackEvent(data: TrackingData) {
    // Optional: forward TrainingKit analytics metadata.
}

Use saveWorkout as the source of truth for completed workout results. Resolve its promise when your persistence step is finished. Use goToNextScreen or your close handling for navigation after the workout, and trackEvent for analytics-only events.

SaveWorkoutState contains the workout id, title, duration, block timing, calories, and start time for the video session. Persist the fields needed by your backend before resolving the promise.

Error and admin hooks ​

WorkoutVideoKitInterface also includes hooks for error reporting, JWT verification, and admin-only behavior.

HookUsage
logError(message: String, data: HashMap<String, Any>)Forward SDK video playback or source errors to your logging system.
onTokenVerificationError(exception: JWTVerificationException)Handle JWT verification failures from the SDK.
isAdmin()Return whether the current user should access admin-only video behavior. Most client apps should return false.