Logging in the Android Player SDK
Troubleshooting streams on mobile devices can be challenging, especially for issues that occur rarely and only in specific circumstances. A common approach in such a scenario is to add log statements to the code in order to observe configurations and states at the time of the failure.
Using events for logs
All state updates of the Android Player are published through the EventEmitter
interface which is implemented by all main components of the Player: the Player
and the Source
for playback as well as the OfflineContentManager
for downloading content for offline playback.
Apart from the events that indicate a specific state change in the respective component, there are three more general events that are especially useful for logging:
- The
Error
event signals a fatal error that can not automatically be recovered from. - The
Warning
event is emitted if something unexpected happens but core functionality is expected to continue. - The
Info
event which contains additional neutral information.
Example
In the following code snippet, error, warning and info events from the player and source are logged to the console.
player.on<PlayerEvent.Error> { Log.e("Player Error", it.toString()) }
player.on<PlayerEvent.Warning> { Log.w("Player Warning", it.toString()) }
player.on<PlayerEvent.Info> { Log.i("Player Info", it.toString()) }
source.on<SourceEvent.Error> { Log.e("Source Error", it.toString()) }
source.on<SourceEvent.Warning> { Log.w("Source Warning", it.toString()) }
source.on<SourceEvent.Info> { Log.i("Source Info", it.toString()) }
The events also enable more complex logging scenario such as e.g. logging only failed downloads:
source.on<SourceEvent.DownloadFinished> {
if (!it.isSuccess){
Log.e(
"Download Error",
"Unable to download ${it.url}, response code was ${it.httpStatus} after ${it.downloadTime} seconds."
)
}
}
A more in-depth logging implementation can be found in the sample projects.
Exhaustive debug logs
In order to enable exhaustive debug log with a single configuration, use the following line of code before the first interaction with the Bitmovin Android Player SDK:
import com.bitmovin.player.api.DebugConfig
...
DebugConfig.isLoggingEnabled = true
import com.bitmovin.player.api.DebugConfig;
...
DebugConfig.setLoggingEnabled(true);
Updated 27 days ago