Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

354
Views
How to play audio file with vue.js

I'm trying to play an audio file in my vue.js project as such:

import sound from '../../recordings/sound.mp4'
const audio = new Audio(sound) 
audio.play()

This works perfectly well, but import may only appear at the top level - not within a function that would ideally accept any audio file.

Now I tried doing it this way:

const audio = new Audio('../../recordings/sound.mp4') 
audio.play()

But then I get this error:

DOMException: Failed to load because no supported source was found

I found a solution to this strange error in this answer: DOMException: Failed to load because no supported source was found

The solution was to use the import statement - but the issue is the the import statement can only be used at the top level - not within a function.

So how can I dynamically play an audio file with vue.js?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You can import your audio file inside a function using Dynamic Imports

(async () => {
  let sound = await import('../../recordings/sound.mp4');
  const audio = new Audio(sound);
  audio.play();
})();
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!