Skip to content

Commit 13f2ac1

Browse files
Merge pull request #32 from newrelic/develop
feat: Changing Event Type from MobileVideo to VideoAction
2 parents cdc0de8 + 878cada commit 13f2ac1

File tree

10 files changed

+94
-32
lines changed

10 files changed

+94
-32
lines changed

NRExoPlayerTracker/build.gradle

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ android {
99
defaultConfig {
1010
minSdkVersion 16
1111
targetSdkVersion 33
12-
versionCode 5
13-
versionName "2.0.0"
14-
12+
versionCode 6
13+
versionName "3.0.0"
1514
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1615
consumerProguardFiles "consumer-rules.pro"
1716
}
@@ -59,4 +58,5 @@ afterEvaluate {
5958
}
6059
}
6160
}
61+
6262
}

NRExoPlayerTracker/src/main/java/com/newrelic/videoagent/exoplayer/tracker/NRTrackerExoPlayer.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,7 @@ public void sendDroppedFrame(int count, int elapsed) {
364364
Map<String, Object> attr = new HashMap<>();
365365
attr.put("lostFrames", count);
366366
attr.put("lostFramesDuration", elapsed);
367-
generatePlayElapsedTime();
367+
// generatePlayElapsedTime();
368368
if (getState().isAd) {
369369
sendVideoAdEvent("AD_DROPPED_FRAMES", attr);
370370
}

NRIMATracker/build.gradle

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ android {
99
defaultConfig {
1010
minSdkVersion 16
1111
targetSdkVersion 33
12-
versionCode 5
13-
versionName "2.0.0"
14-
12+
versionCode 6
13+
versionName "3.0.0"
1514
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1615
consumerProguardFiles "consumer-rules.pro"
1716
}

NewRelicVideoCore/build.gradle

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,13 @@ plugins {
22
id 'com.android.library'
33
id 'maven-publish'
44
}
5-
65
android {
76
compileSdkVersion 33
8-
97
defaultConfig {
108
minSdkVersion 16
119
targetSdkVersion 33
12-
versionCode 8
13-
versionName "2.0.0"
10+
versionCode 9
11+
versionName "3.0.0"
1412

1513
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1614
consumerProguardFiles "consumer-rules.pro"
@@ -38,15 +36,13 @@ android {
3836
}
3937

4038
dependencies {
41-
4239
implementation 'androidx.appcompat:appcompat:1.1.0'
4340
implementation 'com.google.android.material:material:1.1.0'
4441
implementation 'com.newrelic.agent.android:android-agent:7.0.0'
4542
testImplementation 'junit:junit:4.+'
4643
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
4744
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
4845
}
49-
5046
afterEvaluate {
5147
publishing {
5248
publications {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.newrelic.videoagent.core.model;
2+
3+
public class NRChrono {
4+
5+
private long startTime;
6+
7+
// Constructor
8+
public NRChrono() {
9+
startTime = 0;
10+
}
11+
12+
// Start the timer
13+
public void start() {
14+
startTime = System.currentTimeMillis();
15+
}
16+
17+
// Get the delta time in milliseconds
18+
public long getDeltaTime() {
19+
if (startTime > 0) {
20+
return System.currentTimeMillis() - startTime;
21+
} else {
22+
return 0;
23+
}
24+
}
25+
}

NewRelicVideoCore/src/main/java/com/newrelic/videoagent/core/model/NRTimeSinceTable.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public void applyAttributes(String action, Map<String, Object> attributes) {
5050
attributes.put(ts.getAttribute(), ts.timeSince());
5151
}
5252
if (ts.isAction(action)) {
53-
attributes.put("elapsedTime", ts.timeSince());
53+
// attributes.put("elapsedTime", ts.timeSince());
5454
ts.now();
5555
}
5656
}

NewRelicVideoCore/src/main/java/com/newrelic/videoagent/core/tracker/NRVideoTracker.java

Lines changed: 43 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.newrelic.videoagent.core.tracker;
22

33
import android.os.Handler;
4+
5+
import com.newrelic.videoagent.core.model.NRChrono;
46
import com.newrelic.videoagent.core.model.NRTimeSince;
57
import com.newrelic.videoagent.core.model.NRTrackerState;
68
import com.newrelic.videoagent.core.utils.NRLog;
@@ -38,6 +40,8 @@ public class NRVideoTracker extends NRTracker {
3840
private Long playtimeSinceLastEvent;
3941
private String bufferType;
4042
private NRTimeSince lastAdTimeSince;
43+
private Long acc;
44+
private NRChrono chrono;
4145

4246
/**
4347
* Create a new NRVideoTracker.
@@ -67,6 +71,8 @@ public void run() {
6771
}
6872
}
6973
};
74+
acc = 0L;
75+
chrono = new NRChrono();
7076
}
7177

7278
/**
@@ -159,7 +165,7 @@ public Map<String, Object> getAttributes(String action, Map<String, Object> attr
159165
Map<String, Object> attr;
160166

161167
if (attributes != null) {
162-
attr = attributes;
168+
attr = new HashMap<>(attributes);
163169
} else {
164170
attr = new HashMap<>();
165171
}
@@ -178,7 +184,7 @@ public Map<String, Object> getAttributes(String action, Map<String, Object> attr
178184
attr.put("numberOfAds", numberOfAds);
179185
attr.put("numberOfVideos", numberOfVideos);
180186
attr.put("numberOfErrors", numberOfErrors);
181-
attr.put("elapsedTime", playtimeSinceLastEvent);
187+
// attr.put("elapsedTime", playtimeSinceLastEvent);
182188
attr.put("totalPlaytime", totalPlaytime);
183189

184190
if (state.isAd) {
@@ -232,9 +238,7 @@ public Map<String, Object> getAttributes(String action, Map<String, Object> attr
232238
attr.put("contentId", getVideoId());
233239
attr.put("contentIsLive", getIsLive());
234240
}
235-
236241
attr = super.getAttributes(action, attr);
237-
238242
return attr;
239243
}
240244

@@ -269,7 +273,11 @@ public void sendRequest() {
269273
public void sendStart() {
270274
if (state.goStart()) {
271275
startHeartbeat();
276+
chrono.start();
272277
if (state.isAd) {
278+
if(!state.isBuffering){
279+
acc += chrono.getDeltaTime();
280+
}
273281
numberOfAds++;
274282
if (linkedTracker instanceof NRVideoTracker) {
275283
((NRVideoTracker) linkedTracker).setNumberOfAds(numberOfAds);
@@ -291,6 +299,9 @@ public void sendStart() {
291299
*/
292300
public void sendPause() {
293301
if (state.goPause()) {
302+
if(!state.isBuffering){
303+
acc += chrono.getDeltaTime();
304+
}
294305
if (state.isAd) {
295306
sendVideoAdEvent(AD_PAUSE);
296307
} else {
@@ -305,6 +316,9 @@ public void sendPause() {
305316
*/
306317
public void sendResume() {
307318
if (state.goResume()) {
319+
if(!state.isBuffering){
320+
chrono.start();
321+
}
308322
if (state.isAd) {
309323
sendVideoAdEvent(AD_RESUME);
310324
} else {
@@ -376,6 +390,9 @@ public void sendSeekEnd() {
376390
*/
377391
public void sendBufferStart() {
378392
if (state.goBufferStart()) {
393+
if(state.isPlaying){
394+
acc += chrono.getDeltaTime();
395+
}
379396
bufferType = calculateBufferType();
380397
if (state.isAd) {
381398
sendVideoAdEvent(AD_BUFFER_START);
@@ -391,6 +408,9 @@ public void sendBufferStart() {
391408
*/
392409
public void sendBufferEnd() {
393410
if (state.goBufferEnd()) {
411+
if(state.isPlaying){
412+
chrono.start();
413+
}
394414
if (bufferType == null) {
395415
bufferType = calculateBufferType();
396416
}
@@ -410,11 +430,27 @@ public void sendBufferEnd() {
410430
* Send heartbeat event.
411431
*/
412432
public void sendHeartbeat() {
433+
Long _elpasedTime = 0L;
434+
if(this.acc > 0){
435+
_elpasedTime += this.acc;
436+
this.acc = 0L;
437+
}
438+
if(state.isPlaying){
439+
_elpasedTime += chrono.getDeltaTime();
440+
}
441+
chrono.start();
442+
443+
Long minimumElapsedTime = 30000L;
444+
_elpasedTime = Math.min(minimumElapsedTime, _elpasedTime);
445+
446+
Map<String, Object> attributes = new HashMap<>();
447+
attributes.put("elapsedTime", _elpasedTime);
413448
if (state.isAd) {
414449
sendVideoAdEvent(AD_HEARTBEAT);
415450
} else {
416-
sendVideoEvent(CONTENT_HEARTBEAT);
451+
sendVideoEvent(CONTENT_HEARTBEAT, attributes);
417452
}
453+
418454
}
419455

420456
/**
@@ -462,7 +498,7 @@ public void sendError(String errorMessage) {
462498
numberOfErrors++;
463499
Map<String, Object> errAttr = new HashMap<>();
464500
errAttr.put("errorName", errorMessage);
465-
generatePlayElapsedTime();
501+
// generatePlayElapsedTime();
466502
String actionName = CONTENT_ERROR;
467503
if (state.isAd) {
468504
actionName = AD_ERROR;
@@ -877,4 +913,4 @@ private String calculateBufferType() {
877913
// If none of the above is true, it is a connection buffering
878914
return "connection";
879915
}
880-
}
916+
}

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
[![Experimental Project header](https://github.com/newrelic/opensource-website/raw/master/src/images/categories/Experimental.png)](https://opensource.newrelic.com/oss-category/#experimental)
1+
[![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)
22

33
# New Relic Video Agent for Android
44

app/src/main/java/com/newrelic/nrvideoproject/VideoPlayer.java

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,15 @@
44
import androidx.media3.common.MediaItem;
55
import androidx.media3.exoplayer.ExoPlayer;
66
import androidx.media3.ui.PlayerView;
7-
7+
import android.net.Uri;
88
import android.os.Bundle;
99
import android.util.Log;
1010
import com.newrelic.videoagent.core.NewRelicVideoAgent;
1111
import com.newrelic.videoagent.core.tracker.NRVideoTracker;
1212
import com.newrelic.videoagent.exoplayer.tracker.NRTrackerExoPlayer;
13-
13+
import java.util.ArrayList;
1414
import java.util.HashMap;
15+
import java.util.List;
1516
import java.util.Map;
1617

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

2930
if (video.equals("Tears")) {
3031
Log.v("VideoPlayer", "Play Tears");
31-
playVideo("http://www.bok.net/dash/tears_of_steel/cleartext/stream.mpd");
32+
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
3233
}
3334
else if (video.equals("Playhouse")) {
3435
Log.v("VideoPlayer", "Play Playhouse");
35-
playVideo("https://bitmovin-a.akamaihd.net/content/playhouse-vr/mpds/105560.mpd");
36+
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
3637
}
3738
else if (video.equals("Kite")) {
3839
Log.v("VideoPlayer", "Play Kite");
39-
playVideo("https://demos.transloadit.com/dashtest/my_playlist.mpd");
40+
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
4041
}
4142
else if (video.equals("Live")) {
4243
Log.v("VideoPlayer", "Play Live");
43-
playVideo("https://livesim.dashif.org/livesim/testpic_2s/Manifest.mpd");
44+
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
4445
}
4546
else {
4647
Log.v("VideoPlayer","Unknown video");
@@ -80,6 +81,11 @@ private void playVideo(String videoUrl) {
8081

8182
tracker.setPlayer(player);
8283

84+
// Set the playlist URIs
85+
List<Uri> uris = new ArrayList<>();
86+
uris.add(Uri.parse(videoUrl));
87+
tracker.setSrc(uris);
88+
8389
player.setMediaItem(MediaItem.fromUri(videoUrl));
8490
// Prepare the player.
8591
player.setPlayWhenReady(true);

app/src/main/java/com/newrelic/nrvideoproject/VideoPlayerAds.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,19 @@ protected void onCreate(Bundle savedInstanceState) {
3838

3939
if (video.equals("Tears")) {
4040
Log.v("VideoPlayer", "Play Tears");
41-
playVideo("http://www.bok.net/dash/tears_of_steel/cleartext/stream.mpd");
41+
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
4242
}
4343
else if (video.equals("Playhouse")) {
4444
Log.v("VideoPlayer", "Play Playhouse");
45-
playVideo("https://bitmovin-a.akamaihd.net/content/playhouse-vr/mpds/105560.mpd");
45+
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
4646
}
4747
else if (video.equals("Kite")) {
4848
Log.v("VideoPlayer", "Play Kite");
49-
playVideo("https://demos.transloadit.com/dashtest/my_playlist.mpd");
49+
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
5050
}
5151
else if (video.equals("Live")) {
5252
Log.v("VideoPlayer", "Play Live");
53-
playVideo("https://livesim.dashif.org/livesim/testpic_2s/Manifest.mpd");
53+
playVideo("https://turtle-tube.appspot.com/t/t2/dash.mpd");
5454
}
5555
else {
5656
Log.v("VideoPlayer","Unknown video");

0 commit comments

Comments
 (0)