Search code examples
c#windows-store-appsmp3id3-tag

How to read Beats-per-minute tag of mp3 file in windows store apps C#?


i am trying to read bpm embedded in mp3 file like this one :

bpm tag im trying to read

i have tried using

Windows.Storage.FileProperties.MusicProperties

but it only contains title, singer, etc. it can't read the bpm i showed before.

im looking into https://taglib.github.io/ they seems not having such function too. is there any workaround to this?


Solution

  • When you've loaded your music file into a StorageFile, you'll want to place a similar call in your code like this:

    var fileProps = await file.Properties.RetrievePropertiesAsync(null);

    This will get you a list of all the system properties exposed as a Dictionary<string, object>.

    You can then get the BPM value as follows:

    if (fileProps.ContainsKey("System.Music.BeatsPerMinute"))
    {
        var bpmObj = fileProps["System.Music.BeatsPerMinute"];
        if (bpmObj != null)
        {
            var bpm = bpmObj.ToString();
        }
    }
    

    You can find a complete list of available file properties here: https://msdn.microsoft.com/en-us/library/windows/desktop/dd561977(v=vs.85).aspx