can't make popcorn.js work

323 Views Asked by At

I think this is a very basic/dumb question but I can't understand what I'm doing wrong... I would like to add subtitles and a timeline to an html5 video using popcorn.js.

Here's the html5 code:

<script src="http://popcornjs.org/code/dist/popcorn-complete.js">
</script>
(...)
<nav id="timeline"> </nav>
(...)
<video id="video" controls>
        <source src="media/ita.webm" type="video/webm">
        <source src="media/ita.mp4" type="video/mp4">
</video>
(...)

Here's the popcorn part:

document.addEventListener( "DOMContentLoaded", function() {
  var popcorn = Popcorn('#video', { pauseOnLinkClicked: true });

  popcorn.timeline({
          start: 1,
          target: "timeline",
          title: "This is a title",
          text: "this is some interesting text that goes inside",
          innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>" ,
          direction: "down"
        })
        .timeline({
          start: 3,
          target: "#timeline",
          title: "double as interesting",
          text: "this is some interesting text that goes inside",
          innerHTML: "Maybe a button? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</button>",
          direction: "down"
        })
       .timeline({
          start: 7,
          end: 10,
          target: "#timeline",
          title: "3x as interesting",
          text: "this is some interesting text that goes inside",
          innerHTML: "",
          direction: "down"
        });

        popcorn.subtitle({
                start: 1,
                end: 5,
                text: "Subtitle",
            });

        popcorn.play();

}, false);

The pauseOnLinkClicked: true is the only part that's working...

1

There are 1 best solutions below

2
Jack Carlin On

Here's what you've posted working in action.

In your JS you had

target: "timeline"

set initially, but after you were setting

target: "#timeline"

on the next elements in the timeline array.

HTML:

<html>
    <head>
        <title>PopcornJS Test</title>
        <script src="http://popcornjs.org/code/dist/popcorn-complete.js"></script>
    </head>

    <body>
        <nav id="timeline"></nav>
        <video id="video" controls>
            <source src="http://www.w3schools.com/html/mov_bbb.mp4" type="video/webm">
            <source src="media/ita.mp4" type="video/mp4">
        </video>
    </body>
</html>

JS:

document.addEventListener("DOMContentLoaded", function() {
  var popcorn = Popcorn('#video', { pauseOnLinkClicked: true });

  popcorn.timeline({
          start: 1,
          target: "timeline",
          title: "This is a title",
          text: "this is some interesting text that goes inside",
          innerHTML: "Click here for <a href='http://www.google.ca'>Google</a>" ,
          direction: "down"
        })
        .timeline({
          start: 3,
          target: "timeline",
          title: "double as interesting",
          text: "this is some interesting text that goes inside",
          innerHTML: "Maybe a button? <button onClick=\"window.location.href='http://www.google.com'\">Click Me</button>",
          direction: "down"
        })
       .timeline({
          start: 7,
          end: 10,
          target: "timeline",
          title: "3x as interesting",
          text: "this is some interesting text that goes inside",
          innerHTML: "",
          direction: "down"
        });

        popcorn.subtitle({
            start: 1,
            end: 5,
            text: "Subtitle",
        });

        popcorn.play();

}, false);