Background video in Xaringan slides - reveal.js

I'm writing a presentation using Xaringan. I want to embed video such that when I transition to the slide containing the video it plays automatically in fullscreen. (i.e., I do not want to have to click on the video to play it).
I could achieve what I want using revealjs with:
## {data-background-video="my_video.mp4"}
but I've spent about 30 hours writing the presentation in Xaringan, including some custom css styles (I'm a complete css novice) so I don't want to convert to revealjs (especially as I haven't used revealjs other than to test the above).
Is there an equivalent in Xaringan? Given it's based on revealjs I assume it's possible but despite many hours on the internet I can't work out how.
Alternatively, is there a way to activate non-fullscreen video from a keyboard press. For example, like an incremental step that plays the video:
This doesn't work. It plays the audio upon a keypress but not the video:
---
--
<video width="100%" height="100%" controls>
<source src="media/my_video.mp4" type="video/mp4">
</video>
---
This plays the audio at the start of the presentation (not from the slide I want) and there's no video (possibly because I have a background image set up on the first slide):
<video width="100%" height="100%" autoplay>
<source src="media/my_video.mp4" type="video/mp4">
</video>

Thanks to #pat-s and the pages to which he linked, I have this working. In case it helps others, here's a working minimal example that autoplays audio and video (in fullscreen) upon slide transition.
The R Markdown is:
title: "Video Example"
author: "Andy Field"
output:
xaringan::moon_reader:
css: ["default", "my_styles.css"]
includes:
after_body: "afterInit.html"
---
# Minimal example of autoplaying audio and fullscreen video
## Andy Field
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
---
class: inverse
background-image: url("http://www.metalmusicarchives.com/images/covers/dio-killing-the-dragon-20160817062111.jpg")
background-size: cover
<audio controls>
<source src="http://www.discoveringstatistics.com/repository/misc/dio_killing_the_dragon.mp3" type="audio/mpeg">
<source src="http://www.discoveringstatistics.com/repository/misc/dio_killing_the_dragon.ogg" type="audio/ogg"/>
</audio>
.center[Here's the audio.
It is a song by the band Dio.
Like many of their songs, it involves a dragon.
Next up, video.]
---
layout: false
<video width="100%" height="100%" controls id="my_video">
<source src="http://www.discoveringstatistics.com/repository/misc/shrek_burp.mp4" type="video/mp4">
</video>
Note that the YAML includes a reference to a file called "afterInit.html", which (in this case) is stored in the same directory as the markdown. This file contains the following:
<script type='text/javascript'>
var slideElements
function getElementForSlide(slide) {
slideElements = slideElements || document.querySelectorAll('.remark-slide')
return slideElements[slide.getSlideIndex()]
}
slideshow.on('showSlide', function (slide) {
Array.from(getElementForSlide(slide).querySelectorAll('video, audio')).forEach(function (vid) {
vid.loop = false
vid.currentTime = 0
vid.play()
})
})
slideshow.on('hideSlide', function (slide) {
Array.from(getElementForSlide(slide).querySelectorAll('video, audio')).forEach(function (vid) {
vid.pause()
})
})
</script>
The YAML also calls on a css file called 'my_styles' (also in the same directory as the markdown file), which is used to get the video to play fullscreen. I guess you could include this in a css chunk directly in the markdown, but I wanted to keep it external. The file contains:
#my_video {
position: fixed;
right: 0;
bottom: 0;
min-width: 100%;
min-height: 100%;
width: 100%;
}
To get this to work, note that when I reference a video in the markdown I include id="my_video".
This works for me when the presentation is in fullscreen in Firefox.

