JSFiddle - React, Tailwind, and code Playground

by DeadByElpy

HTML

<p>click or drag</p>
<div dropzone>
  <img src="https://thebestcode.ru/media/audioProgress&Visualizer/plus.png" alt="#">
  <input type="file" accept="audio/*">
</div>
<canvas></canvas>

CSS

@font-face {
  font-family: "Nova Mono", monospace;
  src: url("https://thebestcode.ru/media/audioProgress&Visualizer/font.ttf");
}

* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  height: 100vh;
  background: radial-gradient(circle, #666, #222);
  display: flex;
  justify-content: center;
  align-items: center;
}

p {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -70px);
  color: #ddd;
  text-align: center;
  text-transform: uppercase;
  font-family: "Nova Mono", monospace;
  font-size: 0.8em;
  font-weight: bold;
  letter-spacing: 2px;
  user-select: none;
}

span {
  display: block;
  font-size: 1.6em;
}

div {
  width: 100px;
  height: 100px;
  display: flex;
  justify-content: center;
  align-items: center;
  border: 1px dashed #ddd;
  border-radius: 10%;
  cursor: pointer;
}

img {
  width: 70px;
  height: 70px;
  filter: invert();
}

input {
  display: none;
}

canvas {
  display: none;
}

JavaScript

window.onload = () => {
  let dropZone = document.querySelector("div"),
    input = document.querySelector("input"),
    file,
    text,
    progress,
    volume,
    audio,
    frequencyArray;

  dropZone.ondrop = e => {
    e.preventDefault();

    if (e.dataTransfer.items[0].kind == "file") {
      file = e.dataTransfer.items[0].getAsFile();
    } else return;

    playTrack(file);
  };

  dropZone.ondragover = e => {
    e.preventDefault();
  };

  dropZone.onclick = () => {
    input.click();
    input.onchange = () => {
      file = input.files[0];

      playTrack(file);
    };
  };

  let C = document.querySelector("canvas"),
    $ = C.getContext("2d"),
    W = (C.width = innerWidth),
    H = (C.height = innerHeight),
    centerX = W / 2,
    centerY = H / 2,
    radius,
    piece,
    bars = 200,
    x,
    y,
    xEnd,
    yEnd,
    barWidth = 2,
    barHeight,
    lineColor;

  function playTrack(file) {
    dropZone.style.display = "none";

    text = document.querySelector("p");

    text.style.transform = "translate(-50%,-50%)";

    text.innerHTML = `progress: <span class="progress"></span> <br> volume: <span class="volume"></span>`;

    volume = document.querySelector(".volume");

    progress = document.querySelector(".progress");

    document.addEventListener("keydown", e => {
      try {
        if (e.keyCode == 32) {
          audio.paused ? audio.play() : audio.pause();
        } else if (e.keyCode == 13) {
          audio.load();
        } else if (e.keyCode == 39) {
          audio.currentTime += 10;
        } else if (e.keyCode == 37) {
          audio.currentTime -= 10;
        } else if (e.keyCode == 40) {
          audio.volume -= 0.1;
        } else if (e.keyCode == 38) {
          audio.volume += 0.1;
        }
      } catch {
        return;
      }
    });

    console.log(
      "Use Keyboard: \n Space to Play/Pause \n Enter to Stop \n Arrows to Change \n Time and Volume"
    );

    audio = new Audio();
    context = new...