Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

147
Visualizações
playing audio in JavaScript from URL with variable

What I'm trying to make is a input that when you type the song name it plays. First what I tried was

function myFunction() {
  var id = document.getElementById("myInput").value;
var audio = 'https://bobzilla07.github.io/Music_Tap/' + id 
  var audio = new Audio ('audio');
 audio.play();

with the html code of

<input id="myInput" type="text">
<button onclick="myFunction()">play</button>

Which didn't work

so I though what if I made it so

function myFunction() {
var id = document.getElementById("myInput").value;
var audio = new Audio 'https://bobzilla07.github.io/Music_Tap/' + id;
audio.play();

to which is still didn't work. Does anybody have any idea on how to fix it so it works?

Edit: Im not good with json or even know what im doing btu would there be a possibilty to get the input from <input id="myInput" type="text"> <button onclick="myFunction()">play</button>

and put it in json to then call the audio from the link https://bobzilla07.github.io/Music_Tap/${song}.mp3 with ${song} being the input from the html input

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

I believe you have to pass the extension here as well. This does work because this server is CORS enabled.

form.addEventListener("submit", myFunction)
function myFunction(e) {
  e.preventDefault();
  audio.src = 'https://bobzilla07.github.io/Music_Tap/' + myInput.value + '.mp3';
  audio.play();
}
audio { display:none;}
<form id="form">
  <input id="myInput" value="Panic-Song">
  <input type="submit">
</form>
<audio controls id="audio"></audio>

Song list

about 4 years ago · Juan Pablo Isaza Relatório

0

You can do it like this:

let id = document.getElementById("myInput").value;
let audio = new Audio(`https://bobzilla07.github.io/Music_Tap/${id}.mp3`);
audio.play();

Now you can search for the file names of your songs. Like 1979 will play 1979.mp3.

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda