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

218
Visualizações
loading local file in <audio> tag working alternately

I need to load local audio file into <audio> tag.

I did it with the following code.

Let the user choose a file with:

<ion-input type="file" (change)="laodLocalFile($event)">

Prepare it for <audio> tag:

laodLocalFile(event: any)
{    
  file_url = URL.createObjectURL(event.target.files[0]);
  document.getElementById('audio_file').setAttribute("src", file_url);
}

And use it as following:

<audio id="audio_file" type="audio/mpeg" controls></audio>

I tried it with several different mp3 files. It worked several times, but most of the times it didn't work, without any warning or error.

What can be the issue?

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

0

You need to use domeSanitizer and bypassSecurityTrustUrl() this method bypass security and trust the given value to be a safe style URL, i.e. a value that can be used in hyperlinks or src

constructor(private domSanitizer:DomSanitizer) {    }

And in your method: ...

this.mediaSrc = this.domSanitizer.bypassSecurityTrustUrl(file_url);
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