Socket
Socket
Sign inDemoInstall

vue2-audio-visual

Package Overview
Dependencies
15
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    vue2-audio-visual

Vue audio visualization components


Version published
Weekly downloads
219
decreased by-37.43%
Maintainers
1
Install size
13.0 MB
Created
Weekly downloads
 

Readme

Source

vue-audio-visual

Build Status codecov Codacy Badge MIT npm

Vue HTML5 audio visualization components

Overview

An audio spectrum visualizer plugin for VueJS framework. It is built with HTML5 Web Audio API and compatible with all browsers that support HTML5 audio API. It provides several Vue components that allows to draw light and nice visualization for "audio" HTML elements.

There is a DEMO available.

Component AvLine. Vue template name <av-line>

    <av-line
      :line-width="2"
      line-color="lime"
      audio-src="/static/music.mp3"
    ></av-line>

This will create following element:

AvLine Intro

Component AvBars. Vue template name <av-bars>

    <av-bars
      caps-color="#FFF"
      :bar-color="['#f00', '#ff0', '#0f0']"
      canv-fill-color="#000"
      :caps-height="2"
      audio-src="/static/bach.mp3"
    ></av-bars>

This will create following element:

AvBars Intro

Component AvCircle. Vue template name <av-circle>

    <av-circle
      :outline-width="0"
      :progress-width="5"
      :outline-meter-space="5"
      :playtime="true"
      playtime-font="18px Monaco"
      audio-src="/static/bach.mp3"
    ></av-circle>

This will create following element:

AvCircle Intro

Component AvWaveform. Vue template name <av-waveform>

    <av-waveform
      audio-src="/static/bar.mp3"
    ></av-waveform>

This will create following waveform element:

AvWaveform Intro

Component will pre-load audio content and generate clickable waveform.

Component AvMedia. Vue template name <av-media>

    <av-media
      :media="mediaObject"
    ></av-media>

This will create following media element:

AvMedia Intro

Install and setup

Install using npm

npm install --save vue-audio-visual

Enable plugin in main.js:

import Vue from 'vue'
import AudioVisual from 'vue-audio-visual'

Vue.use(AudioVisual)

Example of usage in App.vue or any other Vue component:

  <av-bars
    audio-src="/static/bach.mp3">
  </av-bars>

API

There are three components that comes with plugin: av-line, av-bars, av-circle.

There are a lot of props available to configurate each component. The only mandatory "prop" to pass to component: audio-src. Prop audio-src value should contain URL to media file. Example:

audio-src="http://example.com/media/song.mp3"

Plugin will generate "audio" to control media playback and "canvas" element for visualization.

Another way is to link to existing Vue element using "ref-link" property. When "ref-link" property is set, then "audio-src" property is ignored.

<audio ref="foo" src="music.mp3"></audio>
<av-bars ref-link="foo" />
<av-line ref-link="foo" />

However, it will reference only parent component elements.

There are props that are common for all components and special props for each component.

Common props

NameTypeDefaultDescription
audio-srcStringnull Audio element src attribute. When provided creates audio element wrapped in "div".
ref-linkStringnull Reference to parent audio element via Vue "ref" attribute. When set, then local audio element is not created and the plugin will connect audio analyser to parent audio element. Multiple plugin instances can connect to the same audio element (see example above).
audio-controlsBooleantrue Audio element controls attribute. When provided should display audio element with controls.
cors-anonymBooleanfalse Set CORS attribute for audio element. Set this attribute when using audio source is pointing to different host/domain. When set, parameter crossOrigin of audio element will be set to 'anonymous'.
audio-classStringnullAudio element css class name.
canv-classStringnullCanvas element css class name.
canv-topBooleanfalseBy default plugin creates "audio" element wrapped in "div" and puts "canvas" element below. When "canv-top" is "true" then "canvas" element is set on top. Example: :canv-top="true" or v-bind:canv-top="true"
canv-fill-colorStringnullCanvas fill background RGB color. Default is null, which makes background transperent. Examples:
canv-fill-color="#00AAFF"

AvLine props

