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

How to instruct exoplayer to stop at a certain position in advance? #4176

Closed
abhishekredspace opened this issue Apr 24, 2018 · 1 comment
Closed
Assignees
Labels

Comments

@abhishekredspace
Copy link

abhishekredspace commented Apr 24, 2018

Hi Exoplayer team,
I am using Exoplayer 2 in my video player for playback and I am looking for a mechanism through which I can instruct exoplayer to stop at certain position in advance. Let me explain what exactly I am looking here.
We get a seamless HLS stream which has video content and ads content. Along with stream as a response from the server, we also get ads position for playing the ads i.e. at which playhead position ads are present. We need these positions as we show different UI controls when ads are playing. So for example, I would have something like this as ads position in milliseconds.

TimeInterval{start=TimePosition(532673), end=TimePosition(623094)}

I have a scheduler which polls for getCurrentPosition. Everything seems to work perfectly fine apart from one issue. When I do a seek while the video is playing and if there is an ad interval in between those seeking positions, I am supposed to trigger the ads and once ads are completed, I seeked to the desired position. Here comes the problem, after the ads end,I see the first frame of content. Exoplayer gives positions as,
TimePosition(622593)
TimePosition(623138)

What I am looking here is, if somehow I can pause/stop exoplayer at a certain position which in this case would be end=TimePosition(623094).
I never want exoplayer to go beyond end=TimePosition(623094) in this case. Please suggest what can be the right solution here.

@abhishekredspace abhishekredspace changed the title How to get next position along with current position? How to instruct exoplayer to stop at a certain position in advance? Apr 24, 2018
@ojw28
Copy link
Contributor

ojw28 commented Apr 25, 2018

I understand the problem. I don't think we have a frame accurate solution to this currently, although it should be possible to do better than your polling approach. You can use an event based approach as follows:

  1. Define a component that will be called whenever a boundary between content and ad is reached:
PlayerMessage.Target boundaryHandler = new PlayerMessage.Target() {
  @Override
  public void handleMessage(int messageType, Object payload) {
    long boundaryPositionMs = (long) payload;
    // TODO: Implement your logic here.
  }
};
  1. Ask the player to call your component whenever a boundary between content and ad is reached. For each boundary position, do:
player.createMessage(boundaryHandler)
    .setHandler(mainHandler)
    .setPosition(boundaryPositionMs)
    .setPayload(boundaryPositionMs)
    .setDeleteAfterDelivery(false)
    .send();

You should then see handleMessage invoked whenever a boundary is hit, and you can take appropriate action there. This wont be frame accurate, unfortunately, due to the way ExoPlayer works internally, but it should get you closer to what you need, and is definitely better than polling.

There are variations on the suggested approach above, where you only ask the player to call you back for a single position of interest, don't ask for message re-delivery etc, so you can play around with the idea.

I think the "proper" solution to this would be to implement a variant of AdsMediaSource that operates on a single child MediaSource plus a list of known ad positions. That's a pretty involved change, however.

Let us know how you get on with the approach above! We can probably turn this issue into an enhancement request for the "proper" solution, but I don't think we'll have time to look at it soon.

@ojw28 ojw28 self-assigned this Apr 25, 2018
@ojw28 ojw28 added the question label Apr 25, 2018
@ojw28 ojw28 closed this as completed May 10, 2018
@google google locked and limited conversation to collaborators Sep 11, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

2 participants