audio-cover

Get the cover from an audio file in the browser

Usage no npm install needed!

<script type="module">
  import audioCover from 'https://cdn.skypack.dev/audio-cover';
</script>

README

audio-cover Build Status DEMO

Get the cover from an audio file in the browser

Installation

$ yarn add audio-cover

Demo

https://zzarcon.github.io/audio-cover

Usage

import getAudioCover from 'audio-cover';

try {
  const coverSrc = await getAudioCover(file);
  
  console.log('base64 encoded cover', coverSrc)
} catch (e) {
  console.log('no cover available', e)
}

Api

getAudioCover: (file: File) => Promise<string>

given a file, returns a promise with the cover in base64, otherwise will reject if cover is not present

Example

import getAudioCover from 'audio-cover';

class App extends React.Component {
  state = {}

  onChange = async (e) => {
    try {
      const file = e.target.files[0];
      const coverSrc = await getAudioCover(file);
      this.setState({coverSrc});
    } catch(e) {
      console.log('error:', e)
    }
  }

  render() {
    const {coverSrc} = this.state;

    return (
      <div>
        <input type="file" onChange={this.onChange}/>
        <img src={coverSrc} />
      </div>
    )
  }
}

Author 👶🏼

@zzarcon