SigmaDRM ExoPlayer version 2.19.1
1. Introduction
Please enter dashboard of Sigma DRM to get integration information as image below
2. Require
Requirement
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-common:2.19.1' implementation 'com.sigma.drm:sigma-player-container:2.19.1' implementation 'com.sigma.drm:sigma-player-core:2.19.1' implementation 'com.sigma.drm:sigma-player-extractor:2.19.1' implementation 'com.sigma.drm:sigma-player-dash:2.19.1' implementation 'com.sigma.drm:sigma-player-datasource:2.19.1' implementation 'com.sigma.drm:sigma-player-decoder:2.19.1' implementation 'com.sigma.drm:sigma-player-hls:2.19.1' implementation 'com.sigma.drm:sigma-player-smoothstreaming:2.19.1' implementation 'com.sigma.drm:sigma-player-ui:2.19.1'
- 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" />
- Add a repositories in the
3. Integrate SigmaPlayer
3.1. Initialize the application
java
import com.google.android.exoplayer2.ui.StyledPlayerView;
import com.sigma.player.playlist.DefaultHlsPlaylistParserFactory;
import com.sigma.drm.SigmaHelper;
import com.sigma.player.HlsMediaSource;
/*...*/
public 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();
SigmaHelper.instance().init();
}
3.2 Initiate Player
java
protected void initializePlayer() {
SigmaHelper.instance().configure(MERCHANT_ID, APP_ID, USER_ID, SESSION_ID);
if (player == null) {
mediaSource = createMediaSource(Uri.parse(MEDIA_URL), "", null);
ExoPlayer.Builder playerBuilder = new ExoPlayer.Builder(this);
playerBuilder.setRenderersFactory(getRenderersFactory());
player = playerBuilder.build();
player.setAudioAttributes(AudioAttributes.DEFAULT, /* handleAudioFocus= */ true);
player.setPlayWhenReady(true);
player.addListener(new Player.Listener() {
public void onPlayerError(PlaybackException error) {
if (error.errorCode == PlaybackException.ERROR_CODE_BEHIND_LIVE_WINDOW) {
// Re-initialize player at the live edge.
player.seekToDefaultPosition();
player.prepare();
} else {
// Handle other errors
}
}
});
playerView.setPlayer(player);
}
boolean haveStartPosition = startWindow != C.INDEX_UNSET;
if (haveStartPosition) {
player.seekTo(startWindow, startPosition);
}
player.prepare(mediaSource, !haveStartPosition, false);
}
private MediaSource createMediaSource(Uri uri, String extension, DrmSessionManager drmSessionManager) {
@C.ContentType
int type = Util.inferContentType(uri, extension);
DataSource.Factory dataSourceFactory = buildDataSourceFactory();
switch (type) {
case C.CONTENT_TYPE_DASH:
return new DashMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(uri));
case C.CONTENT_TYPE_SS:
return new SsMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(uri));
case C.CONTENT_TYPE_HLS:
return new HlsMediaSource.Factory(dataSourceFactory)
.setPlaylistParserFactory(new DefaultHlsPlaylistParserFactory())
.createMediaSource(MediaItem.fromUri(uri));
case C.CONTENT_TYPE_OTHER:
return new ProgressiveMediaSource.Factory(dataSourceFactory)
.createMediaSource(MediaItem.fromUri(uri));
default:
throw new IllegalStateException("Unsupported type: " + type);
}
}
private DataSource.Factory buildDataSourceFactory() {
return new DefaultDataSourceFactory(this, buildHttpDataSourceFactory());
}
public HttpDataSource.Factory buildHttpDataSourceFactory() {
return new DefaultHttpDataSource.Factory().setUserAgent("SigmaDRM");
}
private RenderersFactory getRenderersFactory() {
if (renderersFactory == null) {
renderersFactory = new DefaultRenderersFactory(getApplicationContext())
.setExtensionRendererMode(DefaultRenderersFactory.EXTENSION_RENDERER_MODE_ON);
}
return renderersFactory;
}
Please replace the following placeholders in the code:
Props | Type | Description |
---|---|---|
MEDIA_URL | String | The URL to the HLS Multivariant Playlist (M3U8) file. |
MERCHANT_ID | String | The ID of SigmaDRM's merchant. |
APP_ID | String | The ID of merchant's application. |
USER_ID | String | The ID of merchant's user. |
SESSION_ID | String | The session of merchant's user. |