0

I obtained data on and attached to the audio src but it does not run.

detail.component.ts

export class DetailComponent implements OnInit {
    @Input() detailName: string;
    @Output("playnhac") play = new EventEmitter();
     private linkmp3:string;
    constructor(private _http:Http) {

    }
ngOnInit() {
                    this._http.get('http://searchsong.azurewebsites.net/api/mp3File/'+this.detailName+'&type=128&key=minhtaitr')
        .map(res => res.json())
        .subscribe(
          data => {this.linkmp3=data

        })

        }

detail.component.html

<audio controls>

  <source type="audio/mpeg" src="{{linkmp3}}" >

</audio>
5
  • do you receive http response? Commented Dec 25, 2016 at 8:38
  • yes , url correctly but will not turn on Commented Dec 25, 2016 at 8:48
  • try [src] = "linkmp3" and make it public linkmp3 Commented Dec 25, 2016 at 9:00
  • I have tried but not effective Commented Dec 25, 2016 at 9:09
  • @raj no need to add public , if you are using that variable within the same class/template you can use private too. Commented Apr 6, 2017 at 17:39

1 Answer 1

1

You should not use interpolation in attributes, instead [attr.src]="...". Also you will not be able to set this attribute without this pipe:

@Pipe({
    name: 'safe',
    pure: true
})
export class SafePipe implements PipeTransform
{
    private sanitizer:DomSanitizer;

    constructor(sanitizer:DomSanitizer)
    {
        this.sanitizer = sanitizer;
    }

    transform(url)
    {
        return this.sanitizer.bypassSecurityTrustResourceUrl(url);
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

tks. it's great hint
may i know whats the need of this pipe in playing audio ? also better please if you provide any workling example something like plunker.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.