9

I am using Cincopa to embed my video into my website. The page that it is embedded in is hidden and navigation is removed. So I would like everyone to be redirected to the home page once the video is finished.

Here is my code:

<div id="cp_widget_55a42f1b-6e51-4738-87f9-eaf52dc6a826">...</div>
<script type="text/javascript">
    var cpo = [];
    cpo["_object"] = "cp_widget_55a42f1b-6e51-4738-87f9-eaf52dc6a826";
    cpo["_fid"] = "AsBAj2M3MQOr";
    var _cpmp = _cpmp || [];
    _cpmp.push(cpo);
    (function() {
        var cp = document.createElement("script");
        cp.type = "text/javascript";
        cp.async = true;
        cp.src = "//www.cincopa.com/media-platform/runtime/libasync.js";
        var c = document.getElementsByTagName("script")[0];
        c.parentNode.insertBefore(cp, c);
    })();
</script>
<noscript>Powered by Cincopa <a href='http://www.cincopa.com/video-hosting'>Video Hosting for Business</a> solution.<span>Test</span><span>bitrate</span><span> 39961 kb/s</span><span>height</span><span> 1080</span><span>duration</span><span> 00:02:35.31</span><span>lat</span>:<span> +33.2269</span><span>long</span>:<span> 21-96.93</span><span>fps</span><span> 59.94</span><span>width</span><span> 1920</span><span>originaldate</span><span> 2015-06-06 19:08:58</span>
</noscript>
Tripp Kinetics
  • 5,178
  • 2
  • 23
  • 37
  • Hey @Christopher Moore did you have any luck with this? – Asad Malik Aug 08 '17 at 16:44
  • "***This question has not received enough attention.***" because it already has many possible duplicates: [How can I redirect to a URL after a HTML video has ended?](https://stackoverflow.com/questions/20008778/how-can-i-redirect-to-a-url-after-a-html-video-has-ended) and [Redirect html5 video after play](https://stackoverflow.com/questions/10421471/redirect-html5-video-after-play) – Abhishek Pandey Aug 11 '17 at 08:41
  • any [Plunker](https://plnkr.co/edit/?p=preview) ? just paste the whole code there – Neji Soltani Aug 15 '17 at 12:22

4 Answers4

8

Cincopa embeds a video HTML tag, you have to add an event as explained here

Well, right now I'm not quite in the mood to make a complete test, so I'll just suggest a workaround which you will need to adapt.

In order to give you the exact code, I need to know:

  1. What CMS are you using?
  2. Can you add an id or a class to your video tag with cincopa?
  3. Are you including jQuery?

Then you'll have to add this lines in the bottom of your script:

//Wait until the page is entirely loaded, and so you can access the rendered video tag (you'll need jQuery)
$( document ).ready(function() {
    
    function goHomeYouAreDrunk(e) {
        window.location.href = "http://url.to.your.home.page";
    }
    //I'm supposing that your video is the sole video tag in your page, if it's not, you'll have to get it by its id or class
    document.find('video').addEventListener('ended',goHomeYouArDrunk,false);
});
Luis Sieira
  • 29,926
  • 3
  • 31
  • 53
  • Okay thank you. I guess maybe I am not quite understanding how to exactly do this or even where this needs to be placed in the code. Could you perhaps help me out here. – Christopher Moore Aug 13 '15 at 21:17
  • I'm not at home, but I'll try to edit the answer as soon as I come back – Luis Sieira Aug 13 '15 at 21:22
  • I would greatly appreciate your help. Thank you! – Christopher Moore Aug 13 '15 at 22:19
  • Okay, it's not in my top ten answers, but at least this should point you in the right direction. I'll complete it tomorrow when I'm sober... – Luis Sieira Aug 13 '15 at 23:02
  • Luis, I appreciate your help. I am using WIX and I can edit the CSS in Cincopa. I am not using jquery that I am aware of. CSS code is to long to paste in here. – Christopher Moore Aug 14 '15 at 00:12
  • Honestly , I didn't find the time to do it today. Did you try to add the code I shown you to the script you posted? Just incluye Jquery and give it à try. In any case, I'la give it à look tomarnos at 15h Gmt+1 – Luis Sieira Aug 14 '15 at 22:08
  • There's a typo in your example, it's missing a "e" in `goHomeYouAreDrunk`. – Etienne Martin Aug 15 '17 at 16:46
1

Normally, that would be via an event listener on the <audio> or <video> element.

How to add Event Listeners | W3Schools : https://www.w3schools.com/Jsref/met_element_addeventlistener.asp

But a way I'd do it with Javascript just to be sure is:

// The interval clocks every .1 second(s).
setInterval(function() {
    // If the element's current playback time is the playback duration (has reached the end).
    if (audioElement.currentTime == audioElement.duration)
        doSomething()
}, 100)

Although if you are wary about performance and don't want to use a setInterval() function, then stick with adding an event to the element.

By the way, to re-direct to another page, use the Javascript function location.assign("https://www.example.com.").

Lapys
  • 936
  • 2
  • 11
  • 27
1

This code has been tested in https://www.cincopa.com/:

document.getElementById("video_iframe_id_in_your_page")
    .contentWindow
    .document.getElementsByTagName("video")[0]
    .addEventListener("ended", function(args){
        window.open("/", "_top");
    });

wish can help you.

dexiang
  • 1,345
  • 16
  • 23
0

You can redirect to the home page by setting window.location="/"

I'm not sure how you're checking if the video has ended, you can add a listener like this.

Upon completion, you can call a handler function to redirect the user to the homepage.

document.getElementById('myVideo').addEventListener('ended',redirectToHomePage,false);

redirectToHomePage(){
   window.location = "/";
}
kotAPI
  • 1,073
  • 2
  • 13
  • 37