ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Support pausing at a frame-accurate position

Open star-andy opened this issue 6 years ago • 15 comments
trafficstars

Hello, I have a question to consult My English is not very good, please forgive me

I will be more MediaSource add ConcatenatingMediaSource , I want to listen CurrentWindowIndex to finish playing

 @Override
        public void onLoadingChanged(boolean isLoading) {
            int curTime = (int) (player.getCurrentPosition() );
            int time = (int) (player.getBufferedPosition() );
            System.out.println("播放: onLoadingChanged  " + curTime + "--->" + time);
            if (time != 0 && curTime == time) {
                player.setPlayWhenReady(false);
                }
            }
        }

I can't do it that way

star-andy avatar Mar 21 '19 07:03 star-andy

You can listen to onPositionDiscontinuity and check if player.getCurrentWindowIndex changed in there.

tonihei avatar Mar 25 '19 09:03 tonihei

@tonihei Thank you for your reply I want to listen for each end, not the second beginning

player.getCurrentWindowIndex

When changing the source has become the next

star-andy avatar Mar 26 '19 05:03 star-andy

There is only one single moment in which playback changes from window index to the next. If you'd like to know the previous index, you could just save the current index to a variable and check if it changed in the onPositionDiscontinuity callback.

If you want to do something at a specific playback position, you can also try to send a message at a certain time like so: player.createMessage((type, payload) -> doSomething()).setPosition(12345).setHandler(new Handler()).send();

tonihei avatar Mar 26 '19 09:03 tonihei

@tonihei Send is an imprecise I want it to be when the current index play is done

  player.setPlayWhenReady(false);

It's going to stop after the last frame of index not the first frame of next index

star-andy avatar Mar 26 '19 09:03 star-andy

The message is imprecise because it's send on another thread.

I'll mark this as an enhancement to support sending precise messages which may block the playback thread while the message is handled. We do something like that in our testutils here if you want to give it a go.

An alternative is to NOT add MediaSources behind the current one to the ConcatenatingMediaSource and wait until the state changes to STATE_ENDED. After this happens you can add new sources and seek to the next item.

tonihei avatar Mar 26 '19 09:03 tonihei

Thank you very much for trying to prepare one MediaSource per time in PlaybackState.STATE_ENDED: Reprepare MediaSource but there is currently a problem that there will be a lag between two prepare periods and I wonder if I can add a transition effect to add a better experience

star-andy avatar Mar 27 '19 01:03 star-andy

Sending precise messages is most likely not feasible, because the main reason to do that is to pause at a specific frame-accurate timestamp. As we don't control the last few milliseconds before releasing the frame to the surface, this behavior needs to be implemented by actually holding back samples in the renderer.

This can still be implemented, e.g. by using renderer messages sent at an earlier time, but not as a PlayerMessage triggered at the intended position, because by the time the message is triggered, it's already too late.

I'll mark the issue as "low priority" because it's more complicated than anticipated. And also rename to only solve the pausing feature.

tonihei avatar Jun 27 '19 11:06 tonihei

@tonihei Thank you very much
I'm currently using what you called PlaybackState.STATE_ENDED To solve this problem However, when the two MediaSource switch, can't make a better transition? Can we add a transition animation to make a better connection

star-andy avatar Jun 28 '19 06:06 star-andy

Pausing at a frame-accurate position is a subset of setting the playback speed from a frame-accurate position (pausing := speed=0.0). Or at least both share a similar set-up.

@Samrobbo, assigning to you as you may look into the playback speed setting issue anyway.

tonihei avatar Nov 18 '19 14:11 tonihei

There is now a public design doc for this feature at https://exoplayer.dev/design-documents.html (direct doc link)

tonihei avatar Jan 29 '20 13:01 tonihei

We now support pausing at the end of media items (that is, at the last frame) using exoplayer.setPauseAtEndOfMediaItem.

I'll leave this issue open for the more general feature to pause at arbitrary exact frame positions. As most requests have been for last frame pausing, I'll mark this enhancement as low priority for now.

tonihei avatar Apr 24 '20 15:04 tonihei

Hi, This is still not published to release-v2 version but has been dev for 6 months. Any particular reason?

skkshoaib avatar Sep 12 '20 18:09 skkshoaib

It will be released very soon, in 2.12.

ojw28 avatar Sep 12 '20 19:09 ojw28

The work to enable pausing at the end of media items was released in 2.12. This issue remains open to track the more general feature to pause at arbitrary exact frame positions, as per https://github.com/google/ExoPlayer/issues/5660#issuecomment-619067418.

ojw28 avatar Oct 22 '20 13:10 ojw28

Is there any update? @ojw28 @tonihei

bdezso avatar Aug 26 '22 16:08 bdezso

Hi,

Is this planned to be implemented?

There is a design doc from 2020-01-15 by @tonihei , and I found a few other issues that were closed because of similarity\duplicate with this.

Just saying, there is a demand for this feature

pacman899 avatar Oct 24 '22 10:10 pacman899