Skip to content
Merged
6 changes: 3 additions & 3 deletions NRExoPlayerTracker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 33
versionCode 5
versionName "2.0.0"

versionCode 6
versionName "3.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
Expand Down Expand Up @@ -59,4 +58,5 @@ afterEvaluate {
}
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,7 @@ public void sendDroppedFrame(int count, int elapsed) {
Map<String, Object> attr = new HashMap<>();
attr.put("lostFrames", count);
attr.put("lostFramesDuration", elapsed);
generatePlayElapsedTime();
// generatePlayElapsedTime();
if (getState().isAd) {
sendVideoAdEvent("AD_DROPPED_FRAMES", attr);
}
Expand Down
5 changes: 2 additions & 3 deletions NRIMATracker/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@ android {
defaultConfig {
minSdkVersion 16
targetSdkVersion 33
versionCode 5
versionName "2.0.0"

versionCode 6
versionName "3.0.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
}
Expand Down
8 changes: 2 additions & 6 deletions NewRelicVideoCore/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,13 @@ plugins {
id 'com.android.library'
id 'maven-publish'
}

android {
compileSdkVersion 33

defaultConfig {
minSdkVersion 16
targetSdkVersion 33
versionCode 8
versionName "2.0.0"
versionCode 9
versionName "3.0.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
consumerProguardFiles "consumer-rules.pro"
Expand Down Expand Up @@ -38,15 +36,13 @@ android {
}

dependencies {

implementation 'androidx.appcompat:appcompat:1.1.0'
implementation 'com.google.android.material:material:1.1.0'
implementation 'com.newrelic.agent.android:android-agent:7.0.0'
testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
}

afterEvaluate {
publishing {
publications {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.newrelic.videoagent.core.model;

public class NRChrono {

private long startTime;

// Constructor
public NRChrono() {
startTime = 0;
}

// Start the timer
public void start() {
startTime = System.currentTimeMillis();
}

// Get the delta time in milliseconds
public long getDeltaTime() {
if (startTime > 0) {
return System.currentTimeMillis() - startTime;
} else {
return 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public void applyAttributes(String action, Map<String, Object> attributes) {
attributes.put(ts.getAttribute(), ts.timeSince());
}
if (ts.isAction(action)) {
attributes.put("elapsedTime", ts.timeSince());
// attributes.put("elapsedTime", ts.timeSince());
ts.now();
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.newrelic.videoagent.core.tracker;

import android.os.Handler;

import com.newrelic.videoagent.core.model.NRChrono;
import com.newrelic.videoagent.core.model.NRTimeSince;
import com.newrelic.videoagent.core.model.NRTrackerState;
import com.newrelic.videoagent.core.utils.NRLog;
Expand Down Expand Up @@ -38,6 +40,8 @@ public class NRVideoTracker extends NRTracker {
private Long playtimeSinceLastEvent;
private String bufferType;
private NRTimeSince lastAdTimeSince;
private Long acc;
private NRChrono chrono;

/**
* Create a new NRVideoTracker.
Expand Down Expand Up @@ -67,6 +71,8 @@ public void run() {
}
}
};
acc = 0L;
chrono = new NRChrono();
}

/**
Expand Down Expand Up @@ -159,7 +165,7 @@ public Map<String, Object> getAttributes(String action, Map<String, Object> attr
Map<String, Object> attr;

if (attributes != null) {
attr = attributes;
attr = new HashMap<>(attributes);
} else {
attr = new HashMap<>();
}
Expand All @@ -178,7 +184,7 @@ public Map<String, Object> getAttributes(String action, Map<String, Object> attr
attr.put("numberOfAds", numberOfAds);
attr.put("numberOfVideos", numberOfVideos);
attr.put("numberOfErrors", numberOfErrors);
attr.put("elapsedTime", playtimeSinceLastEvent);
// attr.put("elapsedTime", playtimeSinceLastEvent);
attr.put("totalPlaytime", totalPlaytime);

if (state.isAd) {
Expand Down Expand Up @@ -232,9 +238,7 @@ public Map<String, Object> getAttributes(String action, Map<String, Object> attr
attr.put("contentId", getVideoId());
attr.put("contentIsLive", getIsLive());
}

attr = super.getAttributes(action, attr);

return attr;
}

Expand Down Expand Up @@ -269,7 +273,11 @@ public void sendRequest() {
public void sendStart() {
if (state.goStart()) {
startHeartbeat();
chrono.start();
if (state.isAd) {
if(!state.isBuffering){
acc += chrono.getDeltaTime();
}
numberOfAds++;
if (linkedTracker instanceof NRVideoTracker) {
((NRVideoTracker) linkedTracker).setNumberOfAds(numberOfAds);
Expand All @@ -291,6 +299,9 @@ public void sendStart() {
*/
public void sendPause() {
if (state.goPause()) {
if(!state.isBuffering){
acc += chrono.getDeltaTime();
}
if (state.isAd) {
sendVideoAdEvent(AD_PAUSE);
} else {
Expand All @@ -305,6 +316,9 @@ public void sendPause() {
*/
public void sendResume() {
if (state.goResume()) {
if(!state.isBuffering){
chrono.start();
}
if (state.isAd) {
sendVideoAdEvent(AD_RESUME);
} else {
Expand Down Expand Up @@ -376,6 +390,9 @@ public void sendSeekEnd() {
*/
public void sendBufferStart() {
if (state.goBufferStart()) {
if(state.isPlaying){
acc += chrono.getDeltaTime();
}
bufferType = calculateBufferType();
if (state.isAd) {
sendVideoAdEvent(AD_BUFFER_START);
Expand All @@ -391,6 +408,9 @@ public void sendBufferStart() {
*/
public void sendBufferEnd() {
if (state.goBufferEnd()) {
if(state.isPlaying){
chrono.start();
}
if (bufferType == null) {
bufferType = calculateBufferType();
}
Expand All @@ -410,11 +430,27 @@ public void sendBufferEnd() {
* Send heartbeat event.
*/
public void sendHeartbeat() {
Long _elpasedTime = 0L;
if(this.acc > 0){
_elpasedTime += this.acc;
this.acc = 0L;
}
if(state.isPlaying){
_elpasedTime += chrono.getDeltaTime();
}
chrono.start();

Long minimumElapsedTime = 30000L;
_elpasedTime = Math.min(minimumElapsedTime, _elpasedTime);

Map<String, Object> attributes = new HashMap<>();
attributes.put("elapsedTime", _elpasedTime);
if (state.isAd) {
sendVideoAdEvent(AD_HEARTBEAT);
} else {
sendVideoEvent(CONTENT_HEARTBEAT);
sendVideoEvent(CONTENT_HEARTBEAT, attributes);
}

}

/**
Expand Down Expand Up @@ -462,7 +498,7 @@ public void sendError(String errorMessage) {
numberOfErrors++;
Map<String, Object> errAttr = new HashMap<>();
errAttr.put("errorName", errorMessage);
generatePlayElapsedTime();
// generatePlayElapsedTime();
String actionName = CONTENT_ERROR;
if (state.isAd) {
actionName = AD_ERROR;
Expand Down Expand Up @@ -877,4 +913,4 @@ private String calculateBufferType() {
// If none of the above is true, it is a connection buffering
return "connection";
}
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[![Experimental Project header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Experimental.png)](https://opensource.newrelic.com/oss-category/#experimental)
[![Community Project header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Community_Project.png)](https://opensource.newrelic.com/oss-category/#community-project)

# New Relic Video Agent for Android

Expand Down
18 changes: 12 additions & 6 deletions app/src/main/java/com/newrelic/nrvideoproject/VideoPlayer.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@
import androidx.media3.common.MediaItem;
import androidx.media3.exoplayer.ExoPlayer;
import androidx.media3.ui.PlayerView;

import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import com.newrelic.videoagent.core.NewRelicVideoAgent;
import com.newrelic.videoagent.core.tracker.NRVideoTracker;
import com.newrelic.videoagent.exoplayer.tracker.NRTrackerExoPlayer;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class VideoPlayer extends AppCompatActivity {
Expand All @@ -28,19 +29,19 @@ protected void onCreate(Bundle savedInstanceState) {

if (video.equals("Tears")) {
Log.v("VideoPlayer", "Play Tears");
playVideo("http://www.bok.net/dash/tears_of_steel/cleartext/stream.mpd");
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
}
else if (video.equals("Playhouse")) {
Log.v("VideoPlayer", "Play Playhouse");
playVideo("https://bitmovin-a.akamaihd.net/content/playhouse-vr/mpds/105560.mpd");
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
}
else if (video.equals("Kite")) {
Log.v("VideoPlayer", "Play Kite");
playVideo("https://demos.transloadit.com/dashtest/my_playlist.mpd");
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
}
else if (video.equals("Live")) {
Log.v("VideoPlayer", "Play Live");
playVideo("https://livesim.dashif.org/livesim/testpic_2s/Manifest.mpd");
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
}
else {
Log.v("VideoPlayer","Unknown video");
Expand Down Expand Up @@ -80,6 +81,11 @@ private void playVideo(String videoUrl) {

tracker.setPlayer(player);

// Set the playlist URIs
List<Uri> uris = new ArrayList<>();
uris.add(Uri.parse(videoUrl));
tracker.setSrc(uris);

player.setMediaItem(MediaItem.fromUri(videoUrl));
// Prepare the player.
player.setPlayWhenReady(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,19 @@ protected void onCreate(Bundle savedInstanceState) {

if (video.equals("Tears")) {
Log.v("VideoPlayer", "Play Tears");
playVideo("http://www.bok.net/dash/tears_of_steel/cleartext/stream.mpd");
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
}
else if (video.equals("Playhouse")) {
Log.v("VideoPlayer", "Play Playhouse");
playVideo("https://bitmovin-a.akamaihd.net/content/playhouse-vr/mpds/105560.mpd");
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
}
else if (video.equals("Kite")) {
Log.v("VideoPlayer", "Play Kite");
playVideo("https://demos.transloadit.com/dashtest/my_playlist.mpd");
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
}
else if (video.equals("Live")) {
Log.v("VideoPlayer", "Play Live");
playVideo("https://livesim.dashif.org/livesim/testpic_2s/Manifest.mpd");
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
}
else {
Log.v("VideoPlayer","Unknown video");
Expand Down
Loading