Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support pausing at a frame-accurate position #5660

Open
star-andy opened this issue Mar 21, 2019 · 16 comments
Open

Support pausing at a frame-accurate position #5660

star-andy opened this issue Mar 21, 2019 · 16 comments

Comments

@star-andy
Copy link

star-andy commented Mar 21, 2019

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

@tonihei
Copy link
Collaborator

tonihei commented Mar 25, 2019

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

@star-andy
Copy link
Author

star-andy commented Mar 26, 2019

@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

@tonihei
Copy link
Collaborator

tonihei commented Mar 26, 2019

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

@star-andy
Copy link
Author

@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

@tonihei
Copy link
Collaborator

tonihei commented Mar 26, 2019

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 tonihei changed the title I want to listen for CurrentWindowIndex to finish playing Support sending precise messages, e.g. to pause at the end of a window. Mar 26, 2019
@star-andy
Copy link
Author

star-andy commented Mar 27, 2019

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

@tonihei
Copy link
Collaborator

tonihei commented Jun 27, 2019

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 tonihei changed the title Support sending precise messages, e.g. to pause at the end of a window. Support pausing at a frame-accurate position Jun 27, 2019
@star-andy
Copy link
Author

@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

@tonihei
Copy link
Collaborator

tonihei commented Nov 18, 2019

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 tonihei assigned Samrobbo and unassigned tonihei Nov 18, 2019
@tonihei tonihei assigned tonihei and unassigned Samrobbo Jan 8, 2020
@tonihei
Copy link
Collaborator

tonihei commented Jan 29, 2020

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

ojw28 pushed a commit that referenced this issue Mar 19, 2020
Also adds tests covering the internal implementation.

Issue:#5660
PiperOrigin-RevId: 300513548
@tonihei
Copy link
Collaborator

tonihei commented Apr 24, 2020

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.

@skkshoaib
Copy link

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

@ojw28
Copy link
Contributor

ojw28 commented Sep 12, 2020

It will be released very soon, in 2.12.

@ojw28
Copy link
Contributor

ojw28 commented Oct 22, 2020

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 #5660 (comment).

@bdezso
Copy link

bdezso commented Aug 26, 2022

Is there any update? @ojw28 @tonihei

@pacman899
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants