From f8b61281be84a6e4e7a44be5109e688a7c56c671 Mon Sep 17 00:00:00 2001
From: Jules Laplace <julescarbon@gmail.com>
Date: Fri, 7 Jul 2017 21:18:33 +0200
Subject: refactor files so list updates while processing

---
 client/components/UI/AudioPlayerView.jsx | 36 ++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
 create mode 100644 client/components/UI/AudioPlayerView.jsx

(limited to 'client/components/UI/AudioPlayerView.jsx')

diff --git a/client/components/UI/AudioPlayerView.jsx b/client/components/UI/AudioPlayerView.jsx
new file mode 100644
index 0000000..62745ed
--- /dev/null
+++ b/client/components/UI/AudioPlayerView.jsx
@@ -0,0 +1,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'
+}
-- 
cgit v1.2.3-70-g09d2

