summaryrefslogtreecommitdiff
path: root/client/components/UI/AudioPlayerView.jsx
blob: 62745ede75aac1d647c718449fcf98c18a2391e0 (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
36
import { h, Component } from 'preact'

const audio = document.createElement('audio')

export default function AudioPlayerView (props) {
  if (props.file) {
    document.body.style.backgroundImage = 'url(' + pngpath(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'
}