import { h, Component } from 'preact'
const audio = document.createElement('audio')
export default function AudioPlayer (props) {
if (props.file) {
document.body.style.backgroundImage = 'url(' + pngpath(file) + ')'
audio.src = mp3path(props.file)
audio.play()
return (
Playing {props.file.name}
)
}
else {
return (
Not Playing
)
}
}
function filepath (file) {
return '/data/' + file.folder_id + '/' + encodeURIComponent(file.name)
}
function mp3path (file) {
if (file.mime !== 'audio/mp3') {
return filepath(file) + '.mp3'
}
return filepath(file)
}
function pngpath (file) {
return filepath(file) + '.png'
}