Is there a way to use one background video for multiple slides in Reveal.js? - reveal.js

I am trying to create some slides using Reveal.js using a background video that spans multiple slides. I have no problems getting a background video to work on one slide using the data-background-video attribute
The following is the working snippet from the reveal.js documentation:
<section data-background-video="https://s3.amazonaws.com/static.slid.es/site/homepage/v1/homepage-video-editor.mp4,https://s3.amazonaws.com/static.slid.es/site/homepage/v1/homepage-video-editor.webm" data-background-video-loop>
<h2>Video. Multiple sources can be defined using a comma separated list. Video will loop when the data-background-video-loop attribute is provided.</h2>
</section>
What I want however is for the video to be continuous even when I move to the next slide. If I put data-background-video in a "parent" , I can see the first frame of the video but it just freezes there
<section data-background-video="...">
<section><h1>slide 1</h1></section>
<section><h1>slide 2</h1></section>
<section><h1>slide 3</h1></section>
</section>
I want to use this as a backdrop for a performance where I want the lyrics overlaid on background video. I will switch background videos for for a certain part of the song but want the video to be the same while lines of the lyrics appear.

Here's a way to do this. Inside reveal.js modify the updateBackground() function:
Change the "if( currentBackground )" block from:
if( currentBackground ) {
// Start video playback
var currentVideo = currentBackground.querySelector( 'video' );
if( currentVideo ) {
var startVideo = function() {
currentVideo.currentTime = 0;
currentVideo.play();
currentVideo.removeEventListener( 'loadeddata', startVideo );
};
if( currentVideo.readyState > 1 ) {
startVideo();
}
else {
currentVideo.addEventListener( 'loadeddata', startVideo );
}
}
//................
}
to:
if( currentBackground ) {
// Start video playback
var currentVideo = currentBackground.querySelector( 'video' );
// This might be a nested node - check for parent video
if(!currentVideo) currentVideo = currentBackground.parentNode.querySelector( 'video' );
if( currentVideo ) {
var startVideo = function() {
//currentVideo.currentTime = 0;
currentVideo.play();
currentVideo.removeEventListener( 'loadeddata', startVideo );
};
if( currentVideo.readyState > 1 ) {
startVideo();
}
else {
currentVideo.addEventListener( 'loadeddata', startVideo );
}
}
//................
}
What I suggest is to search for video background in the parent node () as well and to resume it.

Just found this answer via google and it did not work. So I started to find my own solution and it seams to be quite simple. Just add this code below the "Reveal.initialize" command on the bottom of your index html (inside the script tag):
Reveal.addEventListener( 'slidechanged', function( event ) {
window.setTimeout(function(){
var stackedBackgrounds = $('body > div > div.backgrounds > div.stack');
stackedBackgrounds.each(function(){
var me = $(this);
var video = me.find('video').get(0);
console.log(video);
if(video){
if(me.hasClass('present')) {
console.log('play');
video.play();
}
else {
console.log('stop');
video.load();
}
}
});
}, 300);
} );
What does it do?
It registers the "slidechanged"-Event, waits another 300ms (because the event triggers too early). Then it finds all stacked backgrounds and starts the video if it is visible, otherwise it stops the video by reloading. That also sets the resume to position 0.
That all.
PS.: Of cause you can drop the console.log lines.

Related

Very slow hover interactions in OpenLayers 3 with any browser except Chrome

