i create a function for stram audio in angular :
private streamObservable(url) {
new Observable(observer => {
// Play audio
this.audioObj.src = url;
this.audioObj.load();
this.audioObj.play();
const handler = (event: Event) => {
observer.next(event);
};
this.addEvents(this.audioObj, this.audioEvents, handler);
return () => {
// Stop Playing
this.audioObj.pause();
this.audioObj.currentTime = 0;
// remove event listeners
this.removeEvents(this.audioObj, this.audioEvents, handler);
};
});
}
and when i need to using that function it show me error :
function use :
playStream(url) {
return this.streamObservable(url).pipe(takeUntil(this.stop$));
}
and show this error :
Property 'pipe' does not exist on type 'void'.
whats the problem ???how can i solve this problem ???
i create a function for stram audio in angular :
private streamObservable(url) {
new Observable(observer => {
// Play audio
this.audioObj.src = url;
this.audioObj.load();
this.audioObj.play();
const handler = (event: Event) => {
observer.next(event);
};
this.addEvents(this.audioObj, this.audioEvents, handler);
return () => {
// Stop Playing
this.audioObj.pause();
this.audioObj.currentTime = 0;
// remove event listeners
this.removeEvents(this.audioObj, this.audioEvents, handler);
};
});
}
and when i need to using that function it show me error :
function use :
playStream(url) {
return this.streamObservable(url).pipe(takeUntil(this.stop$));
}
and show this error :
Property 'pipe' does not exist on type 'void'.
whats the problem ???how can i solve this problem ???
Share Improve this question asked Aug 16, 2020 at 6:42 kianoush dortajkianoush dortaj 4519 silver badges28 bronze badges2 Answers
Reset to default 5You need to return the observable from the called function.
Like - return new Observable (observer => {
private streamObservable(url) {
return new Observable(observer => {
// Play audio
this.audioObj.src = url;
this.audioObj.load();
this.audioObj.play();
const handler = (event: Event) => {
observer.next(event);
};
this.addEvents(this.audioObj, this.audioEvents, handler);
return () => {
// Stop Playing
this.audioObj.pause();
this.audioObj.currentTime = 0;
// remove event listeners
this.removeEvents(this.audioObj, this.audioEvents, handler);
};
});
}
The solution for me was a pretty simple mistake, in my case I was returning an observable but I wasn't calling the method properly. I was missing the ()
in the method call.
Original Code
this.service.method.pipe().subscribe();
Fixed Code
this.service.method().pipe().subscribe();