Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

89. Add support for <video>

This also enables controls for the video tag, it seems before videos
embedded like this were at least unusable in Chrome.
We check every 500ms if the metadata of the video has been retrieved
before trying to seek to a specific time.
  • Loading branch information...
commit 91a448b97fe4d0ddc20024dd2a707bfd35ecac47 1 parent d0ba78c
Reiner Gerecke authored
17 apps/videos/static/videos/js/videos.js
@@ -43,3 +43,20 @@ function UnisubsSeekVideo(time) {
43 43 var w = unisubs.widget.Widget.getAllWidgets()[0];
44 44 w.playAt(time);
45 45 }
  46 +
  47 +// Seek to specified time in the video and start playing.
  48 +function HTML5SeekVideo(time) {
  49 + var v = document.getElementsByTagName("video")[0];
  50 +
  51 + function waitForMetadata() {
  52 + if (v.readyState >= 1) {
  53 + v.currentTime = time;
  54 + v.play();
  55 + return;
  56 + }
  57 +
  58 + setTimeout(waitForMetadata, 500);
  59 + }
  60 +
  61 + waitForMetadata();
  62 +}
10 apps/videos/templates/videos/video_display.html
@@ -39,7 +39,7 @@
39 39 {% elif v.embed %}
40 40 {{ v.embed|safe }}
41 41 {% else %}
42   - <video id="{{ v.slug }}">
  42 + <video id="{{ v.slug }}" controls>
43 43 {% if v.video_ogv_url %}
44 44 <source src="{{ v.video_ogv_url }}" type="video/ogg">
45 45 {% endif %}
@@ -53,6 +53,14 @@
53 53 <source src="{{ v.video_flv_url }}" type="video/x-flv">
54 54 {% endif %}
55 55 </video>
  56 + <script type="text/javascript" src="{{ settings.STATIC_URL }}videos/js/videos.js"></script>
  57 + <script type="text/javascript">
  58 + var config = parseLocationHash();
  59 +
  60 + if (typeof(config.t) !== "undefined") {
  61 + HTML5SeekVideo(parseTime(config.t));
  62 + }
  63 + </script>
56 64 {% endif %}
57 65 </div>
58 66 {% endmacro %}

0 comments on commit 91a448b

Please sign in to comment.
Something went wrong with that request. Please try again.