ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

How to get current video index

Open ummerakbar45 opened this issue 8 years ago • 1 comments

Hi I feed ConcatenatingMediaSource() to the player, it plays well but with few issue

  1. 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();


        }

ummerakbar45 avatar Sep 14 '18 02:09 ummerakbar45

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.

ojw28 avatar Sep 14 '18 09:09 ojw28