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 clipping of multi-period content #6234

Open
brianchu opened this issue Jul 27, 2019 · 8 comments
Open

Support clipping of multi-period content #6234

brianchu opened this issue Jul 27, 2019 · 8 comments
Assignees

Comments

@brianchu
Copy link

Issue description

Want to loop a video (mp4) for certain fix period of time and if it doesn't fit perfectly, it will play and finish partially within the time limit. so thinking combine X numbers of source with concatenatingMediaSource and use ClippingMediaSource to clip the media.

other option is use LoopingMedaiSource() with ClippingMediaSource, basically

ClippingMediaSource(LoopingMediaSource(...), ...)

but it gives me the same error.

com.google.android.exoplayer2.source.ClippingMediaSource$IllegalClippingException: Illegal clipping: invalid period count

Reproduction steps

I use ConcatenatingMediaSource with two (same) mp4 and then wrap that with ClippingMediaSource.

  val baseMediaSource1 = ProgressiveMediaSource.Factory(...).createMediaSource(videoUrl)
  val baseMediaSource2 = ProgressiveMediaSource.Factory(...).createMediaSource(videoUrl)

  val concat = ConcatenatingMediaSource(true, baseMediaSource1, baseMediaSource2)
  mediaSource = ClippingMediaSource(concat, <duration for 10seconds>)

Link to test content

Any mp4

A full bug report captured from the device

I can offer you the full report but I feel the stack is enough here.

Version of ExoPlayer being used

2.10.3

Device(s) and version(s) of Android being used

emulator, S9, Pixel 3.

@brianchu
Copy link
Author

I hope it is not an unsupported feature.

@marcbaechinger
Copy link
Contributor

Looping a media source with more than a single period, is indeed an unsupported feature of the ClippingMediaSource I'm afraid. Like the java doc of the ClippingMediaSource says:

/**
 * {@link MediaSource} that wraps a source and clips its timeline based on specified start/end
 * positions. The wrapped source must consist of a single period.
 */

I don't think there is an easy solution for this with media source composition with a ConcatenatingMediaSource. The easiest is probably to just send a message to a handler to be executed after a given duration of time. This is not a nice solution from a playback perspective, as the player can not really avoid rebuffering. I think it depends on your use case if this is sufficient for you.

final Handler handler = new Handler();
handler.postDelayed(new Runnable() {
  @Override
  public void run() {
    player.setPlayWhenReady(false);
  }
}, 5 * 60 * 1000);

@marcbaechinger
Copy link
Contributor

I added the enhancement tag, so we can check whether we can either remove the constraint of ClippingMediaSource working only for single period media sources or we can think about another approach to make that use case easier to achieve.

@dexterleng
Copy link

@brianchu have you tried clipping first before concatenating?

@ojw28
Copy link
Contributor

ojw28 commented Sep 2, 2019

I think you can already do what you want to do. Suppose the mp4 is 10 seconds and you want to play for 56 seconds. Create a MediaSource for the mp4, which we'll call A, and do the following (this is pseudo-code only; it's not intended to actually compile):

ConcatenatingMediaSource(
    LoopingMediaSource(A, /* loopCount= */ 5),
    ClippingMediaSource(A, /* clipEndPosition= */ 6 seconds));

Closing this issue on the assumption that the above works (please let us know if not). I know that @tonihei has some plans on making this more flexible, but I'm not sure we need this issue kept open for tracking (there may already be, or possibly should be, a more general issue tracking this).

@ojw28 ojw28 closed this as completed Sep 2, 2019
@tonihei
Copy link
Collaborator

tonihei commented Sep 2, 2019

I think there is no enhancement tracking "Clipping of multi-period content" as such. We have one to track changing the clipping position during playback (#3163), but this is only helpful for this case to adapt the clipping duration of the last loop to adjust for the total duration of the previous loops (if it was unknown before playback).

It would make sense to support clipping of multi-period content eventually by updating the respective period clipping positions based on the specified window clipping. Will leave the issue open to track this. Seems also helpful for multi-period DASH streams.

@tonihei tonihei reopened this Sep 2, 2019
@ojw28 ojw28 changed the title ClippingMediaSource of multiple ConcatenatingMediaSource give error: invalid period count Support clipping of multi-period content Sep 2, 2019
@mzgreen
Copy link

mzgreen commented Feb 18, 2020

Hey what is the status of this issue? Are there any plans to implement it in near future?

@marcbaechinger
Copy link
Contributor

There are no plans to implement this in the near future I'm afraid.

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

6 participants