I am attempting to incorporate an audio file into my vue.js project using the following code:
import sound from '../../recordings/sound.mp4'
const audio = new Audio(sound)
audio.play()
Although this method works perfectly fine, I have encountered a limitation where import
can only be used at the top level and not within a function that ideally should accept any audio file.
To address this issue, I tried an alternative approach:
const audio = new Audio('../../recordings/sound.mp4')
audio.play()
Unfortunately, this resulted in the following error message:
DOMException: Failed to load because no supported source was found
After researching this strange error, I came across a solution in this response: DOMException: Failed to load because no supported source was found
The answer suggested using the import statement, which brings me back to the initial challenge of it not being allowed within a function.
So my question remains: how can I dynamically play an audio file with vue.js?