Open akshdeep-singh opened 1 week ago
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 https://github.com/androidx/media/commit/df07fa35d835c1226a6bfeb4783f944c7f00e858), 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):
StatsDataSource
wrapped around DefaultDataSource
and grab getBytesRead()
after loading each file.StatsDataSource.getLastResponseHeaders()
after loading each file instead, and read the Content-Length
HTTP header.
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.