Im using Angular 8 and Typescript
Problem: i want an array to have the same length as the music source of an audio tag, to enable comments that are synchronized with the intended location in the track. Similar as soundcloud.
Technical approach:
I have an audio tag with one audiofile in it. this got a duration i can access with this.audioplayer.duration
now i have an array, public comments = [] which i want to be the same length as the track duration
<div *ngFor="let comment of comments">
</div>
to sync them, i tried
ngAfterViewInit() {
this.comments.length= this.audioplayer.duration }
but im getting invalid array length. Is there a way to make this work?
this.comments = new Array(this.audioplayer.duration)orthis.comments = Array.from({length: this.audioplayer.duration})or any of the other suggestions there. How, specifically, is the other answer not suitable?durationproperty returns a double-precision floating-point value, which means your duration could be189.21which should be rounded to a whole number.