I have two styles of interactions, one highlights the feature, the second places a tooltop with the feature name. Commenting both out, they're very fast, leave either in, the map application slows in IE and Firefox (but not Chrome).
map.addInteraction(new ol.interaction.Select({
condition: ol.events.condition.pointerMove,
layers: [stationLayer],
style: null // this is actually a style function but even as null it slows
}));
$(map.getViewport()).on('mousemove', function(evt) {
if(!dragging) {
var pixel = map.getEventPixel(evt.originalEvent);
var feature = null;
// this block directly below is the offending function, comment it out and it works fine
map.forEachFeatureAtPixel(pixel, function(f, l) {
if(f.get("type") === "station") {
feature = f;
}
});
// commenting out just below (getting the feature but doing nothing with it, still slow
if(feature) {
target.css("cursor", "pointer");
$("#FeatureTooltip").html(feature.get("name"))
.css({
top: pixel[1]-10,
left: pixel[0]+15
}).show();
} else {
target.css("cursor", "");
$("#FeatureTooltip").hide();
}
}
});
I mean this seems like an issue with OpenLayers-3 but I just wanted to be sure I wasn't overlooking something else here.
Oh yeah, there's roughly 600+ points. Which is a lot, but not unreasonably so I would think. Zooming-in to limit the features in view definitely helps. So I guess this is a # of features issue.
This is a known bug and needs more investigation. You can track progress here: https://github.com/openlayers/ol3/issues/4232.
However, there is one thing you can do to make things faster: return a truthy value from map.forEachFeatureAtPixel to stop checking for features once one was found:
var feature = map.forEachFeatureAtPixel(pixel, function(f) {
if (f.get('type') == 'station') {
return feature;
}
});
i had same issue, solved a problem by setInterval, about this later
1) every mouse move to 1 pixel fires event, and you will have a quee of event till you stop moving, and the quee will run in calback function, and freezes
2) if you have an objects with difficult styles, all element shown in canvas will take time to calculate for if they hit the cursor
resolve:
1. use setInterval
2. check for pixels moved size from preview, if less than N, return
3. for layers where multiple styles, try to simplify them by dividing into multiple ones, and let only one layer by interactive for cursor move
function mouseMove(evt) {
clearTimeout(mm.sheduled);
function squareDist(coord1, coord2) {
var dx = coord1[0] - coord2[0];
var dy = coord1[1] - coord2[1];
return dx * dx + dy * dy;
}
if (mm.isActive === false) {
map.unByKey(mm.listener);
return;
}
//shedules FIFO, last pixel processed after 200msec last process
const elapsed = (performance.now() - mm.finishTime);
const pixel = evt.pixel;
const distance = squareDist(mm.lastP, pixel);
if (distance > 0) {
mm.lastP = pixel;
mm.finishTime = performance.now();
mm.sheduled = setTimeout(function () {
mouseMove(evt);
}, MIN_ELAPSE_MSEC);
return;
} else if (elapsed < MIN_ELAPSE_MSEC || mm.working === true) {
// console.log(`distance = ${distance} and elapsed = ${elapsed} mesc , it never should happen`);
mm.sheduled = setTimeout(function () {
mouseMove(evt);
}, MIN_ELAPSE_MSEC);
return;
}
//while multithreading is not working on browsers, this flag is unusable
mm.working = true;
let t = performance.now();
//region drag map
const vStyle = map.getViewport().style;
vStyle.cursor = 'default';
if (evt.dragging) {
vStyle.cursor = 'grabbing';
}//endregion
else {
//todo replace calback with cursor=wait,cursor=busy
UtGeo.doInCallback(function () {
checkPixel(pixel);
});
}
mm.finishTime = performance.now();
mm.working = false;
console.log('mm finished', performance.now() - t);
}
In addition to #ahocevar's answer, a possible optimization for you is to utilize the select interaction's select event.
It appears that both the select interaction and your mousemove listener are both checking for hits on the same layers, doing double work. The select interaction will trigger select events whenever the set of selected features changes. You could listen to it, and show the popup whenever some feature is selected and hide it when not.
This should reduce the work by half, assuming that forEachFeatureAtPixel is what's hogging the system.

stop fade in out on a movieclip actionscript 2

