Calling JS API functions when jwplayer is defined
I have a custom script that loads JWPlayer JS API functions to enhance our users video experience.
The issue I am having is that this script loads on every page of our website (in wordpress) and on those pages where JWPlayer is not embedded it keeps throwing errors:
Uncaught TypeError: jwplayer(...).on is not a function
The script I am talking about is here: https://www.visualsp.com/wp-content/themes/VisualSP/js/player.js
IS there a way to defer executing of the code in this script until we know JW Player is required and loaded on the page?