Android Integration Skill
Integration conventions for the StreamLayer Android SDK that keep an AI agent's diff small and correct — where to initialize, where to place StreamLayerFragment, delegate wiring, and minimal-diff placement.
StreamLayer Android SDK Integration
How to wire StreamLayer into an existing Android app cleanly. Follow the rules — they prevent the common over-integration mistakes.
This page is the human-readable form of the streamlayer-android-integration agent skill. Reference it from your AI agent alongside the streamlayer-docs MCP — see Integrate with an AI Agent.
Pick the package
io.streamlayer:androidsdk— the Android SDK, distributed via the public Maven repository (mavenCentral()+maven { url "https://jitpack.io" }).- Main UI element:
StreamLayerFragment(io.streamlayer.sdk.main.StreamLayerFragment) — the StreamLayer Element container, placed with aFragmentContainerViewtaggedandroid:tag="StreamLayerFragment". - Player extension (pick one):
io.streamlayer:android-media3orio.streamlayer:android-exoplayer— or implementSLRVideoPlayerProvideryourself if you use a different player. - Requirements: Android Studio 4.0+, target SDK 33+, min SDK 23, Kotlin or Java.
Rules (do this)
-
Initialize once and high; place the fragment low. Call
StreamLayer.initializeApp(this, SDK_KEY)exactly once in yourApplication.onCreate(). Initialize your player extension (StreamLayerMedia3Player.initSdk(this)/StreamLayerExoPlayer.initSdk(this)) right after. AddStreamLayerFragmentinside the player screen's layout — the one that owns the video — not as a global singleton fragment.- ❌ Adding
StreamLayerFragmentbeforeStreamLayer.initializeApp()runs — this crashes the app. - ✅
initializeAppinApplication;StreamLayerFragmentdeclared in the player activity's layout.
- ❌ Adding
-
Place
StreamLayerFragmentwithFragmentContainerView, anchored to your player. Useandroid:tag="StreamLayerFragment"on every version of the fragment. In portrait, pin its top to the player view and setoverlayHeightSpace(viawithStreamLayerUI { }) from a layout listener so the expanded Element stops at the player's bottom edge. In landscape, let it go full-screen and pick a side withoverlayLandscapeMode. -
Wire only the
SLRAppHost.Delegatecallbacks your app needs. Set it withwithStreamLayerUI { delegate = appHostDelegate }and clear it (delegate = null) inonDestroy(). ImplementrequestAudioDucking(level)/disableAudioDucking()/setAudioVolume(value)/getAudioVolumeListener()for the player-audio bridge,requestStream(id)if the SDK can request a stream switch, andonScreenSizeChanged(size)only if you useOverlayLandscapeMode.LBAR. -
Forward authentication after init. For logged-in users, call
StreamLayer.authorizationBypass(schema, token)from a coroutine; for guests useStreamLayer.useAnonymousAuth(). Both throwRuntimeExceptionon failure — always wrap inrunCatching/try-catch. ImplementSLRAuthRequestHandler.onAuthRequired()only if you want to handle the SDK's own auth-required prompt (e.g. by openingStreamLayerAuthActivity). -
Keep credentials and the diff simple. The SDK API Key is a public, client-side value from StreamLayer Studio — a constant or your existing config is fine; don't add
.envscaffolding. CallStreamLayer.createEventSession(eventId, timecodeProvider)when the user switches streams (timecodeProvideris optional, only needed for spoiler prevention). Fit the fragment around your existing player and layout — don't restructure the app or refactor unrelated view code.
Gotchas
- App crashes on
StreamLayerFragmentinflate. Almost alwaysStreamLayer.initializeApp()hasn't run yet — the fragment's component builder depends on an initialized SDK context. - Expanded Element covers the player. Missing
overlayHeightSpaceupdate in portrait mode — wire the layout listener described in the Layout Guide. - Two player extensions installed. Only add one of
android-media3orandroid-exoplayer— mixing both causes dependency conflicts. authorizationBypass/useAnonymousAuthsilently crash. Both throwRuntimeException— always catch it.- Delegate stops firing.
SLRAppHost.Delegatemust stay assigned for as long as the screen is visible; clear it inonDestroy(), not earlier. - Authoritative API details: the
streamlayer-docsMCP (search/fetch) and the API Reference.
Related
- Integrate with an AI Agent — Connect the MCP and prompt your agent to run this integration
- Integration Guide — Complete Android SDK setup and configuration
- Authentication Forwarding — Bypass, phone, and anonymous auth flows
- Video Management — Media3/ExoPlayer extensions and
SLRVideoPlayerProvider - Layout Guide — Portrait/landscape placement and L-bar setup
Updated 16 days ago
