ExoPlayer
1. Introduction
Please enter dashboard of Sigma DRM to get integration information as image below
2. Require
Requirment
Operating system: Android 16+
Install SigmaPlayer:
- Add a repositories in the build.gradle file of your app module.
javarepositories{ maven { url "https://maven.sigmadrm.com" } } }
- Add a dependency in the build.gradle file of your app module. The following will add a dependency to the full library:
javaimplementation 'com.sigma.drm:sigma-player-core:2.9.6' implementation 'com.sigma.drm:sigma-player-hls:2.9.6' implementation 'com.sigma.drm:sigma-player-ui:2.9.6' implementation 'com.sigma.drm:sigma-player-dash:2.9.6' implementation 'com.sigma.drm:sigma-player-smoothstreaming:2.9.6'
- Add support Java version 1.8 by add compileOptions in build.gradle file of your app module.
javacompileOptions { targetCompatibility JavaVersion.VERSION_1_8 }
- Add permission to access internet by add user permission.
xml<uses-permission android:name="android.permission.INTERNET" />
3. Integrate SigmaPlayer
3.1. Initiate PlayerView
java
// Import PlayerView
import com.google.android.exoplayer2.ui.PlayerView;
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
playerView = findViewById(R.id.player_view);
playerView.setControllerVisibilityListener(this);
playerView.setErrorMessageProvider(new PlayerErrorMessageProvider());
playerView.requestFocus();
}
3.2. Config Sigma Player
java
// Import SigmaHelper
import com.sigma.drm.SigmaHelper;
...
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
/*...*/
SigmaHelper.instance().configure(MERCHANT_ID, APP_ID, USER_ID, SESSION_ID);
}
Integration Information
Props | Description | Type | Example |
---|---|---|---|
MERCHANT_ID | Identify of merchant that get from cms | String | thudomultimedia |
APP_ID | Identify of app that get from cms | String | RedTV |
USER_ID | Identify of user that get from merchant application | String | username_1 |
SESSION_ID | Identify of session that get from merchant application | String | session_1 |
3.3 Initialize Player
java
private void initializePlayer() {
if (player == null) {
mediaSource = createMediaSource(uri, "", null);
if (mediaSource == null) {
return;
}
DefaultTrackSelector trackSelector = new DefaultTrackSelector(new AdaptiveTrackSelection.Factory());
RenderersFactory renderersFactory = getRenderersFactory();
DefaultDrmSessionManager<FrameworkMediaCrypto> drmSessionManager = null;
player = ExoPlayerFactory.newSimpleInstance(this, renderersFactory, trackSelector, drmSessionManager);
player.setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */ true);
player.setPlayWhenReady(true);
playerView.setPlayer(player);
playerView.setPlaybackPreparer(this);
}
boolean haveStartPosition = startWindow != C.INDEX_UNSET;
if (haveStartPosition) {
player.seekTo(startWindow, startPosition);
}
player.prepare(mediaSource, !haveStartPosition, false);
}
3.4 Create Media Source
java
private MediaSource createMediaSource(
Uri uri, String extension, DrmSessionManager<?> drmSessionManager) {
@C.ContentType int type = Util.inferContentType(uri, extension);
switch (type) {
case C.TYPE_DASH:
return new DashMediaSource.Factory(buildDataSourceFactory())
.createMediaSource(uri);
case C.TYPE_SS:
return new SsMediaSource.Factory(buildDataSourceFactory())
.createMediaSource(uri);
case C.TYPE_HLS:
return new HlsMediaSource.Factory(buildDataSourceFactory())
.setPlaylistParserFactory(new DefaultHlsPlaylistParserFactory())
.createMediaSource(uri);
case C.TYPE_OTHER:
return new ExtractorMediaSource.Factory(buildDataSourceFactory()).createMediaSource(uri);
default:
throw new IllegalStateException("Unsupported type: " + type);
}
}
3.5 Create Factory
java
private RenderersFactory getRenderersFactory() {
if (renderersFactory == null) {
renderersFactory = new DefaultRenderersFactory(getApplicationContext())
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
}
return renderersFactory;
}
/** Returns a {@link DataSource.Factory}. */
public DataSource.Factory buildDataSourceFactory() {
DefaultDataSourceFactory upstreamFactory =
new DefaultDataSourceFactory(this, buildHttpDataSourceFactory());
return upstreamFactory;
}
/** Returns a {@link HttpDataSource.Factory}. */
public HttpDataSource.Factory buildHttpDataSourceFactory() {
return new DefaultHttpDataSourceFactory(Util.getUserAgent(this, "SigmaDRM"));
}