minhtai trinh
minhtai trinh

Reputation: 9

Angular 2 http request audio src not play

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>

Upvotes: 0

Views: 1246

Answers (1)

kemsky
kemsky

Reputation: 15261

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);
    }
}

Upvotes: 1

Related Questions