This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function createHash() { | |
var text = ""; | |
var possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; | |
for (var i = 0; i < 32; i++) | |
text += possible.charAt(Math.ceil(Math.random() * possible.length)); | |
return text; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gulp.task('autoprefixer', function () { | |
var postcss = require('gulp-postcss'); | |
var sourcemaps = require('gulp-sourcemaps'); | |
var autoprefixer = require('autoprefixer'); | |
return gulp.src('./src/*.css') | |
.pipe(sourcemaps.init()) | |
.pipe(postcss([ autoprefixer() ])) | |
.pipe(sourcemaps.write('.')) | |
.pipe(gulp.dest('./dest')); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// webpack.config.js | |
module.exports = { | |
module: { | |
rules: [ | |
{ | |
test: /\.css$/, | |
use: ["style-loader", "css-loader", "postcss-loader"] | |
} | |
] | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8"> | |
<title>SoundWave</title> | |
<style> | |
canvas { | |
background-color: #101010; | |
width: 600px; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const | |
source = document.getElementById('source'), | |
player = document.getElementById('player'), | |
canvas = document.getElementById('visualizer'), | |
name = document.getElementById('song_name'), | |
format = document.getElementById('song_format'), | |
blob = window.URL || window.webkitURL, | |
color = ['#1abc9c','#2ecc71','#3498db','#9b59b6','#34495e','#16a085','#27ae60','#2980b9','#8e44ad']; | |
// Check if blob is exist in this browser |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Load song to player | |
source.addEventListener('change', (e) => { | |
let | |
file = e.target.files[0], | |
fileURL = blob.createObjectURL(file); | |
name.innerHTML = file.name; | |
format.innerHTML = file.type; | |
player.src = fileURL; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stream() { | |
const | |
audio = new(window.AudioContext || window.webkitAudioContext)(), | |
analyser = audio.createAnalyser(); | |
player.addEventListener('canplay', (e) => { | |
let source = audio.createMediaElementSource(player); | |
source.connect(analyser); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Prepare Canvas | |
const context = canvas.getContext('2d'); | |
// Draw wave | |
function draw() { | |
requestAnimationFrame(draw); | |
analyser.getByteFrequencyData(frequency); | |
context.fillStyle = '#101010'; | |
context.fillRect(0, 0, canvas.width, canvas.height); |
OlderNewer