Video Agent Library for Android
The New Relic Video Agent for Android contains multiple modules necessary to instrument video players and send data to New Relic.
There are three modules available:
Contains all the base classes necessary to create trackers and send data to New Relic. It depends on the New Relic Agent.
The video tracker for ExoPlayer2 player. It depends on NewRelicVideoCore.
The video tracker for Google IMA Ads library. It depends on NewRelicVideoCore.
Install the New Relic Android Agent, and any other needed dependency, like ExoPlayer or Google IMA.
Add the following line inside your root build.gradle:
allprojects {
repositories {
...
// Add this line at the end of your repositories
maven { url 'https://jitpack.io' }
}
}
And inside your app’s build.gradle, add the following dependencies:
dependencies {
...
// Add this to install the NewRelicVideoCore (required)
implementation 'com.github.newrelic.video-agent-android:NewRelicVideoCore:v4.0.0'
// Add this to install the ExoPlayer tracker
implementation 'com.github.newrelic.video-agent-android:NRExoPlayerTracker:v4.0.0'
// Add this to install the Google IMA library tracker
implementation 'com.github.newrelic.video-agent-android:NRIMATracker:v4.0.0'
}
To install an specific version, replace the master-SNAPSHOT
by a version tag.
dependencies {
...
implementation project(":NewRelicVideoCore")
implementation project(":NRExoPlayerTracker")
implementation project(':NRIMATracker')
}
dependencies {
...
implementation project(":NewRelicVideoCore")
implementation project(":NRExoPlayerTracker")
implementation project(':NRIMATracker')
}
To start the video agent with ExoPlayer tracker only:
Java
// Step 1: Initialize the NRVideo at main activity. i.e MainActivity.java
NRVideoConfiguration config = new NRVideoConfiguration.Builder("application-token")
.autoDetectPlatform(getApplicationContext())
.withHarvestCycle(5*60) //This is in seconds, for ondemand video, please use minimum 5 minutes
.build();
NRVideo.newBuilder(getApplicationContext()).withConfiguration(config).build();
//Step 2: Initialize the player(it could have n number of players in your application). i.e VideoPlayer.java
player = new ExoPlayer.Builder(this).build();
NRVideoPlayerConfiguration playerConfiguration = new NRVideoPlayerConfiguration("test-player", player, true, customAttr);
Integer trackerId = NRVideo.addPlayer(playerConfiguration);
Integer trackerId = NewRelicVideoAgent.getInstance().start(new NRTrackerExoPlayer(player));
// Step 4(Optional): Destroy the player on your player activity close. i.e VideoPlayer.java
// New Relic auto detects the player close, but its advisable to release tracker for a better control.
@Override
void onDestroy() {
NRVideo.releaseTracker(trackerId);
player.stop();
}
To start the video agent with ExoPlayer and IMA trackers:
Java
//Step 2: Initialize the player(it could have n number of players in your application). i.e VideoPlayer.java
//... more details on configuring the ads loader
player = new SimpleExoPlayer.Builder(this).setMediaSourceFactory(mediaSourceFactory).build();
NRVideoPlayerConfiguration playerConfiguration = new NRVideoPlayerConfiguration("test-player-something-else", player, true, null);
Integer trackerId = NRVideo.addPlayer(playerConfiguration);
// Get the ads tracker
adTracker = (NRTrackerIMA) NewRelicVideoAgent.getInstance().getAdTracker(trackerId);
//While building ads loader pass the listeners
ImaAdsLoader.Builder builder = new ImaAdsLoader.Builder(this);
builder.setAdErrorListener(adTracker.getAdErrorListener());
builder.setAdEventListener(adTracker.getAdEventListener());
NRVideoConfiguration.java
applicationToken
Unique identifier for your application. Used for authentication and region detection. Must be a non-empty string.
harvestCycleSeconds
Interval (in seconds) between regular data harvests. Controls how often data is sent to the New Relic. Typical values range from 300 to 600 seconds.
liveHarvestCycleSeconds
Interval (in seconds) for live stream data harvests. Used for real-time or near-real-time data transmission. Valid range is 30 to 60 seconds.
NRVideoPlayerConfiguration.java
playerName
player
Player
interface from ExoPlayer.isAdEnabled
true
for player having ads loader capability else false
.To generate the javadocs, open the project in Android Studio and then go to Tools > Generate JavaDoc...
, select Whole Project
, then select the Output directory
and click OK
.
For more detail on the Events and Data Model generated by Video Agent for Android and for advanced concepts such as creating custom trackers, reference the Advanced Topics manual.
The app
folder contains a usage example that shows the basics of video tracking using ExoPlayer.
The Test
folder contains the test apps.
New Relic has open-sourced this project. This project is provided AS-IS WITHOUT WARRANTY OR DEDICATED SUPPORT. Issues and contributions should be reported to the project here on GitHub.
We encourage you to bring your experiences and questions to the Explorers Hub where our community members collaborate on solutions and new ideas.
We encourage your contributions to improve New Relic Video Agent! Keep in mind when you submit your pull request, you’ll need to sign the CLA via the click-through using CLA-Assistant. You only have to sign the CLA one time per project. If you have any questions, or to execute our corporate CLA, required if your contribution is on behalf of a company, please drop us an email at opensource@newrelic.com.
A note about vulnerabilities
As noted in our security policy, New Relic is committed to the privacy and security of our customers and their data. We believe that providing coordinated disclosure by security researchers and engaging with the security community are important means to achieve our security goals.
If you believe you have found a security vulnerability in this project or any of New Relic’s products or websites, we welcome and greatly appreciate you reporting it to New Relic through HackerOne.
New Relic Video Agent is licensed under the Apache 2.0 License.