I am experimenting with a scenario where I read the data, loop based on the duration. For example, starting with "Adam" first, play Adam for a 15-second timer, then move on to the next beginner "Andy" and play Andy for 15 seconds.
Once we reach group "intermediate," play "Fam" for 30s, then move to "Jamie" and play for 30s. Repeat for intermediate because the "play" count is 2. Once complete, move to the "expert" group.
let data = [{
"play": 1,
"name": "Adam",
"duration": 15,
"group": "beginner"
}, {
"play": 1,
"group": "beginner",
"name": "Andy",
"duration": 15
}, {
"duration": 30,
"play": 2,
"name": "Fam",
"group": "intermediate"
}, {
"name": "Jamie",
"group": "intermediate",
"duration": 30,
"play": 2
},
{
"duration": 45,
"play": 2,
"name": "Fam",
"group": "expert"
}, {
"name": "Jamie",
"group": "expert",
"duration": 45,
"play": 2
}];
destroy$: Subject<boolean> = new Subject<boolean>();
onStart() {
from(data).pipe(
takeUntil(this.destroy$),
concatMap(record => timer(0, record.duration * 1000).pipe(
map(i => data[i]))
))
.subscribe(data => {
this.currentItem = data;
});
}
ngOnDestroy() {
this.destroy$.next(true);
this.destroy$.unsubscribe();
}
Thank you for sharing your idea in advance!