google / ExoPlayer

This project is deprecated and stale. The latest ExoPlayer code is available in https://github.com/androidx/media
https://developer.android.com/media/media3/exoplayer
Apache License 2.0
21.7k stars 6.02k forks source link

player.getCurrentPosition() return value is negative when using ClippingMediaSource #4873

Closed Romantic-LiXuefeng closed 5 years ago

Romantic-LiXuefeng commented 5 years ago

ExoPlayer version: v2.8.4 The sample code is :

 MediaSource[] mediaSources = new MediaSource[uris.length];
 for (int i = 0; i < uris.length; i++) {
     mediaSources[i] = buildMediaSource(uris[i], extensions[i], null);
 }
 if (mediaSources.length == 1){
    ClippingMediaSource content1 = new ClippingMediaSource(mediaSources[0], 0, 15000000,null);
    ClippingMediaSource content2 = new ClippingMediaSource(mediaSources[0], 15000000, C.TIME_END_OF_SOURCE,null);
    mediaSource = new ConcatenatingMediaSource(
          content1,            // content[0~15s]
          content2 );           // content[15s ~ end]
}

I use a ClippingMediaSource to split one video into two video at point 15s, then concatenate them. When the player begins to play the second video, I pressed home button, then resume to play, I find that the TimeBar's current position is negative. The logs like this:

  E/EventLogger: player position = [-6421] bufferedPosition = [-1742]
  E/EventLogger:player position = [-5006] bufferedPosition = [4760]
Romantic-LiXuefeng commented 5 years ago

@ojw28 Did you already had the time to look into this issue? Is there anything I can do to support you?

erdemguven commented 5 years ago

Reproducible on the latest development branch.

tonihei commented 5 years ago

Thanks for reporting. We'll provide a fix for this soon.

tonihei commented 5 years ago

The commit above fixes the issue.

Romantic-LiXuefeng commented 5 years ago

@tonihei thanks! Hope to give me some information about how was this bug generated?

Romantic-LiXuefeng commented 5 years ago

@ojw28 I find that when the player plays the first clip video ,press home button, then resume to play,there is no this bug. Hope you give me some explanation.

tonihei commented 5 years ago

The bug occurred because the player creates the element at which playback starts with a default position of zero until we know more. In your case, this default position was non-zero (because of the clipping) and we forgot to set the right offset at one point.

Not sure why you don't see the bug with the first video? I was able to reproduce the issue with the first and the second video in a concatenation.