audio-cover
v0.0.3
Published
Get the cover from an audio file in the browser
Downloads
6
Readme
audio-cover 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>
)
}
}