[TW5]Setting currentTime in a video with a macro

25 views
Skip to first unread message

FrD

unread,
Jul 23, 2015, 1:02:18 PM7/23/15
to TiddlyWiki
Hi,

I want to include a video in a tiddler with the video html tag (the video is a local file).
And I want to change the currentTime attribute of the video element so that the video starts at  a precise time.
But I don't want to use the start time (or end time) that one can put at the end of the src attribute (at least in Firefox), because I want to be able to go to a previous time if I need some context. And specifying a start time doesn't allow that.

So I created a js macro to do the job and I'm pretty sure it's not the right way to go because macros should'nt have side-effects. But it works !

Here is the macro :


/*\
title: gotoTime.js
type: application/javascript
module-type: macro

<<gotoTime id time>>

\*/

(function(){

/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";

/*
Information about this macro

*/


exports
.name = "gotoTime";

exports
.params = [
{ name: "id" },
{ name: "time" }
];

/*
Run the macro
*/

exports
.run = function(id, time) {
   
var myVid = document.getElementById(id);
    myVid
.addEventListener("canplay",function() { myVid.currentTime = parseInt(time);});
   
return "";
};

})();


In my test tiddler  :

<video id="demo" width=100% controls="controls">
            <source src= "./DVDs/Forme103/00Enchainement.mp4"/>
</video>

<<gotoTime demo 100>>

So my problem is that I'd like to make it the right way (or the TW5ish way !).
Could someone give me some guidelines ?

Thanks

FrD
Reply all
Reply to author
Forward
0 new messages