Search code examples
c#androidmetadatamedia

Edit local media file metadata information


I managed to download audio file from a remote source, and I want to change it's metadata, like Author, Title, Album.

I save it locally so it's easily accessible and editable, but I can't find anything to edit it's metadata.

I've tried: Android.Media.MediaMetadataEditor but the error is pretty straightforward:

This class is obsoleted in this android platform

I'm using latest SDK (28) and API, for android Pie. And it is also stated on android developer documentation

This class was deprecated in API level 21. Use MediaMetadata instead together with MediaSession.

I really searched for some example, and I didn't found anything useful, most of cases are with playlist.

I don't get how MediaSession can replace in any manner the MediaMetadataEditor, since MediaSession

Allows interaction with media controllers, volume keys, media buttons, and transport controls.

A MediaSession should be created when an app wants to publish media playback information or handle media keys

Instead MediaMetadata seems what I need because

Contains metadata about an item, such as the title, artist, etc. And its Builder class is promising.

I'm sure that just reading that pages I should be able to understand how to do it, but after hours of trying, it seems I'm not experienced enough to learn from that documentation.

Is there an example to understand it?

Thanks


Solution

  • I found a solution outside android Library.

    taglib-sharp seems working on android project, and it can be installed via nuget package, the name is TagLibSharp

    Really easy to use:

    TagLib.File my_file = TagLib.File.Create(path_to_my_file);
    string[] performers = new string[1]{"My Performer"}
    
    my_file.Tag.Title = "The real title";
    my_file.Tag.Performers = performers;
    
    my_file.Save();
    

    Easy.