NameTypeDefaultDescription
canv-widthNumber300Canvas element width. Default 300. Example: :canv-width="600"
canv-heightNumber80Canvas element height. Default 80. Example: :canv-height="120"
line-widthNumber2Graph line width in px. Integer or float number. Example: :line-width="0.5"
line-colorString, Array#9F9Graph line color. Can be string RGB color or Array of RGB color. When Array is given, plugin creates linear gradient and set it as background. Array value should be binded. Examples:
line-color="#00AAFF"
:line-color="['#FFF', 'rgb(0,255,127)', '#00f']"
fft-sizeNumber128Represents the window size in samples that is used when performing a Fast Fourier Transform (FFT) to get frequency domain data.
Must be power of 2 between 25 and 215. Example: :fft-size="512"

AvBars props

NameTypeDefaultDescription
canv-widthNumber300Canvas element width. Default 300. Example: :canv-width="600"
canv-heightNumber80Canvas element height. Default 80. Example: :canv-height="120"
bar-widthNumber5Width of bars in pixels. Example: :bar-width="12"
bar-spaceNumber1Space between bars. Example: :bar-space="1.6"
bar-colorString, Array#0A0AFFBar fill color. Can be string RGB color or canvas gradients array.
Examples:
bar-color="#00AAFF"
:bar-color="['#FFF', 'rgb(0,255,127)', 'green']"
caps-heightNumber0Create caps on bars with given height in pixels. When zero no caps created. Example: :caps-height="2"
caps-drop-speedNumber0.9Caps drop down animation speed. The higher nubmer the faster caps are going down. Example: :caps-drop-speed="0.5"
caps-colorString#A0A0FFCaps rectangles RGB color. Example: caps-color="lime"
brick-heightNumber0Draw bar as bricks when height is set and not zero.
Example: :brick-height="6"
brick-spaceNumber1Space between bricks. Example: :brick-space="2"
symmetricBooleanfalseDraw bars symmetric to canvas vertical center. Example: :symmetric="true"
fft-sizeNumber1024Represents the window size in samples that is used when performing a Fast Fourier Transform (FFT) to get frequency domain data.
Must be power of 2 between 25 and 215. Example: :fft-size="2048"

AvCircle props

