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

131
Visualizações
Angular2 set audio currentTime in component

Below is the html content which creates HTML 5 audio element:

  <audio id ="audio2"controls="controls" autoplay="false" (canplay)="CanPlay($event)">
            <source src="http://localhost:51657/Audio/1" type="audio/mp3"> 
</audio>

Below is the component in which I am trying set the current time to some default value, the commented code is working fine, however please suggest how to do same thing the Angular2 way?.

    import { OnInit, Output,Component, Injectable, EventEmitter } from '@angular/core';
    declare let $: any;
@Component({
    selector: 'audio-tag',
  templateUrl: './audio-tag.component.html',
})

@Injectable()
export class AudioComponent implements OnInit {
 @Output() canplay: EventEmitter<any> = new EventEmitter();
   audio:any;
    playBtn: any;
    pauseBtn: any
    currentTime:any;
    timer:any;
    duration:any;

    sound: any;
    ngOnInit(): void {
//     $('#audio2').bind('canplay', function() {
//   this.currentTime = 20;
// });
          }       

    CanPlay(){
      console.log('canplay');        
      this.currentTime=10;
      this.audio.currentTime = 20;
    }
}
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

AudioComponent should be decorated with @Component({...}) not @Injectable()

@Component({
selector: 'my-audio-player',
 templateUrl: `
    <audio id ="audio2"controls="controls" autoplay="false" 
  (canplay)="CanPlay($event)">
        <source src="http://localhost:51657/Audio/1" type="audio/mp3"> 
 </audio>
`
}) 
export class AudioComponent implements OnInit { ... }
over 4 years ago · Santiago Trujillo 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