Skip to main content

ExoPlayer

ExoPlayer is the native video player for Android, created and maintained by Google until version 2.19.1.

note

The ExoPlayer package "com.google.android.exoplayer" is now deprecated and will not be updated by Google anymore. The QUANTEEC plugin documentation on this page is only for the previous versions of ExoPlayer and not the new one contained in the package "androidx.media3:media3-exoplayer." A version of QUANTEEC plugin for media3-exoplayer is under development and will come out shortly.

Compatibility with ExoPlayer and QUANTEEC plugin

The QUANTEEC plugin has been tested for version 2.11.0 until version 2.19.1 of ExoPlayer. For each major version of ExoPlayer (2.18.X, 2.17.X ...) you must used the corresponding version of the QUANTEEC Exoplayer adapter.

Exoplayer VersionQUANTEEC Exoplayer Adapter to use
2.11.Xcom.quanteec:quanteecExoPlugin2_11:1.4.1
2.12.Xcom.quanteec:quanteecExoPlugin2_12:1.4.1
2.13.Xcom.quanteec:quanteecExoPlugin2_13:1.4.1
2.14.Xcom.quanteec:quanteecExoPlugin2_14:1.4.1
2.15.Xcom.quanteec:quanteecExoPlugin2_15:1.4.1
2.16.Xcom.quanteec:quanteecExoPlugin2_16:1.4.1
2.17.Xcom.quanteec:quanteecExoPlugin2_17:1.4.1
2.18.Xcom.quanteec:quanteecExoPlugin:1.4.1
2.19.Xcom.quanteec:quanteecExoPlugin:1.4.1

Add QUANTEEC plugin as a dependency

Add QUANTEEC plugin modules

The easiest way to get started using QUANTEEC plugin with ExoPlayer is to add Gradle dependencies to the libraries you need.

First, you need to declare the QUANTEEC Maven repository with your credentials. This declaration must be made in your settings.gradle file or build.gradle file, depending on the configuration of your project.

repositories {
...
maven {
url 'https://maven.quanteec.com/repository/internal/'
credentials {
username "username"
password "password"
}
authentication {
basic(BasicAuthentication)
}
}
}
info

To obtain your credentials for QUANTEEC Maven repository, please contact us by mail.

Then, you can add the dependencies in your build.gradle file of your app module:

repositories {
dependencies {
...
implementation "com.quanteec:quanteecExoPlugin:1.4.1"
implementation "com.quanteec:quanteecPlugin:1.4.1"
}

}

Where 1.4.1 is your preferred version. All the modules must have the same version. The com.quanteec:quanteecExoPlugin library can be changed according to your Exoplayer version as explained above

Setting up the permissions

In order to function correctly, QUANTEEC plugin needs to have access to the network state of the Android devices. The network state is used to determine the type of network your device uses (mobile, wi-fi, or Ethernet) and adapt the behavior of the plugin to download segments.

Add the following permissions in the AndroidManifest.xml of your app module:

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />

Create the QUANTEEC elements

Create the QUANTEEC Core

You can create a QuanteecExoCore instance first by creating a QuanteecConfig instance, which will describe the initial configuration of the QUANTEEC plugin. Next, you can create a QuanteecExoCore instance using the QuanteecConfig you created as one of its parameters. The following code is the simplest example of creating an instance:

val quanteecConfig = QuanteecConfig.Builder("<your-quanteec-key>").setVideoID("<enter-your-custom-videoID>").build();
val quanteecCore = QuanteecExoCore(context, quanteecConfig);
note

The creation of a QuanteecConfig instance with a Builder is only available for versions 1.3.0 and later. For older versions you must use a constructor :

val quanteecConfig = QuanteecConfig("<enter-your-custom-videoID>", "<your-quanteec-key>");
val quanteecCore = QuanteecExoCore(context, quanteecConfig);
warning

