Provide an API for metadata & frame extraction without playback
Issue description
I'm trying to extract track information such as title and an artist from the local mp3 file before playing it.
I managed to get track metadata in 'onTracksChanged' callback, but I need access to it earlier. I have File object and its uri and I tried to use Mp3Extractor directly, which needs DataSource, but I'm not sure how to create it.
Could you provide me with the information if such a thing is possible and how to do it?
Version of ExoPlayer being used
2.5.4
The easiest option may be to create a player which is paused (setPlayWhenReady(false)) so that playback doesn't start automatically, then prepare it with your media source. You should get an onTracksChanged callback with the metadata but audio won't start playing.
Thank you for your reply, but I wonder if there is a chance to extract metadata without initializing and preparing player? You wrote about the easiest way, so is there another option? Will it take a lot of effort to implement it without using player?
@andrewlewis - Should we turn this into a general enhancement request for providing metadata APIs (or alternatively, should we file a new one and dupe this one to it)?
Marking as an enhancement for now.
Can you please also consider adding metadata extraction of video files?
@AndroidDeveloperLB That will be included. There is already pending work in that area and we will notify this thread if we publish something.
@tonihei That's great news. But I also wonder something: Doesn't the Android framework already offer such things ? Or do you plan on much more than what it offers, and have a consistent result, or something ?
@AndroidDeveloperLB @mhabzda some sample code in my project is available here: https://github.com/ened/flutter_plugin_media_info/blob/master/android/src/main/java/asia/ivity/mediainfo/MediaInfoPlugin.java#L139-L188 . It uses the technique mentioned by @andrewlewis, but comes with the full initialisation of a player instance.
@ened Sadly now that Android Q isn't nice to file path, I think you should provide an alternative, that uses Uri or InputStream. Can you please make a repository that shows only this? Meaning of metadata extraction without playback ?
Just adding a clarification for #7285: this API would also support video thumbnail extraction.
Hello. Do you happen to have any updates regarding the frame extraction API?
We don't have any updates on this yet I'm afraid.
Coil has this feature that allows to extract the first frame from video: https://coil-kt.github.io/coil/videos/ Although this thing is pretty slow.
I set a transparent background for the player and placed AsyncImage below that. It does work, but flicks with black.
Not sure how to fix this thing