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

Get duration and size of an mp3 file without playback? #1885

Closed
akshdeep-singh opened this issue Nov 14, 2024 · 2 comments
Closed

Get duration and size of an mp3 file without playback? #1885

akshdeep-singh opened this issue Nov 14, 2024 · 2 comments
Assignees
Labels

Comments

@akshdeep-singh
Copy link

There is an option to retrieve metadata without playback as mentioned in the docs.

Is it possible to get duration and size of an mp3 file (https in my case) without playback?

My use case is that I want to show duration and size of all my playlist items.

@icbaker
Copy link
Collaborator

icbaker commented Nov 21, 2024

For duration, you could try MediaExtractorCompat, using getTrackFormat(0) and looking for KEY_DURATION.

This will only work on the main branch for now (because you need df07fa3), so you will need to build the library locally. It will be included in 1.6.0.

You could also use the framework MediaExtractor implementation for this if you don't need to use media3.


By size, I assume you mean file size? We don't have an easy way to expose that in media3. You can probably do some combination of (configuring this via passing a custom DataSource.Factory instance to the MediaExtractorCompat constructor):

  1. Use StatsDataSource wrapped around DefaultDataSource and grab getBytesRead() after loading each file.
  2. Use StatsDataSource.getLastResponseHeaders() after loading each file instead, and read the Content-Length HTTP header.

@icbaker
Copy link
Collaborator

icbaker commented Jan 13, 2025

Closing because I think the question has been answered.

@icbaker icbaker closed this as completed Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants