Skip to content

Commit

Permalink
Add exoplayer playback listener
Browse files Browse the repository at this point in the history
  • Loading branch information
amarullz committed Apr 18, 2024
1 parent 4b9ab4f commit d725789
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ android {
minSdk 22
targetSdk 34
versionCode 405
versionName "4.1.9-Nightly"
versionName "4.2.1-Nightly"

// Automatic Build Version
buildConfigField "long", "TIMESTAMP", System.currentTimeMillis() + "L"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,13 @@
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.media3.common.MediaItem;
import androidx.media3.common.Tracks;
import androidx.media3.common.util.UnstableApi;
import androidx.media3.datasource.DefaultHttpDataSource;
import androidx.media3.exoplayer.analytics.AnalyticsListener;
import androidx.media3.exoplayer.dash.DashMediaSource;
import androidx.media3.exoplayer.source.MediaSource;
import androidx.media3.exoplayer.source.ProgressiveMediaSource;

import com.devbrackets.android.exomedia.core.source.data.DataSourceFactoryProvider;
import com.devbrackets.android.exomedia.core.video.scale.MatrixManager;
Expand Down Expand Up @@ -382,6 +385,20 @@ else if (host.contains(Conf.STREAM_DOMAIN3)){
videoPlayer.setSurface(videoView.getHolder().getSurface());
videoPlayer.setVideoSizeListener(videoSize -> videoViewEnvelope.setVideoSize(videoSize.width, videoSize.height,
videoSize.pixelWidthHeightRatio));
videoPlayer.addAnalyticsListener(new AnalyticsListener() {
@Override
public void onPlaybackStateChanged(EventTime eventTime, int state) {
AnalyticsListener.super.onPlaybackStateChanged(eventTime, state);
Log.d(_TAG, "ANL: onPlaybackStateChanged="+state);
}

@Override
public void onTracksChanged(EventTime eventTime, Tracks tracks) {
AnalyticsListener.super.onTracksChanged(eventTime, tracks);

Log.d(_TAG, "ANL: TrackChanged="+tracks);
}
});
}

public void videoSetSource(String url){
Expand All @@ -397,6 +414,14 @@ public void videoSetSource(String url){
.createMediaSource(MediaItem.fromUri(url));
videoPlayer.setMediaSource(mediaSource);
}
else if (url.endsWith(".mkv")) {
Log.d(_TAG,"VIDEO-SET-SOURCE (MKV) : "+url);
MediaSource mediaSource =
new ProgressiveMediaSource.Factory(videoDataSourceFactory.provide(""
, null))
.createMediaSource(MediaItem.fromUri(url));
videoPlayer.setMediaSource(mediaSource);
}
else {
Log.d(_TAG,"VIDEO-SET-SOURCE (HLS) : "+url);
videoPlayer.setMediaUri(Uri.parse(url));
Expand Down

0 comments on commit d725789

Please sign in to comment.