summaryrefslogtreecommitdiff
path: root/client/components/UI/AudioPlayer.jsx
blob: de6502c51132c4f3115c27a3c9c97d432a1065da (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import { h, Component } from 'preact'

const audio = document.createElement('audio')

export default function AudioPlayer (props) {
  if (props.file) {
    audio.src = mp3path(props.file)
    audio.play()
    return (
      <div>
        Playing {props.file.name}
      </div>
    )
  }
  else {
    return (
      <div>
        Not Playing
      </div>
    )
  }
}

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'
}