How to get music’s info from input type file in ReactJs

I have input with type="file" that only accepts a music file. I want to get information about music. For example: the name of the singer or the photo of the music.

<input type="file" className="popup-content--file" accept="audio/*" id="file" onChange={(e) => {selectMusic(e, e.currentTarget.files[0])}} />

const selectMusic = (e, file) => {
    if(file.size < 10485760 && file.type.includes('audio/')){
        const reader = new FileReader()

        reader.readAsDataURL(file)

        reader.onload = () => {
            console.log(reader)
        }
    }
}

Answer

Audio file can contain metadata information stored as ID3 tags.

There are browser-based id3 parsers like this one that will help you – from their docs:

<input type="file">

<script type="module">
import * as id3 from '//unpkg.com/id3js@^2/lib/id3.js';

document
  .querySelector('input[type="file"]')
  .addEventListener('change', async (e) => {
    const tags = await id3.fromFile(e.currentTarget.files[0]);
    // tags now contains v1, v2 and merged tags
  });
</script>