Audiocontext in Tone.js and Vue.js

111 Views Asked by At

I am using Tone.js as a package in Vue.js. The tone import results in this warning message:

An AudioContext was prevented from starting automatically. It must be created or resumed after a user gesture on the page.

How can I prevent the audio autoload in the Tone import context?

<template>
    <div>
        <h3>Test</h3>
        <button @click="play()">Play</button>
    </div>
</template>

<script>
import { Oscillator } from 'tone'

export default {
    name: 'Test',
    created() {
        this.osc = new Oscillator(440, 'sine').toDestination()
    },
    data() {
        return {
            osc: null,
        }
    },
    methods: {
        play() {
            this.osc.start()
        }
    }
}
</script>
0

There are 0 best solutions below