I'm trying to stop fading in/out my movieclip.
I'll explain: I've integrated my swf in an HTML page with a dropdown list. When i choose an item from this list a javascript function it's called.This function execute a callback to a function in my swf file that fade in/out an image drawn at runtime (depending on the item selected in the dropdown list). When I choose another element I want the previuos item stops fading and the new starts.
This is my fading function:
function fadeIn(h){
if (eval(h)._alpha<100) {
eval(h)._alpha += 20;
}
else {
clearInterval(fadeInterval);
setTimeout(startOut, 500, h);
}
}
function fadeOut(h) {
if (eval(h)._alpha>0) {
eval(h)._alpha -= 20;
} else {
clearInterval(fadeInterval);
setTimeout(startIn, 100, h);
}
}
function startOut(h) {
fadeInterval = setInterval(fadeOut, 1, h);
}
function startIn(h){
fadeInterval = setInterval(fadeIn, 1, h);
}
function flashing(h){
var bname;
bname = "planGroup.singleObject." + h;
eval(bname)._alpha = 0;
fadeInterval = setInterval(fadeIn, 1, bname);
}
I tried with clearInterval(fadeInterval), but this doesn't always work, tried with my_mc.stop() but this doesn't work either.
I tried also to set a variable count that execute the fading olny 5 times, and this work unless I change the item in the drowpdown list before the function complete.
Any ideas?? Hope it was clear!
Thanks
If anyone cares i solved with the Tween class!! All those functions were replaced by one line of code:
function fadeTo(clipName, fadeValue){
new mx.transitions.Tween(eval(clipName), "_alpha", mx.transitions.easing.Regular.easeOut, eval(clipName)._alpha, fadeValue, 1, true);
}

How to pause embedded youtube video on the last frame?

When playing embedded youtube videos, I don't want to display a poor resolution thumbnail when completed. Instead I'd like to have a high-resolution image of the last frame. Is this possible?
Either I can pause on the last frame or maybe there's a way to create a high-resolution thumbnail of the last frame?
You can use the YouTube Player API to detect when playback has ended, and at that point do some DOM manipulation to swap out the player and swap in an img tag pointing to one of the video's thumbnails. There normally would not be a thumbnail for the last frame in the video, though, so you would have to choose a different thumbnail.
If you just want to disable the related videos that are shown when a video ends, you can use the rel=0 player parameter, but that will leave you with a black screen.
Video player gives a callback "onStateChange" with the status YT.PlayerState.PAUSED before calling the callback with status YT.PlayerState.ENDED, you can try here.
I am also doing the same thing. I am just displaying an overlay to cover the video with replay button, But still it appears at the end of the video and then overlay appears (some glitch is observed)
I ran into this same problem and after spending a bunch of time playing around with it, the best solution for me was to just pause the video a fraction of second before the end, thus keeping it on that frame. Something like this:
var player;
function onYouTubePlayerAPIReady() {
player = new YT.Player('player', {
playerVars: { 'autoplay': 1, 'controls': 0,'loop': 1, 'showinfo': 0, 'disablekb': 1, 'version': 3, 'vq': 'large', 'wmode':'opaque','rel': 0 },
videoId: 'YOURVIDEOID',
events: {
'onReady': onPlayerReady,
'onStateChange': onStateChange,
'onytplayerStateChange': onStateChange }
});
}
var done = false;
function onStateChange(event){
var videoDuration = player.getDuration();
if (event.data == YT.PlayerState.PLAYING && !done) {
// pause 0.1 seconds before the end
setTimeout(pauseVideo, (videoDuration-0.1)*1000);
done = true;
}
}
function pauseVideo() {
player.pauseVideo();
}
After the video starts (which we catch using onStateChange), we can get the video duration from the YouTube Player API (using player.getDuration), and then use setInterval to time a function that pauses the video 0.1 seconds (or whichever value we choose) before the end.
After running into to this issue too I ended up with this, which has been working pretty consistent for me so far:
var player;
var curTimer;
function onYouTubeIframeAPIReady() {
player = new YT.Player('player', {
videoId: 'The Video ID',
playerVars: { 'rel':0, 'enablejsapi':1, 'autohide':1, 'wmode':'opaque'}
});
player.addEventListener('onReady', 'onPlayerReady');
player.addEventListener('onStateChange', 'onPlayerStateChange');
}
function onPlayerStateChange(event) {
var videoDuration = event.target.getDuration();
var curTime = event.target.getCurrentTime();
if ( curTime ) {
/** Video Already Started */
/** Get video time remaining. */
videoDuration = videoDuration-curTime;
/** Remove old 'setTimeout' function */
removeTimeout(curTimer);
}
/**
Note: The '.25' is time subtracted to stop video on last frame.
Adjust this as needed.
*/
/** Add/Re-Add 'setTimeout' function with video time remaining. */
curTimer = setTimeout(pauseVideo, (videoDuration-.25)*1000);
}
function removeTimeout(elTimer){
/** Remove old timer */
clearTimeout(elTimer);
}
function stopVideo() {
player.stopVideo();
}
Explanations and/or notes are within the comments.
var thumb = true;
function onStateChange(event) {
if (thumb && event.data == YT.PlayerState.PLAYING) {
thumb = false;
player.pauseVideo();
return;
}
if (event.data != YT.PlayerState.ENDED) {
return;
}
player.setPlaybackQuality('highres');
player.seekTo(player.getDuration() - 1, true);
player.playVideo();
thumb = true;
}

