1

I included the viostream api js library on the head of my project, so I can use the object viostreamPlayer in js file:

<head>
  ...
  <script src='https://publish.viostream.com/embed/api'></script>
</head>

I need to call embed function twice in js and without reloading page. However, the second time to use the viostreamPlayer would cause some problem.

Therefore, I would like to reload the api library before the second use. To make sure the viostreamPlayer object fresh and ready to use.


More details:

I use the backbone.js to load the video view in the page, and after another video view loaded by js, I should update the video content. That's why I need to call embed function twice, which is to load another video. The new video is successfully embedded, but all the event handler failed. Load page by js cannot reload the head.

The event handler is added by calling on method with viostreamPlayer:

viostreamPlayer.on('play', function(){})

But its out of work when I embedded the second video. That's why I am looking for the method to make sure the viostreamPlayer fresh before calling embed function.

Documentation: https://help.viostream.com/hc/en-us/articles/223291607-Embedding-and-using-the-Player-API

Cheers

Update

ViostreamPlayer has updated the api so the error is no longer existing.

Stephen
  • 3,822
  • 2
  • 25
  • 45
  • "However, the second time to use the viostreamPlayer would cause some problem.". What exactly is the problem? – Charlie Fish Jul 26 '17 at 05:19
  • Hi @CharlieFish, I explained in the `More details`, the problem is all the event listeners cannot be set correctly and out of work – Stephen Jul 26 '17 at 05:32
  • Have you tried contacting their support? Looks like a paid product. They should offer support. I'm not sure why you need to reload a script. Sounds more like a problem in their script. – Charlie Fish Jul 26 '17 at 05:34
  • @CharlieFish, yeah that's the other option, it's already under contact, but I am still trying to find any possible solution on my side. – Stephen Jul 26 '17 at 05:45
  • Yeah, I'm not sure. I could be wrong but truly sounds like a problem in their script. – Charlie Fish Jul 26 '17 at 05:46
  • Yeps, it should be a design issue in their script. But based on the current script, the only way to do it reload the `script` in the `head`. You know that reloading the whole page didn't cause this problem, cos it reload the `head` part. – Stephen Jul 26 '17 at 05:49
  • That's why I am looking for the way to reload the script library by js @CharlieFish – Stephen Jul 26 '17 at 05:50
  • Yeah, and I just don't think that is possible. Could be wrong tho. – Charlie Fish Jul 26 '17 at 05:53
  • What about this solution https://stackoverflow.com/questions/9642205/how-to-force-a-script-reload-and-re-execute – hsd Jul 30 '17 at 13:16

1 Answers1

0

If you are using jQuery you can use $.getScript() to reload.

Example:

setTimeout(() => {
    $.getScript("https://publish.viostream.com/embed/api?1")
        .done(function (script, textStatus) {
            console.log(textStatus);
        })
        .fail(function (jqxhr, settings, exception) {
            console.log.("Triggered ajaxError handler.");
        });
}, 1000);
qzb
  • 8,163
  • 3
  • 21
  • 27
  • Thanks for your answer @Arunesh Saxena. However, I found that `getScript` function cannot reload the script. For example, this js will include a object `viostreamPlayer`, and add a `delete viostreamPlayer` before `getScript` method, you could see it wouldn't create the object again – Stephen Jul 27 '17 at 02:58