Logging & Debugging
The fl-foundation library abstracts away platform-dependent functionality and exposes a platform-agnostic API for the consuming modules.
It primarily focuses on the following features:
- Networking using
HttpClient - Storage using
KeyValueStore - Logging using
Logger
Logger
You can create a logger using defaultPlatformFactory:
val logger = FoundationFactory.defaultPlatformFactory().loggerWith {
tag("FOUNDATION-SAMPLE")
prefixCallSiteInfo(true)
maxVerboseLevel(Logger.Level.TRACE)
}
logger.trace { "Entering a function" }
logger.debug { "response is $response" }
logger.info { "An information message" }
logger.warn { "Mismatch in data" }
logger.error { "An error occurred" }
The following logger levels are supported (ordered in terms of verbosity from the most to the least):
TRACEDEBUGINFOWARNERROR
Playback logger
The PlayerBuilder accepts a logger, and application developers can configure a logger with their own tag information and logger levels.
val logger = FoundationFactory.defaultPlatformFactory().loggerWith {
tag("FL-PLAYBACK")
prefixCallSiteInfo(true)
maxVerboseLevel(Logger.Level.INFO)
}
val player = PlayerBuilder()
.logger(logger)
//other configurations
.build(getApplication())
Download logger
You can configure the logger for download during DownloadManager creation.
val logger = FoundationFactory.defaultPlatformFactory().loggerWith {
tag("FL-DOWNLOADER")
prefixCallSiteInfo(true)
maxVerboseLevel(Logger.Level.INFO)
}
DownloadManager.create(this, logger).resumeDownloads()
Player Stats overlay
The Player Stats overlay ("Stats for Nerds") shows live playback diagnostics on top of the player. It shows any custom rows your app passes, followed by the viewport and video resolution, codecs, seek position, playback speed, volume, average and playing bitrate, dropped frames, connection speed, required bandwidth, and buffer health. It also has two live charts: the buffer ahead of the playhead, and the available network bandwidth. The overlay samples once a second while it is attached to a window, and stops sampling when it is detached.
Create the overlay from a Player and add it to any container:
val statsView = player.createPlayerStatsView(
context = this,
customInfo = mapOf(
"Content ID" to contentId,
"Ad Break" to adBreakName
),
onClose = { rootLayout.removeView(statsView) }
)
rootLayout.addView(
statsView,
FrameLayout.LayoutParams(FrameLayout.LayoutParams.MATCH_PARENT, FrameLayout.LayoutParams.MATCH_PARENT)
)
statsView.requestFocus()
| Parameter | Default | Description |
|---|---|---|
| context | - | The Android Context used to inflate the overlay. |
| customInfo | emptyMap() | Label and value rows shown at the top of the overlay, in iteration order. Pass any number of entries. |
| onClose | null | Called when the user presses Close or Back. The host removes the view. |
On a TV or other remote-controlled device, the Close button is the only focusable element. Up and down scroll the overlay when the screen is too short to show every row, and Back calls onClose.
The buffer chart shows only the buffer ahead of the playhead. ExoPlayer does not expose how much back buffer it holds, so buffer behind the playhead is not shown.