question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to get the entire content Duration of a MediaItem, not just the clip length?

See original GitHub issue

[REQUIRED] Question

I have a list of MediaItems with different start positions.

MediaItem mediaItem = new MediaItem.Builder()
    .setUri(trackUri)
    .setClipStartPositionMs(startPos)
    .setClipEndPositionMs(C.TIME_END_OF_SOURCE)
    .build();

When a particular MediaItem is being played, the Player is just returning the duration of the clip, not the total length of the track. Is there a way where I can get the total length of the track, not just the clip length?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:9 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ojw28commented, Nov 3, 2020

@pavan245 - For only changing the start clip position, my solution posted above will work. For the end position, marking this as a duplicate of #3163 as per Toni’s response above.

1reaction
ojw28commented, Nov 2, 2020

If you’re only changing the start clip position then I think you can retrieve the entire content duration like:

@Override
public void onTimelineChanged(Timeline timeline, @TimelineChangeReason int reason) {
  if (!timeline.isEmpty()) {
    long durationMs = timeline.getPeriod(0, new Period()).getDurationMs();
  }
}

Note that you can also retrieve the timeline from Player.getCurrentTimeline. @pavan245 - Does that work for you?

The same trick does not work if you set an end clip position, however. This may not be relevant to your use case, but is something we should think about. @tonihei - Do you understand why that’s not the case? If both start and end are clipped, I think I’d expect the period and window to look like:

<----------- original content ----------->
<-------------- period ------------------>
            <----- window ----->

where-as it seems they look like:

<----------- original content ----------->
<-------------- period -------->
            <----- window ----->

I tried changing ClippingTimeline.getPeriod to do what I expected, but then playback doesn’t transition to the ended state once the clip end point is reached. Which also seems unexpected to me.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to get duration of a video file? - android - Stack Overflow
I'm writing an application to list all video file in a folder and display information of all videos in the folder. But when...
Read more >
REST Resource: mediaItems | Google Photos APIs
Metadata that is specific to a photo, such as, ISO, focal length and exposure time. Some of these fields may be null or...
Read more >
Setting the duration of a video file in C# - MSDN - Microsoft
I want to change the duration to reflect the total length of both files. Any suggestions are appriciated. p.s not using ffmpeg.
Read more >
Display the duration, current time, and remaining time of the ...
Wait for the player to be in at least the PREPARED state. Retrieve the current playhead time by using the MediaPlayer.getCurrentTime method.
Read more >
Working with Media - ProPresenter User Guide
If you have multiple Media Actions selected at the same time, ... Scale to Fit will make sure that all of your content...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found