
Developers
Android SDK
Developers
Android SDK
This article will guide you through on how to create your first player instance.
There are two ways to add a player to an Activity.
FlowplayerView
FlowplayerSupportFragment
or FlowplayerFragment
.The second option is the recommended way since these two Fragments wrap FlowplayerView
and handle its lifecycle automatically for you.
Optionally, both these Fragments can also handle orientation changes and toggle fullscreen.
The FlowplayerView
is the core of the Flowplayer Android SDK. It allows to load a video/audio, control the playback, and subscribe to player related callbacks.
It extends FrameLayout
and can therefore be added either via xml or programmatically in an ordinary fashion:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.flowplayer.android.player.FlowplayerView
android:id="@+id/player_view"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
Adding FlowplayerView
gives you more control over its lifecycle.
However, if you do not need this control then we recommend using either FlowplayerFragment
or FlowplayerSupportFragment
instead.
If you decide to use FlowplayerView
instead of FlowplayerFragment
or FlowplayerSupportFragment
, then you need to take care of its lifecycle. There are two ways to achieve this:
FragmentAcitivy
or Fragment
and register lifecyle listeners.If your Activity or Fragment inherits (directly or indirectly) from AndroidX's FragmentActivity or Fragment, respectively, then it implements LifecycleOwner
.
In this case, you can simply register your Activity's or Fragment's lifecycle by adding the following line in its onCreate()
method:
FlowplayerLifecycleObserver.registerLifecycle(lifecycle)
If your Activity or Fragment does not implement LifecycleOwner
, then you need to call the FlowplayerView
's lifecycle methods manually by putting the following code inside the parent Activity or Fragment:
override fun onStart() {
super.onStart()
flowplayerView.onStart()
}
override fun onResume() {
super.onResume()
flowplayerView.onResume()
}
override fun onPause() {
flowplayerView.onPause()
super.onPause()
}
override fun onStop() {
flowplayerView.onStop()
super.onStop()
}
override fun onDestroy() {
flowplayerView.onDestroy()
super.onDestroy()
}
Whether to use FlowplayerSupportFragment
or FlowplayerFragment
depends on whether or not your Activity inherits (directly or indirectly) from AndroidX's FragmentActivity.
Both FlowplayerFragment
and FlowplayerSupportFragment
can be added in the same way as any other Fragment, either via xml:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<fragment
android:id="@+id/player_fragment"
class="com.flowplayer.android.player.FlowplayerFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</RelativeLayout>
or programmatically:
val playerFragment = FlowplayerFragment.newInstance()
fragmentManager.beginTransaction()
.replace(R.id.player_holder, playerFragment)
.commit()
You can then get the instance of the FlowplayerView
by calling:
playerFragment.getPlayer()
playerFragment.getPlayer()
you first need to call fragmentManager.executePendingTransactions()
.
That's because the .commit()
that you called earlier, will commit the transaction asynchronously.FlowplayerView
can play media either by fetching a so-called Flowplayer config or directly from a media URL that you specify.
In the first scenario, the player needs to be prepared with a Flowplayer mediaId
and a playerId
.
This is achieved by preparing the player with a FlowplayerMedia
instance, similar to the example below.
The player will then fetch the Flowplayer config which contains the media URL, the ad schedule (if any), and branding-related information.
val flowplayerVideo = FlowplayerMedia("some-media-id", "some-player-id")
flowplayerView.prepare(flowplayerVideo, true)
In a similar way, the player can be prepared with a local or remote media URL.
This is possible by preparing the player with an ExternalMedia
instance as shown below.
An ExternalMedia
may optionally contain an ad schedule, as well. For more information about ads, see section Advertising.
val externalVideo = ExternalMedia("https://link.to.a.media.file")
flowplayerView.prepare(externalVideo, true)
If you prepare the player using a FlowplayerMedia
and the media that
is defined in the Flowplayer config is DRM-protected, then the player
will automatically take care of the DRM.
If, however, you wish to prepare the player with an ExternalMedia
that
has DRM-protected content, then you should provide a DrmConfig
when
you initialize your media instance:
val drmConfig = DrmConfig(DrmConfig.Scheme.WIDEVINE, "https://link.to.a.drm.license")
val externalMedia = ExternalMedia("https://link.to.a.media.file", drmConfig)
flowplayerView.prepare(externalMedia, true)
The Flowplayer Android SDK is based on ExoPlayer
which in turn uses
Android's MediaDrm
API to support DRM-protected playbacks. The minimum
Android versions required for different supported DRM schemes, along
with the streaming formats for which they're supported, are listed
below.
DRM scheme | Android version number | Android API level | Supported formats |
---|---|---|---|
Widevine "cenc" | 4.4 | 19 | DASH, HLS (FMP4 only) |
Widevine "cbcs", "cbc1" and "cens" | 7.1 | 25 | DASH, HLS (FMP4 only) |
ClearKey | 5.0 | 21 | DASH |
PlayReady SL2000 | AndroidTV | AndroidTV | DASH, SmoothStreaming, HLS (FMP4 only) |
Live streaming
Live analytics
Ad scheduling
Monetization