I’m building a video-player library for angular. Currently working on a Streamable integration.
I’ve recreated the situation in a StackBlitz, where you can see a console.warn for player.on('ready', ...) but not for fromEvent(player, 'ready').subscribe(...)
const player = new playerjs.Player(iframe);
player.on('ready', () => console.warn('player.on(ready)'));
fromEvent(player, 'ready').subscribe(() => console.warn('fromEvent ready'));
Does anyone know why fromEvent doesn’t work in this situation?
Similar examples (also using on):
I have to note that the same does actually work for Vidyard.
>Solution :
You could try to use the fromEventPattern function, which allows you to specify custom add and remove handler functions.
Example;
const addHandler = (handler) => player.on('ready', handler);
const removeHandler = (handler) => player.off('ready', handler);
fromEventPattern(addHandler, removeHandler).subscribe(() => console.warn('fromEventPattern ready'));
From the above, I use addHandler to adds a handler for the ‘ready’ event, and removeHandler that removes a handler. fromEventPattern uses these functions to create an Observable that emits events whenever the ‘ready’ event is fired.