I’m getting the error below when I try to call .consent() method on Clappr’s player in an Angular application:
core.mjs:6494 ERROR TypeError: Cannot read properties of undefined (reading 'getCurrentPlayback')
at Player.consent (clappr.js:7580:19)
at LiveEmbutidaComponent.ativarNovoPlayer (live-embutida.component.ts:176:27)
at Object.next (live-embutida.component.ts:256:18)
at ConsumerObserver.next (Subscriber.js:91:1)
at SafeSubscriber._next (Subscriber.js:60:1)
at SafeSubscriber.next (Subscriber.js:31:1)
at OperatorSubscriber._next (Subscriber.js:60:1)
at OperatorSubscriber.next (Subscriber.js:31:1)
at map.js:7:1
at OperatorSubscriber._next (OperatorSubscriber.js:13:1)
I think the problem isn’t exactly .consent(), because after .consent() I do a .stop() and then a .load(). If I remove any, the error persist only with different vars on ‘reading’ message.
The problem is that I use this exact same code successfully for some years now in production. I just went to do a new page, copied the old code and it’s not working. The difference is that in the old page all the components are loaded then I call the methods that play the stream and in this new page, the page is loaded at user discretion and I tell the player te correct url on page load.
I’ve checked if the parentId’s div is already loaded by DOM and it is. Link is also correct. I’m not really sure where is the undefined Clapper is complaining…
code:
activateNewPlayer() {
if (!this.clapprPlayer) return;
console.log('activateNewPlayer', this.clapprPlayer); //<-- fine, dumps instance
let link = this.chooseLink();
if (link == this.link) return;
console.log('anp0', this.link); //<-- fine, correct link
this.link = link;
this.clapprPlayer.consent(); //<-- error here
this.cancelEnding = true;
this.clapprPlayer.stop(); //<-- or here if I remove .consent()
this.clapprPlayer.options.loop = link == this.linkLoading;
if (this.link == this.linkLoading && this.currentSchedule.openingImage) {
this.clapprPlayer.getContainerPlugin('poster').load(this.agendamentoAtual.openingImage)
} else {
this.clapprPlayer.load(this.link, '', true); //<-- or here if I remove .consent() and .stop()
}
this.deactivatePlayButtonAndErrorScreen();
}
The player’s instance is created in another method, this one:
createNewPlayer() {
if (this.clapprPlayer) return;
console.log('createNewPlayer', document.querySelector('#playerEmbeddedLive')); // <-- fine, dumps div
this.link = this.chooseLink();
console.log('link', this.link); // <-- correct link
let poster = this.currentSchedule.openingImage ? this.currentSchedule.openingImage : null;
try {
this.clapprPlayer = new Clappr.Player({
source: this.link,
parentId: "playerEmbeddedLive",
autoPlay: !this.currentSchedule.openingImage,
loop: this.link == this.linkLoading,
poster,
events: {
onError: this.stopMonitoring.bind(this, 'onError'),
onStop: this.stopMonitoring.bind(this, 'onStop'),
onEnded: this.stopMonitoring.bind(this, 'onEnded'),
onPause: this.stopMonitoring.bind(this, 'onPause'),
onPlay: this.stopMonitoring.bind(this),
onSeek: this.onSeek.bind(this)
}
});
} catch (e) {
console.log('error', e);
}
}
Any ideas ?