How to get current video index
Hi I feed ConcatenatingMediaSource() to the player, it plays well but with few issue
- Onclick previous button same video restarts instead of playing previous one. 2 When video ends and next video starts automatically, I am not able to find current video index in any method.In ontrackchanged method, player.getCurrentWindowIndex does return only previous value. Please check code below and suggest answer to me.
try { MediaSource[] mediaSources = new MediaSource[vods.size()]; for (int initialVid = 0; initialVid < vods.size(); initialVid++) {
if (StringUtils.isNotEmpty(vods.get(initialVid).getVideoUrl())) {
String url = vods.get(initialVid).getVideoUrl();
switch (vods.get(initialVid).getStreamFormat()) {
case "mp4":
mediaSources[initialVid] = buildMP4MediaSource(url);
break;
default:
mediaSources[initialVid] = buildHLSMediaSource(url,vods.get(initialVid).getCcPath());
break;
}
}
}
mediaSource = mediaSources.length == 1 ? mediaSources[0]
: new ConcatenatingMediaSource(mediaSources);
playVideo();
}
Onclick previous button same video restarts instead of playing previous one.
This is by design unless you're near the start of the current video (I think it's within the first 3 seconds). This is fairly standard behavior for the back button. If you want something else you're able to build your own UI components that control the player in a different way.
In ontrackchanged method, player.getCurrentWindowIndex does return only previous value
You should call getCurrentWindowIndex from the onPositionDiscontinuity method instead, when reason == DISCONTINUITY_REASON_PERIOD_TRANSITION.