From b89147ecd38b0f95a2e4917aba7f44bf3bb70327 Mon Sep 17 00:00:00 2001
From: Jules Laplace <julescarbon@gmail.com>
Date: Fri, 7 Jul 2017 18:43:24 +0200
Subject: refactor audioplayer

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

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

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