I couldn't get a fully working solution in limited time, but you can use this is a start.
There are multiple issues already about this, both in remark and xaringan:
- https://github.com/yihui/xaringan/issues/218
- https://github.com/gnab/remark/issues/322
afterInit.html should start <script type='text/javascript'> and end with </script> if I understand correctly.
---
title: "Presentation Ninja"
subtitle: "⚔<br/>with xaringan"
author: "Yihui Xie"
institute: "RStudio, Inc."
date: "2016/12/12 (updated: `r Sys.Date()`)"
output:
xaringan::moon_reader:
includes:
after_body: "afterInit.html"
lib_dir: libs
nature:
highlightStyle: github
highlightLines: true
countIncrementalSlides: false
---
background-image: url(https://upload.wikimedia.org/wikipedia/commons/b/be/Sharingan_triple.svg)
```{r setup, include=FALSE}
options(htmltools.dir.version = FALSE)
```
---
<iframe width="560" height="315" src="https://www.youtube.com/embed/MWnZ8SoMeHc" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>

Related

Grav markup how to embed youtube video in frontmatter?

I was planning to do something like the following to embed a youtube video into a grav website using frontmatter (the page is currently using only only frontmatter with no entries in the markup file):
rows:
-
title: XYZ
description: 'Something'
description_position: left
image: image.JPG
name: video
-
title: IJK
description: 'Something'
description_position: right
html: '<iframe width="560" height="315" src="https://www.youtube.com/embed/somevideo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
This does not work. Grav does not say that this isn't valid frontmatter but it just doesn't create the iframe either. Is there a way to embed video from youtube using html inline in the frontmatter and without plugins?
They also have a dedicated youtube plugin (written by the grav developers) to better integrate into the markdown and frontmatter:
https://github.com/getgrav/grav-plugin-youtube
You can use the code below
<//iframe style="position:center;bottom:0px;left:0px;height:100%;width:100%" src="https://www.youtube.com/embed/-5wpm-gesOY" frameborder="0" allowfullscreen></iframe>
(// not use)
Good work

Embedded video youtube

I wanna learn how you guys can implement an embedded youtube video of personalize dimensions. I searched on Google "how to" and I tried some of the tips, but still not working. Can you help me ?
Create a new file index.html. Open it with your text editor (e.g., Notepad). Add the following to it:
<!DOCTYPE html>
<html>
<body>
<h1>My Embeded YouTube video</h1>
<iframe width="1280" height="720" src="https://www.youtube.com/embed/bWPMSSsVdPk" frameborder="0" allowfullscreen></iframe>
</body>
</html>
Change width="1280" and height="720" to the desired number of pixels. Change "https://www.youtube.com/embed/bWPMSSsVdPk" to whatever youtube video you want. For instance, if you'd like to change it to the following video: https://www.youtube.com/watch?v=ohr6O78jGzs
Just switch bWPMSSsVdPk to ohr6O78jGzs in the "https://www.youtube.com/embed/bWPMSSsVdPk" part, such that "https://www.youtube.com/embed/ohr6O78jGzs". Just note that not all videos are embeddable.
Open index.html with a browser. Just drag and drop it into the browser window.
Should do the trick.

iPad HTML5 Video tag list and scrolling issue

I am building cross platform application based on PhoneGap.
I am testing this app on iPad, I am using AngularJS.
I have created a list of media files using ng-repeat as below:
<div ng-repeat="media in mediaArray" style="width:200px; height:200px;">
<img ng-src="{{media.imgSrc}}"
ng-hide="media.isVideo"
style="width:200px; height:200px;"
>
<video id="video{{media.id}"
ng-show="media.isVideo"
postersrc="test.png"
poster-src <!-- Directive for poster source fix -->
controls
style="width:200px; height:200px;"
>
<source type="video/mp4"
videosrc="{{media.videoUrl}}"
video-src <!-- Directive for video source fix -->
>
Your browser does not support HTML5 video.
</video>
</div>
In my list I have images and video files.
I am able to see the list and also able to play the video files.
But problem is that, When I play any of the video then I am not able to scroll the list, scrolling works till I don't play any video once video is played scrolling does not work at all. what can be the issue?
Try this
<div ng-repeat="media in mediaArray" ng-controller="ScrollController" style="width:200px; height:200px;">
<img ng-src="{{media.imgSrc}}"
ng-hide="media.isVideo"
style="width:200px; height:200px;"
>
<video id="video{{media.id}"
ng-show="media.isVideo"
postersrc="test.png"
poster-src <!-- Directive for poster source fix -->
controls
style="width:200px; height:200px;"
>
<source type="video/mp4"
videosrc="{{media.videoUrl}}"
video-src <!-- Directive for video source fix -->
>
Your browser does not support HTML5 video.
</video>
</div>
Script for controller
angular.module('anchorScrollExample', [])
.controller('ScrollController', ['$scope', '$location', '$anchorScroll',
function ($scope, $location, $anchorScroll) {
$scope.gotoBottom = function() {
// set the location.hash to the id of
// the element you wish to scroll to.
$location.hash('bottom');
// call $anchorScroll()
$anchorScroll();
};
}]);

Detect Quicktime plugin withOUT using Javascript

Is it possible to detect the existence of the Browser's Quicktime plugin withOUT using Javascript?
I know how to test for Quicktime using Javascript, but not without.
My logic says that Javascript can be enabled/disabled by the user and the existence of the Quicktime plugin is determined by the programmers for each Browser. Therefore, each should an independent statistic ... even for Apple's iOS which has Quicktime built in.
Thanks,
I am really throwing away my question. However, I thought some of you might be curious why ...
I honestly do not know if it is possible to detect the existence of the Browser's Quicktime plugin withOUT using Javascript. I do know, for example, that Quicktime is built into Apple's current OS and probably many prior ones.
Nevertheless, I have come across the expression "Progressive Enhancement". As a direct result, I have discovered the works of others that result in my being okay with detection of Quicktime using Javascript.
The following illustrates what I mean:
The way-back-when driving force was to avoid document.write in the display of media players for .mp3, .m4a and the like.
The new approach places the media player, the no-js message, and the no-qt message in the html markup.
The default case is to show just the no-js message in the html markup. Using the "Progressive Enhancement" paradigm, if Javascript is enabled, then Javascript is used to first hide the no-js message. Depending on the presence of Quicktime, we then show the media player and hide the no-qt message, or vice versa. As a result, we progress from a "vanilla" text message about no Javascript to showing a media player if Quicktime is present.
For example, my html markup presents:
<section class="mediaWrapper">
<div class="mediaplayer">
<audio name="aMedia" class="aMedia" controls preload="auto"
src="audio/My Love Song Forever.mp3">
</div>
<div class="nojs">
Turn on Javascript to hear an awesome Love Song
</div>
<div class="noqt">
<a href="http://www.apple.com/quicktime/download/"
title="Get Quicktime"
onclick="window.open(this.href); return false">
Install Quicktime
</a>
to hear an awesome Love Song
</div>
</section> <!-- mediaWrapper -->
In my <head> is this <style>:
/* default settings for the html markup */
.mediaWrapper {
display: block;
position: relative;
text-align: center;
}
.mediaplayer {
display: none;
}
.nojs {
display: block;
font-size: 110%; /* for the no-js alert text */
color: #360;
font-weight: bold;
/*
text-align: center; // inherited from .mediaWrapper
*/
}
.noqt {
display: none;
font-size: 110%; /* for the no-qt alert text */
color: #360;
font-weight: bold;
/*
text-align: center; // inherited from .mediaWrapper
*/
}
Also in the <head> is this <script>:
$(document).ready (function() {
$('.nojs').hide(); // we're here, already!
if (QuicktimeIsPresent)
{
$('.mediaplayer').show();
$('.noqt').hide();
}
else
{
$('.mediaplayer').hide();
$('.noqt').show();
}
}); // $(document).ready
As already stated, the html markup (via the above <style>) shows just the vanilla no-js message. Via Progressive Enhancement, if Javascript is enabled, then the above <script> is seen. So, Javascript is used to first hide the no-js message. Depending on the presence of Quicktime, we then show the media player and hide the no-qt message, or vice versa.

embed a YouTube video in an XPages repeat control

I'm looking to embed a YouTube video into an XPage, probably into a repeat control. I've looked around but can't find anything specific to XPages. I can create a link to open the YouTube video but that just moves them to YouTube but I don't want to leave my site.
Does someone have an example of how to do this.
Use the HTML <iframe>, <object> or <embed> tag to insert YouTube videos into your XPage repeat control.
Example:
<xp:repeat
id="repeat1"
rows="30"
var="video"
indexVar="number">
<xp:this.value><![CDATA[#{javascript:
[ "http://www.youtube.com/embed/XMoTb1iep48",
"http://www.youtube.com/embed/lvs3vpmEKHg",
"http://www.youtube.com/embed/63lYaeOJZOA",
"http://www.youtube.com/embed/6D6PzLSlEsQ"
]
}]]></xp:this.value>
<iframe
width="400"
height="250"
style="margin:2em"
src="#{video}"
frameborder="0"
allowfullscreen="allowfullscreen">
</iframe>
<xp:text
rendered="#{javascript:(number + 1) % 2 == 0}">
<br />
</xp:text>
</xp:repeat>
Make sure you use http://www.youtube.com/embed/YOUR_VIDEO_ID as URL.
A detailed description you can find here.
You need to follow instructions and put a short snippet anywhere in the XPage. Something like:
<iframe title="YouTube video player" class="youtube-player" type="text/html"
width="640" height="390" src="http://www.youtube.com/embed/-X2zNe3YFNM"
frameborder="0" allowFullScreen></iframe>
With too many rows in your repeat you can expect lots of iframe reloads on every refresh.

Resources