NameTypeDefaultDescription
canv-widthNumber100Canvas element width. Example: :canv-width="600"
canv-heightNumber100Canvas element height. Example: :canv-height="120"
radiusNumber0Base circle radius. If zero, then will be calculated from canvas width: (canv-width / 2) * 0.7 Example: :radius="20"
line-widthNumber1Frequency bit line width to draw. Example: :line-width="0.4"
line-spaceNumber1Space between lines to draw. Example: :line-space="2"
outline-colorString#0000FFOutline (contour) style RGB color. Example: outline-color="rgb(0,255,0)"
outline-widthNumber0.3Outline (contour) line width. Float value. Example: :outline-width="1"
bar-widthNumber1Frequency graph bar width. Example: :bar-width="1"
bar-lengthNumber0Frequency graph bar length/height. Default is a difference between radius and canvas width. Example: :bar-length="27"
bar-colorString, Array[#FFF,#00F]Bar style RGB color or radient gradient when array. Example: :bar-color="#12AA55"
progressBooleantrueDraw playtime progress meter. Example: :progress="false"
progress-widthNumber1Playtime progress meter width. Example: :progress-width="2.4"
progress-colorString#0000FFPlaytime progress meter color. Example: :progress-color="green"
progress-clockwiseBooleanfalsePlaytime progress meter arc draw direction. Example: :progress-clockwise="true"
outline-meter-spaceNumber3Space between outline and progress meter. The bigger the closer to the circle centre. Example: :outline-meter-space="1"
playtimeBooleanfalseDraw played time as text in the center of the circle. Example: :playtime="true"
playtime-fontString14px MonacoPlayed time print font. Example: playtime-font="18px monospace"
playtime-colorString#00fPlayed time font color. Example: playtime-color="green"
rotate-graphBooleanfalseRotate graph clockwise enable. Example: :rotate-graph="true"
rotate-speedNumber0.001Rotate graph speed. Example: :rotate-speed="0.2"
fft-sizeNumber1024Represents the window size in samples that is used when performing a Fast Fourier Transform (FFT) to get frequency domain data.
Must be power of 2 between 25 and 215. Example: :fft-size="2048"

AvWaveform props

NameTypeDefaultDescription
canv-widthNumber100Canvas element width. Example: :canv-width="500"
canv-heightNumber80Canvas element height. Example: :canv-height="120"
played-line-widthNumber0.5Waveform line width for played segment of audio. Example: :playtime-line-width="0.8"
played-line-colorStringnavyWaveform line color for played segment of audio. Example: :playtime-line-color="#ABC123"
noplayed-line-widthNumber0.5Waveform line width for not yet played segment of audio Example: :noplayed-line-width="1"
noplayed-line-colorStringlimeWaveform line color for not yet played segment of audio. Example: :noplayed-line-color="grey"
playtimeBooleantrueDisplay played time next to progress slider. Example: :playtime="false"
playtime-with-msBooleantrueDisplay milliseconds in played when true. For example: 02:55.054. Example: :playtime-with-ms="false"
playtime-font-sizeNumber12Played time print font size in pixels. Example: :playtime-font-size="14"
playtime-font-familyStringmonospacePlayed time print font family. Example: :playtime-font-family="monaco"
playtime-font-colorStringgreyPlayed time print font RGB color string. Example: :playtime-font-color="#00f"
playtime-text-bottomBooleanfalsePosition playtime text bottom. Default on top. Example: playtime-text-bottom
playtime-sliderBooleantrueDraw played time slider on the waveform. Example: :playtime-slider="false"
playtime-slider-colorStringredPlayed slider color. Example: :playtime-slider-color="#fafafa"
playtime-slider-widthNumber1Played slider width. Example: :playtime-slider-width="2.5"
playtime-clickableBooleantrueAllow click on waveform to change playtime. Example: :playtime-clickable="false"
requesterObjectnew axios instanceAllow set a custom requester (axios/fetch) to be used. Example: :requester="myCustomRequesterInstance"

AvMedia props

Please note that common pros are not usable for that element.

Vue component example with media from user device.

<template>
  <audio ref="player" controls />
  <av-media :media="media" />
</template>
<script>
export default {
    name: 'HelloWorld',
    data() {
        return {
            media: null
        }
    },
    mounted () {
      const constraints = { audio: true, video: false }
      navigator.mediaDevices.getUserMedia(constraints).
        then(media => {
          this.media = media
          this.$refs.player.srcObject = media
        })
    }
}
</script>
NameTypeDefaultDescription
mediaMediaStreamnoneRequired property. See example above.
canv-widthNumber300Canvas element width. Default 300. Example: :canv-width="600"
canv-heightNumber80Canvas element height. Default 80. Example: :canv-height="120"
canv-classStringnullCanvas element css class name.
typeStringwformType of media visualization. Currently supplies two types: 'wform', 'circle' and 'frequ'. If not set or not recognized then 'wform' is set.
Example: :type="frequ"
fft-sizeNumber1024/8192Represents the window size in samples that is used when performing a Fast Fourier Transform (FFT) to get frequency domain data. Default 8192 for the type 'wform' or 1024 for 'frequ'
Example: :fft-size="512"
frequ-lnumNumber60Number of vertical lines for 'frequ' type. Example: :frequ-lnum="30"
frequ-line-capBooleanfalseDraw lines of 'frequ' type with rounded caps. Example: :frequ-line-cap="true"
line-colorString#9F9Graph line RGB color. Examples:
line-color="#00AAFF"
line-widthNumber0.5 / 3Graph line width in px. Integer or float number. If not set then 0.5 for 'wform' type and 3 for 'frequ' Example: :line-width="0.8"
radiusNumber0Base 'circle' radius. Example: :radius="4"
connect-destinationBooleanfalseAnalyser to connect to audio context's destination. Avoid echo during playback. Example: :connect-destination="true"

License

MIT Copyright (c) 2018-present, Stas Kobzar

Keywords

FAQs

Last updated on 01 Oct 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc