Widget - Player Deck -Beta
FwPlayerDeckView is a horizontal video feed component in the Firework Android SDK. It displays a scrollable row of video thumbnails with built-in autoplay support and product panel
This page covers how to integrate FwPlayerDeckView into your Android app and documents every public method and property.
Table of Contents
1. Adding the View in XML
Add FwPlayerDeckView to your layout file. The recommended way to configure FwPlayerDeckView is programmatically via ViewOptions, so the XML tag only needs android:id, layout_width, and layout_height:
<com.firework.videofeed.FwPlayerDeckView
android:id="@+id/playerDeck"
android:layout_width="match_parent"
android:layout_height="500dp" />Note: Do not set custom XML attributes on
FwPlayerDeckView. Use theViewOptions.BuilderAPI (described below) for all configuration. See the next section for how to choose the correctlayout_height.
2. Recommended Height Configuration
Choosing the right height for FwPlayerDeckView is important for a good user experience. We recommend a height that shows approximately 1.5 deck items on screen, so the user can see the current item fully and get a visual hint that more content is available by scrolling horizontally.
How Item Width Is Derived from View Height
Each deck item fills the full height of the FwPlayerDeckView. The item consists of a 9:16 video area on top and a 72dp product panel at the bottom. The SDK calculates item width from the available height:
The number of items visible on screen is determined by: screenWidth / itemWidth.
The Formula
To display 1.5 items horizontally, set the view height to:
This is derived from solving itemWidth = screenWidth / 1.5:
Reference Values for Common Screen Widths
360
~499
Budget / mid-range phones
390
~534
Pixel 7, iPhone-class widths
412
~560
Pixel 7 Pro, Samsung Galaxy S series
Tip: For most portrait-mode phones, a height of 500dp is a reasonable default that works well across common screen sizes. For a more precise fit, compute the height dynamically at runtime.
Dynamic Calculation at Runtime
To compute the optimal height programmatically based on the device's actual screen width:
In traditional Views (Kotlin):
In Jetpack Compose:
Note: If you configure
feedPaddingoritemSpacinginLayoutOption, the effective visible area changes slightly. The formula above ignores these values for simplicity; in practice the difference is negligible.
3. Programmatic Initialization (Fragment)
The typical lifecycle for FwPlayerDeckView in a Fragment is:
Build a
ViewOptionsinstance viaViewOptions.Builder.Call
init(viewOptions, fragmentManager)to start loading content.Call
destroy()inonDestroyView()to release resources.
Full Example
Key Points
feedResourcedetermines the content source. Common options include:FeedResource.Discovery— curated discovery feedFeedResource.Channel("channelId")— all videos from a channelFeedResource.Playlist("channelId", "playlistId")— a specific playlist
autoplayinPlayerOptioncontrols whether the first visible video plays automatically.init()can be called multiple times to reinitialize with new options (e.g., switching channels). Each call generates a newfeedId.destroy()must always be called when the view is no longer needed to prevent memory leaks.
4. Compose Integration
Embed FwPlayerDeckView inside Jetpack Compose using AndroidView. Use the factory block for creation and initialization, and onRelease for cleanup.
Key Points
The hosting Activity must extend
FragmentActivity(orAppCompatActivity) so thatsupportFragmentManageris available.onReleaseis called when theAndroidViewis removed from the composition. This is the correct place to calldestroy().Wrap
ViewOptionsinremember { }to avoid rebuilding on every recomposition.
5. Public API Reference
init(options: ViewOptions?, fragmentManager: FragmentManager)
init(options: ViewOptions?, fragmentManager: FragmentManager)Initializes the view with configuration options and starts loading content.
options
A ViewOptions instance built via ViewOptions.Builder. Pass null to use XML-declared attributes or defaults.
fragmentManager
The FragmentManager from the hosting Fragment (childFragmentManager) or Activity (supportFragmentManager).
Usage notes:
Must be called before any content is displayed.
Can be called multiple times to reinitialize with new options. Each call generates a new embed instance ID (
feedId).If the Firework SDK has not been initialized, the error listener will receive
SdkNotInitialized.
destroy()
destroy()Releases all resources held by the view: cancels coroutines, unbinds dependency injection, destroys impression trackers, and stops visibility tracking.
Usage notes:
Must be called when the view is no longer needed (e.g., in
onDestroyView()for Fragments, oronReleasefor ComposeAndroidView).If a fullscreen player or PiP session is active for this view, the DI scope is preserved until the player closes.
refresh()
refresh()Clears the current feed and reloads content from the data source.
Usage notes:
Useful for pull-to-refresh implementations.
If the SDK is not initialized, the error listener receives
SdkNotInitialized.
setOnErrorListener(listener: FwErrorListener)
setOnErrorListener(listener: FwErrorListener)Registers a callback to receive SDK errors.
listener
FwErrorListener
A functional interface: fun onFwError(error: FwError)
Usage notes:
Set this before calling
init()so that initialization errors (e.g.,SdkNotInitialized) are captured.Only one listener can be active at a time. Setting a new listener replaces the previous one.
setOnFeedItemClickListener(listener: FeedItemClickListener)
setOnFeedItemClickListener(listener: FeedItemClickListener)Registers a callback triggered when a user taps a video thumbnail.
The FeedItem data class contains:
id
String
The video ID
title
String
The video caption/title
duration
Long
Video duration in seconds (0 for livestreams)
indexInTheList
Int
Position in the feed list
videoInfo
VideoInfo
Detailed video metadata for analytics
setOnFeedViewStateListener(listener: FeedViewStateListener)
setOnFeedViewStateListener(listener: FeedViewStateListener)Registers a callback for feed loading state changes.
Loading
The feed is currently fetching data.
LoadData
Data has been successfully loaded and displayed.
EmptyFeed
The data source returned no content.
EndOfFeed
All available content has been loaded (no more pages).
Error(message)
An error occurred during loading.
setVisibilityTrackingEnabled(enabled: Boolean)
setVisibilityTrackingEnabled(enabled: Boolean)Enables or disables automatic visibility-based autoplay control.
When enabled, the view uses a ViewTreeObserver-based tracker (OnScrollChangedListener + OnGlobalLayoutListener + getGlobalVisibleRect) to automatically detect when the view scrolls in or out of the visible area. Playback is paused when less than 50% of the view is visible and resumed when at least 50% is visible again.
Usage notes:
Can be called before or after
init().See Page 2: Handling Autoplay in Scrollable Containers for details and known Compose limitations.
onViewPortEntered()
onViewPortEntered()Manually notifies the view that it has become visible in the viewport. Resumes autoplay if applicable.
Usage notes:
Use this when you are manually tracking visibility (Approach 1 in Page 2).
Has no effect if
init()has not been called.
onViewPortLeft()
onViewPortLeft()Manually notifies the view that it has left the viewport. Pauses autoplay.
Usage notes:
Use this when you are manually tracking visibility (Approach 1 in Page 2).
Has no effect if
init()has not been called.
feedId: String (read-only property)
feedId: String (read-only property)Returns the current embed instance ID. This value is unique per initialization cycle and changes each time init() is called.
Usage notes:
Useful for analytics or debugging to correlate events with a specific initialization cycle.
Last updated
Was this helpful?