Giter Club home page Giter Club logo

audio-visualizer's Introduction

Audio Visualizer

Vanilla JS

IMPORTANT: Please don't use this code out of the box (copy & paste) in production without testing it. It's been quite some time since I wrote this, and it's been written only as an example code, which you'll probably need to modify for your project's needs. Many things have changed, both in JavaScript rules and browser / mobile security rules.

Purpose of this code is to serve as a guideline to start using Web Audio API.

Description:

Web Audio experiment for audio visualization on canvas.

visualizer

Install via bower

$bower install --save-dev audio-visualizer

Usage

Include visualizer script in your index.html

    <script src="visualizer.js"></script>

Include audio and canvas HTML elements.

    <div>
        <audio id="myAudio" src="path/to/source/audio/" data-author="insert/author/name" data-title="insert/audio/name"></audio>
        <canvas id="myCanvas" width="800" height="400"></canvas>
    </div>

Note: For visualizer to render audio and author names you'll have to set data-author and data-title attributes on your audio element.

Create Visualizer instance.

    AUDIO.VISUALIZER.getInstance({
        audio: 'myAudio',
        canvas: 'myCanvas',
    });

Options

audio (String) (required)

    Audio element's ID selector.

canvas (String) (required)

    Canvas element's ID selector.

autoplay (Boolean)

    Auto-start visualizer.

loop (Boolean)

    Sets visualizer auto-replay option.

style (Boolean)

    Sets canvas rendering visualization style. Currently only 'lounge' style is supported.

barWidth (Integer)

    Sets bar's width in pixels.

barHeight (Integer)

    Sets initial bar's height in pixels (when there's no visualization).

barSpacing (Integer)

    Sets spacing between bars in pixels.

barColor (String) - '#cafdff'

    Sets HEX value as bar's color.

shadowBlur (Integer)

    Sets value as bar's shadow blur.

shadowColor (String) - '#ffffff'

    Sets HEX value as bar's shadow color.

font (Array) - ['12px', 'Helvetica']

    Sets font size and font type.

CSS Styles

Style by your own preference or you can use my styles.

<div class="vz-wrapper">
    <audio id="myAudio" src="path/to/source/audio" data-author="insert/author/name" data-title="insert/audio/name"></audio>

    <div class="vz-wrapper -canvas">
        <canvas id="myCanvas" width="800" height="400"></canvas>
    </div>
</div>
body {
    margin: 0;
}

.vz-wrapper {
    position: relative;
    height: 100vh;
    width: 100%;
    background: -webkit-gradient(radial, center center, 0, center center, 460, from(#396362), to(#000000));
    background: -webkit-radial-gradient(circle, #396362, #000000);
    background: -moz-radial-gradient(circle, #396362, #000000);
    background: -ms-radial-gradient(circle, #396362, #000000);
    box-shadow: inset 0 0 160px 0 #000;
    cursor: pointer;
}

.vz-wrapper.-canvas {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    height: initial;
    width: initial;
    background: transparent;
    box-shadow: none;
}

@media screen and (min-width: 420px) {
    .vz-wrapper {
        box-shadow: inset 0 0 200px 60px #000;
    }
}

Live preview

audio-visualizer's People

Contributors

davidlazic avatar lazicdavid avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

audio-visualizer's Issues

Volume Control and etc...

Hi
thanks for this great plugin, i've been looking for it like forever!
but there is one problem or maybe multiple problems!
one of them id how can i control the volume when user clicks on a button?
i tried gainNode but when the gainNode is set, it's set forever and i can't change it while audio is playing.
another problem is how can i change the song when a button is pressed ?

I can't change volume

I wanted to add an input range to adjust the audio volume, but from what I see the audio is handled in the script. What value should I change for the volume?

Cannot read property 'setAnalyser' of undefined

Hi, I had an issue, but solved it since then ... but I was not able to 'remove' this comment. So therefore, the only thing that is left for me to do is to thank you for your beautifully designed visual element!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.