Skip to content

Commit

Permalink
Merge pull request #24 from bitmovin/feature/modules
Browse files Browse the repository at this point in the history
Feature/modules
  • Loading branch information
Tigraine committed Sep 18, 2018
2 parents 6e31fe9 + fb0531e commit 02856f0
Show file tree
Hide file tree
Showing 32 changed files with 2,844 additions and 308 deletions.
2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions .idea/modules.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

46 changes: 35 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,36 +18,60 @@ allprojects {

And this line to your main project `build.gradle`

For Bitmovin Player:

```
dependencies {
compile 'com.bitmovin.analytics:collector-bitmovin-player:1.4.0'
}
```

For ExoPlayer:

```
dependencies {
compile 'com.bitmovin.analytics:collector:1.3.8'
compile 'com.bitmovin.analytics:collector-exoplayer:1.4.0'
}
```


## Examples

The following example creates a BitmovinAnalytics object and attaches an Bitmovin Native SDK or ExoPlayer instance to it.
The following example creates a BitmovinAnalytics object and attaches an Bitmovin Native SDK instance to it.

#### Basic analytics monitoring
#### Basic analytics monitoring with Bitmovin Player SDK
```java
// Create a BitmovinAnalyticsConfig using your Bitmovin analytics license key and (optionally) your Bitmovin Player Key
BitmovinAnalyticsConfig bitmovinAnalyticsConfig = new BitmovinAnalyticsConfig("<BITMOVIN_ANALYTICS_KEY>", "<BITMOVIN_PLAYER_KEY>", getApplicationContext());

//Bitmovin Native:
BitmovinAnalyticsConfig bitmovinAnalyticsConfig = new BitmovinAnalyticsConfig("<BITMOVIN_ANALYTICS_KEY>", "<BITMOVIN_PLAYER_KEY>", getApplicationContext());

//ExoPlayer monitoring:
BitmovinAnalyticsConfig bitmovinAnalyticsConfig = new BitmovinAnalyticsConfig("<BITMOVIN_ANALYTICS_KEY>", getApplicationContext());

// Create a BitmovinAnalytics object using the BitmovinAnalyitcsConfig you just created
BitmovinAnalytics analyticsCollector = new BitmovinAnalytics(bitmovinAnalyticsConfig);
// Create a BitmovinPlayerCollector object using the BitmovinAnalyitcsConfig you just created
BitmovinAnalytics analyticsCollector = new BitmovinPlayerCollector(bitmovinAnalyticsConfig);

// Attach your player instance
analyticsCollector.attachPlayer(player);

// Detach your player when you are done. For example, call this method when you call the release() method
analyticsCollector.detachPlayer();
```

#### Basic analytics monitoring with ExoPlayer
```java
// Create a BitmovinAnalyticsConfig using your Bitmovin analytics license key
BitmovinAnalyticsConfig bitmovinAnalyticsConfig = new BitmovinAnalyticsConfig("<BITMOVIN_ANALYTICS_KEY>", getApplicationContext());

Create Analytics Collector for ExoPlayer
ExoPlayerCollector bitmovinAnalytics = new ExoPlayerCollector(bitmovinAnalyticsConfig);

//Attach your ExoPlayer instance
bitmovinAnalytics.attachPlayer(player);

// Detach your player when you are done. For example, call this method when you call ExoPlayer's release() method
bitmovinAnalytics.detachPlayer();
analyticsCollector.detachPlayer();
```


#### Switching to a new video
When switching to a new video we recommend that you follow the sequence of events below.

Expand Down
4 changes: 3 additions & 1 deletion analyticsexample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ dependencies {

//Compile from source
compile project(path: ':collector')
compile project(path: ':collector-exoplayer')
implementation 'com.google.android.exoplayer:exoplayer:2.8.+'

// Pull from Maven Repo
// compile 'com.bitmovin.analytics:collector:1.3.8'
// compile 'com.bitmovin.analytics:collector-exoplayer:1.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import android.view.View;
import android.widget.Button;

import com.bitmovin.analytics.analytics.BitmovinAnalytics;
import com.bitmovin.analytics.analytics.BitmovinAnalyticsConfig;
import com.bitmovin.analytics.exoplayer.ExoPlayerCollector;
import com.bitmovin.analytics.BitmovinAnalytics;
import com.bitmovin.analytics.BitmovinAnalyticsConfig;
import com.bitmovin.analytics.enums.CDNProvider;
import com.google.android.exoplayer2.DefaultLoadControl;
import com.google.android.exoplayer2.DefaultRenderersFactory;
Expand Down Expand Up @@ -91,11 +92,13 @@ private void createPlayer() {
bitmovinAnalyticsConfig.setHeartbeatInterval(59700);

//Step 3: Create Analytics Colelctor
bitmovinAnalytics = new BitmovinAnalytics(bitmovinAnalyticsConfig);
ExoPlayerCollector bitmovinAnalytics = new ExoPlayerCollector(
bitmovinAnalyticsConfig);

//Step 4: Attach ExoPlayer
bitmovinAnalytics.attachPlayer(player);


//Step 5: Create, prepeare, and play media source
playerView.setPlayer(player);

Expand Down
5 changes: 4 additions & 1 deletion bitmovinanalyticsexample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@ dependencies {
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

compile project(path: ':collector')
compile project(path: ':collector-bitmovin-player')
implementation 'com.bitmovin.player:playercore:2.13.0'

// compile 'com.bitmovin.analytics:collector:1.3.8'
// compile 'com.bitmovin.analytics:collector-bitmovin-player:1.4.0'

}

Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.bitmovin.bitmovinanalyticsexample;

import android.os.Bundle;
import android.os.Handler;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;

import com.bitmovin.analytics.analytics.BitmovinAnalytics;
import com.bitmovin.analytics.analytics.BitmovinAnalyticsConfig;
import com.bitmovin.analytics.BitmovinAnalyticsConfig;
import com.bitmovin.analytics.bitmovin.player.BitmovinPlayerCollector;
import com.bitmovin.analytics.enums.CDNProvider;
import com.bitmovin.player.BitmovinPlayer;
import com.bitmovin.player.BitmovinPlayerView;
Expand All @@ -17,7 +16,7 @@ public class MainActivity extends AppCompatActivity implements View.OnClickListe

private BitmovinPlayerView bitmovinPlayerView;
private BitmovinPlayer bitmovinPlayer;
private BitmovinAnalytics bitmovinAnalytics;
private BitmovinPlayerCollector bitmovinAnalytics;
private Button releaseButton;
private Button createButton;

Expand All @@ -40,7 +39,7 @@ protected void onCreate(Bundle savedInstanceState) {

}

protected void initializeAnalytics(){
protected void initializeAnalytics() {
//Step 1: Create your analytics config object
BitmovinAnalyticsConfig bitmovinAnalyticsConfig = new BitmovinAnalyticsConfig("<YOUR_ANALYTICS_KEY>", "<YOUR_PLAYER_KEY>", getApplicationContext());

Expand All @@ -58,7 +57,7 @@ protected void initializeAnalytics(){
bitmovinAnalyticsConfig.setHeartbeatInterval(59700);

//Step 3: Create Analytics Collector
bitmovinAnalytics = new BitmovinAnalytics(bitmovinAnalyticsConfig);
bitmovinAnalytics = new BitmovinPlayerCollector(bitmovinAnalyticsConfig);
}


Expand Down
1 change: 1 addition & 0 deletions collector-bitmovin-player/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build
92 changes: 92 additions & 0 deletions collector-bitmovin-player/build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
apply plugin: 'com.android.library'
apply plugin: 'com.jfrog.artifactory'
apply plugin: 'maven-publish'

def packageName = 'com.bitmovin.analytics-bitmovin-player'
def libraryVersion = '1.4.0'

android {

compileSdkVersion 27

defaultConfig {
minSdkVersion 16
targetSdkVersion 27
versionCode 13
versionName "1.4.0"

testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.android.support:appcompat-v7:27.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'

implementation project(path: ':collector')
implementation 'com.bitmovin.player:playercore:2.13.0'

}

publishing {
publications {
aar(MavenPublication) {
groupId packageName
version = libraryVersion
artifactId project.getName()

// Tell maven to prepare the generated "*.aar" file for publishing
artifact("$buildDir/outputs/aar/${project.getName()}-release.aar")

pom.withXml {
def dependenciesNode = asNode().appendNode('dependencies')

//Defining configuration names from which dependencies will be taken (debugCompile or releaseCompile and compile)
def configurationNames = ['compile']

configurationNames.each { configurationName ->
configurations[configurationName].allDependencies.each {
def dependencyNode = dependenciesNode.appendNode('dependency')
dependencyNode.appendNode('groupId', it.group)
dependencyNode.appendNode('artifactId', it.name)
dependencyNode.appendNode('version', it.version)
}
}
}
}
}
}

artifactory {
contextUrl = 'https://bitmovin.jfrog.io/bitmovin'
publish {
repository {
// The Artifactory repository key to publish to
repoKey = libraryVersion.endsWith('SNAPSHOT') ? 'libs-snapshot-local' : 'libs-release-local'
}
defaults {
// Tell the Artifactory Plugin which artifacts should be published to Artifactory.
publications('aar')
publishArtifacts = true
username = "${artifactory_user}"
password = "${artifactory_password}"

// Properties to be attached to the published artifacts.
properties = ['qa.level': 'basic', 'dev.team': 'core']
// Publish generated POM files to Artifactory (true by default)
publishPom = true
}
}
}
21 changes: 21 additions & 0 deletions collector-bitmovin-player/proguard-rules.pro
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Add project specific ProGuard rules here.
# You can control the set of applied configuration files using the
# proguardFiles setting in build.gradle.
#
# For more details, see
# http://developer.android.com/guide/developing/tools/proguard.html

# If your project uses WebView with JS, uncomment the following
# and specify the fully qualified class name to the JavaScript interface
# class:
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
# public *;
#}

# Uncomment this to preserve the line number information for
# debugging stack traces.
#-keepattributes SourceFile,LineNumberTable

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
1 change: 1 addition & 0 deletions collector-bitmovin-player/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<manifest package="com.bitmovin.analytics.bitmovin.player" />
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.bitmovin.analytics.bitmovin.player;

import com.bitmovin.analytics.BitmovinAnalytics;
import com.bitmovin.analytics.BitmovinAnalyticsConfig;
import com.bitmovin.player.BitmovinPlayer;

public class BitmovinPlayerCollector extends BitmovinAnalytics {

/**
* Bitmovin Analytics
*
* @param bitmovinAnalyticsConfig {@link BitmovinAnalyticsConfig}
*/
public BitmovinPlayerCollector(
BitmovinAnalyticsConfig bitmovinAnalyticsConfig) {
super(bitmovinAnalyticsConfig);
}

public void attachPlayer(BitmovinPlayer player) {
BitmovinSdkAdapter adapter = new BitmovinSdkAdapter(player, this.bitmovinAnalyticsConfig,
this.playerStateMachine);

this.attach(adapter);
}
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
package com.bitmovin.analytics.adapters;
package com.bitmovin.analytics.bitmovin.player;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.os.Build;
import android.util.Log;

import com.bitmovin.analytics.analytics.BitmovinAnalyticsConfig;
import com.bitmovin.analytics.adapters.PlayerAdapter;
import com.bitmovin.analytics.BitmovinAnalyticsConfig;
import com.bitmovin.analytics.data.ErrorCode;
import com.bitmovin.analytics.data.EventData;
import com.bitmovin.analytics.enums.PlayerType;
import com.bitmovin.analytics.stateMachines.PlayerState;
import com.bitmovin.analytics.stateMachines.PlayerStateMachine;
import com.bitmovin.analytics.utils.Util;
import com.bitmovin.player.BitmovinPlayer;
import com.bitmovin.player.*;
import com.bitmovin.player.api.event.data.ErrorEvent;
import com.bitmovin.player.api.event.data.PausedEvent;
import com.bitmovin.player.api.event.data.PlayEvent;
Expand Down Expand Up @@ -91,10 +97,29 @@ private void removePlayerListener() {
this.bitmovinPlayer.removeEventListener(onErrorListener);
}

private String getUserAgent(Context context) {
ApplicationInfo applicationInfo = context.getApplicationInfo();
int stringId = applicationInfo.labelRes;
String applicationName = "Unknown";
if (stringId == 0 && applicationInfo.nonLocalizedLabel != null) {
applicationInfo.nonLocalizedLabel.toString();
}
String versionName;
try {
String packageName = context.getPackageName();
PackageInfo info = context.getPackageManager().getPackageInfo(packageName, 0);
versionName = info.versionName;
} catch (PackageManager.NameNotFoundException var5) {
versionName = "?";
}

return applicationName + "/" + versionName + " (Linux;Android " + Build.VERSION.RELEASE + ") " + "BitmovinPlayer/" + com.bitmovin.player.BuildConfig.VERSION_NAME;
}

@Override
public EventData createEventData() {

EventData data = new EventData(config, stateMachine.getImpressionId());
EventData data = new EventData(config, stateMachine.getImpressionId(), getUserAgent(config.getContext()));
data.setPlayer(PlayerType.BITMOVIN.toString());

//duration
Expand Down
1 change: 1 addition & 0 deletions collector-exoplayer/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/build

0 comments on commit 02856f0

Please sign in to comment.