Multiple collada scenes

I have two collada files (two different scenes: "01.dae" and "02.dae").
I want to display 01.dae first and right after the animation finishes I want to load and display 02.dae on the same canvas.
(I'm trying to modify "webgl_loader_collada_keyframe.html" to do this but no results so far.)
How could I handle more than one animated collada scenes? A source code or any tips or tricks would be appreciated!
Thank you for your answer. I modified my code based on your idae but unfortunately it's not working.
Could you take a look at my code please?
Here is my code:
loader.load( 'pump.dae', function ( collada ) {
model = collada.scene;
animations = collada.animations;
kfAnimationsLength = animations.length;
model.scale.x = model.scale.y = model.scale.z = 0.125; // 1/8 scale, modeled in cm
init();
start();
animate( lastTimestamp );
setTimeout(loadSecond,3000);
} );
function loadSecond()
{
loader2.load( 'pump2.dae', function ( collada2 )
{
scene.remove( model );
model2 = collada2.scene;
animations2 = collada2.animations;
kfAnimationsLength2 = animations2.length;
model2.scale.x = model2.scale.y = model2.scale.z = 0.125; // 1/8 scale, modeled in cm
init2();
start2();
animate2( lastTimestamp2 );
//alert("second loaded");
} );
}
...
As you can see I extended your code with
scene.remove( model );
to remove the previous scene.
The first scene displays and then disapears properly however the new secene does not load. Do you have an idae why?
(Note: I don't know how long my first scene realy is.)
If you know how long the animation is, you could use a setTimeout to load the second model.
var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load('PATH TO MODEL', function colladaReady( collada){
dae = collada.scene;
skin = collada.skins[ 0 ];
dae.scale.x = dae.scale.y = dae.scale.z = 1;
dae.updateMatrix();
scene.add(dae);
render();
setTimeout(loadSecond,3000);
});
function loadSecond(){
var loader = new THREE.ColladaLoader();
loader.options.convertUpAxis = true;
loader.load('PATH TO MODEL', function colladaReady( collada){
///repeat model loading logic
}
Where the time interval in the setTimeout is equal to the length of your animation.

ray doesn't reach JSON

I'm trying to catch a JSON object with a mouse click event. I use ray to identify the object, but for some reason, the objects are not always identified. I suspect that it is related to the fact that I move the camera, because when I click nearby the object, i is identified.
Can you help me figure out how to set the ray correctly, in accordance with the camera move?
Here is the code :
this is the part of the mouse down event *
document.addEventListener("mousemove", onDocumentMouseMove, false);
document.addEventListener("mouseup", onDocumentMouseUp, false);
document.addEventListener("mouseout", onDocumentMouseOut, false);
mouseXOnMouseDown = event.clientX - windowHalfX;
targetRotationOnMouseDown = targetRotation;
var ray, intersections;
_vector.set((event.clientX / window.innerWidth) * 2 - 1, -(event.clientY / window.innerHeight) * 2 + 1, 0);
projector.unprojectVector(_vector, camera);
ray = new THREE.Ray(camera.position, _vector.subSelf(camera.position).normalize());
intersections = ray.intersectObjects(furniture);
if (intersections.length > 0) {
selected_block = intersections[0].object;
_vector.set(0, 0, 0);
selected_block.setAngularFactor(_vector);
selected_block.setAngularVelocity(_vector);
selected_block.setLinearFactor(_vector);
selected_block.setLinearVelocity(_vector);
mouse_position.copy(intersections[0].point);
block_offset.sub(selected_block.position, mouse_position);
intersect_plane.position.y = mouse_position.y;
}
}
this is the part of the camera move *
camera.position.x = (Math.cos(timer) * 10);
camera.position.z = (Math.sin(timer) * 10);
camera.lookAt(scene.position);
Hmmm, It is hard to say what your problem might be without seeing some kind of demonstration of how your program is actually acting. I would suggest looking at my demo that I have been working on today. I handle my camera, controls, and rays. I am using a JSON as well.
First you can view my demo: here to get an idea of what it is doing, what your describing sounds similar. You should be able to adapt my code if you can understand it.
--If you would like a direct link to the source code: main.js
I also have another you might find useful where I use rays and mouse collisions to spin a cube. --Source code: main.js
Finally I'll post the guts of my mouse events and how I handle it with the trackball camera in the first demo, hopefully some of this will lead you to a solution:
/** Event fired when the mouse button is pressed down */
function onDocumentMouseDown(event) {
event.preventDefault();
/** Calculate mouse position and project vector through camera and mouse3D */
mouse3D.x = mouse2D.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse3D.y = mouse2D.y = -(event.clientY / window.innerHeight) * 2 + 1;
mouse3D.z = 0.5;
projector.unprojectVector(mouse3D, camera);
var ray = new THREE.Ray(camera.position, mouse3D.subSelf(camera.position).normalize());
var intersects = ray.intersectObject(maskMesh);
if (intersects.length > 0) {
SELECTED = intersects[0].object;
var intersects = ray.intersectObject(plane);
offset.copy(intersects[0].point).subSelf(plane.position);
killControls = true;
}
else if (controls.enabled == false)
controls.enabled = true;
}
/** This event handler is only fired after the mouse down event and
before the mouse up event and only when the mouse moves */
function onDocumentMouseMove(event) {
event.preventDefault();
/** Calculate mouse position and project through camera and mouse3D */
mouse3D.x = mouse2D.x = (event.clientX / window.innerWidth) * 2 - 1;
mouse3D.y = mouse2D.y = -(event.clientY / window.innerHeight) * 2 + 1;
mouse3D.z = 0.5;
projector.unprojectVector(mouse3D, camera);
var ray = new THREE.Ray(camera.position, mouse3D.subSelf(camera.position).normalize());
if (SELECTED) {
var intersects = ray.intersectObject(plane);
SELECTED.position.copy(intersects[0].point.subSelf(offset));
killControls = true;
return;
}
var intersects = ray.intersectObject(maskMesh);
if (intersects.length > 0) {
if (INTERSECTED != intersects[0].object) {
INTERSECTED = intersects[0].object;
INTERSECTED.currentHex = INTERSECTED.material.color.getHex();
plane.position.copy(INTERSECTED.position);
}
}
else {
INTERSECTED = null;
}
}
/** Removes event listeners when the mouse button is let go */
function onDocumentMouseUp(event) {
event.preventDefault();
if (INTERSECTED) {
plane.position.copy(INTERSECTED.position);
SELECTED = null;
killControls = false;
}
}
/** Removes event listeners if the mouse runs off the renderer */
function onDocumentMouseOut(event) {
event.preventDefault();
if (INTERSECTED) {
plane.position.copy(INTERSECTED.position);
SELECTED = null;
}
}
And in order to get the desired effect shown in my first demo that I wanted, I had to add this to my animation loop in order to use the killControls flag to selectively turn on and off the trackball camera controls based on the mouse collisions:
if (!killControls) controls.update(delta);
else controls.enabled = false;

Resources