In your QUANTEEC configuration, remember to set a different videoID if you have different formats of the same stream (e.g., one DASH stream and one HLS stream) or two variants of the same stream (one stream with English audio and one stream with another language).

Click here to find more informations on videoID

Create the QUANTEEC Datasource Factory

The QUANTEEC Datasource will receive requests from the ExoPlayer instance and will forward them to the quanteecCore created, which in turn will download the requested data. A QUANTEEC data source factory instance will allow Exoplayer to create QUANTEEC Datasource instances to download the data it needs. The following code is the simplest example of creating a QUANTEEC Datasource Factory instance:

val quanteecDataSourceFactory = QuanteecBaseDataSource.Factory(quanteecCore);

Create the QUANTEEC Bandwidth meters

In order to avoid the users' quality changing frequently due to the way the data is downloaded through QUANTEEC (from CDN or P2P), we slightly change the way the bandwidth of the user is calculated when using QUANTEEC through a custom BandwidthMeter called QuanteecBandwidthMeters. The following code is the simplest example of creating a QuanteecBandwidthMeters instance:

val quanteecBandwidthMeters = QuanteecBandwidthMeters.Builder(context).build();

Attach the QUANTEEC elements to ExoPlayer

To be functional, the QuanteecCore and the QuanteecBandwidthMeters created must be attached to an ExoPlayer instance during its creation. The following code shows an example of how to attach QUANTEEC elements to an ExoPlayer instance:

val mExoPlayer = remember(mContext) {
ExoPlayer.Builder(mContext).setMediaSourceFactory(DefaultMediaSourceFactory(mContext).setDataSourceFactory(quanteecDataSourceFactory)
).setBandwidthMeter(quanteecBandwidthMeters
).build().apply {
val mediaItem = MediaItem.Builder(
).setUri(Uri.parse("your-video-url")
).build()

setMediaItem(mediaItem)

playWhenReady = true
}
}

Register ExoPlayer instance inside QUANTEEC Core

Once created, the player instance must be registered inside the QUANTEEC core. The following code shows how to register an ExoPlayer instance inside a QUANTEEC Core:

quanteecCore.setPlayer(mExoPlayer);
tip

Good practice: try-catch block

One good practice is to encapsulate the instantiation of the QUANTEEC object within a try-catch block. This approach provides a robust mechanism for handling situations where QUANTEEC might not be available or may encounter compatibility issues.

Error handling

Embedding QUANTEEC in an Android app involves configuring and initializing the QUANTEEC plugin instance. If any issues arise during this process, such as missing dependencies or runtime errors, a try-catch block allows you to catch and handle these errors gracefully.

Unusual environments

Android devices and versions vary, and not all devices may support certain features or configurations of QUANTEEC. Wrapping the QUANTEEC initialization in a try-catch block allows you to account for scenarios where certain features might not be available on the user's device or where there are compatibility issues with the Android version.

QUANTEEC plugin and Android activity lifecycle

In order to manage efficiently the ressources used by the QUANTEEC plugin, it's important to take into account the activity lifecycle during the development of your application.

note

Releasing the ressources used by the Android plugin are not mandatory. But, if the application goes into background without doing it, the plugin will always be connected to others peer and will be able to send them data. This will happen even if you release the Exoplayer instance or stop the playback.

When you're application goes into background you have to possibiliy to free the ressources used by QUANTEEC. The first one is to totally release the QUANTEEC plugin by using this code for example :

quanteecCore?.release();
quanteecCore = null;

In this case when your application come back in the foreground you'll have to recreate a new QUANTEEC plugin instance and link it to the player.

The second possibility is just to deactivate the plugin by using the function quanteecCore.activateQuanteec(false). This function will totally deactivate the use of QUANTEEC plugin. To activate it again all you have to do is to called quanteecCore.activateQuanteec(true) when the application came back in the foreground. With this method, the reactivation of the QUANTEEC plugin will be faster. However some ressources, especially store in memory will not be free with such method.